summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Guzzo <andrea.guzzo@booking.com>2013-09-26 14:44:16 (GMT)
committer Andrea Guzzo <andrea.guzzo@booking.com>2013-09-26 14:44:16 (GMT)
commita66d258f95368e943cb46a9bf6bcd237348095c5 (patch)
tree8ab37974977b666cf31ccfe71052a32569c84f6c
parente5dc3865530aa8d8fa0f4ef231e183afbb7ca4f2 (diff)
the jmx-cli now works
many DOM/XML related bugfixes while testing the cli-based target
-rw-r--r--JMX.xcodeproj/project.pbxproj16
-rw-r--r--core/JMXApplication.h1
-rw-r--r--core/JMXApplication.m1
-rw-r--r--core/JMXAttribute.mm7
-rw-r--r--core/JMXElement.mm13
-rw-r--r--core/JMXEntity.mm9
-rw-r--r--core/JMXInputPin.m3
-rw-r--r--core/JMXOutputPin.m2
-rw-r--r--core/JMXPin.mm14
-rw-r--r--core/JMXScript.mm5
-rw-r--r--core/NSXMLNode+V8.mm9
-rw-r--r--entities/JMXScriptEntity.mm22
-rw-r--r--gui/JMXBoardViewController.m8
-rw-r--r--jmx/main.m8
-rw-r--r--jsapi/JMX.js42
-rw-r--r--node.js/lib/_third_party_main.js2
16 files changed, 95 insertions, 67 deletions
diff --git a/JMX.xcodeproj/project.pbxproj b/JMX.xcodeproj/project.pbxproj
index d6b26da..3b7ab50 100644
--- a/JMX.xcodeproj/project.pbxproj
+++ b/JMX.xcodeproj/project.pbxproj
@@ -490,7 +490,7 @@
AA37E05014FA318400CBA0AE /* JMXDOMBrowser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMXDOMBrowser.h; sourceTree = "<group>"; };
AA37E05114FA318500CBA0AE /* JMXDOMBrowser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JMXDOMBrowser.m; sourceTree = "<group>"; };
AA38D1CB12DCC29D00208826 /* jquery.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = jquery.js; sourceTree = "<group>"; };
- AA417D5417F2D34B00A705DF /* jmx */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = jmx; sourceTree = BUILT_PRODUCTS_DIR; };
+ AA417D5417F2D34B00A705DF /* jmx-cli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "jmx-cli"; sourceTree = BUILT_PRODUCTS_DIR; };
AA417D5717F2D34B00A705DF /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
AA417D5A17F2D34B00A705DF /* jmx-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "jmx-Prefix.pch"; sourceTree = "<group>"; };
AA417D5B17F2D34B00A705DF /* jmx.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = jmx.1; sourceTree = "<group>"; };
@@ -765,7 +765,7 @@
children = (
8D1107320486CEB800E47090 /* JMX.app */,
AA9BFA5F178F0FB2003673D9 /* JMXCore.framework */,
- AA417D5417F2D34B00A705DF /* jmx */,
+ AA417D5417F2D34B00A705DF /* jmx-cli */,
);
name = Products;
sourceTree = "<group>";
@@ -1515,9 +1515,9 @@
productReference = 8D1107320486CEB800E47090 /* JMX.app */;
productType = "com.apple.product-type.application";
};
- AA417D5317F2D34B00A705DF /* jmx */ = {
+ AA417D5317F2D34B00A705DF /* jmx-cli */ = {
isa = PBXNativeTarget;
- buildConfigurationList = AA417D5F17F2D34B00A705DF /* Build configuration list for PBXNativeTarget "jmx" */;
+ buildConfigurationList = AA417D5F17F2D34B00A705DF /* Build configuration list for PBXNativeTarget "jmx-cli" */;
buildPhases = (
AA417D5017F2D34B00A705DF /* Sources */,
AA417D5117F2D34B00A705DF /* Frameworks */,
@@ -1528,9 +1528,9 @@
dependencies = (
AA417D6117F2D36400A705DF /* PBXTargetDependency */,
);
- name = jmx;
+ name = "jmx-cli";
productName = jmx;
- productReference = AA417D5417F2D34B00A705DF /* jmx */;
+ productReference = AA417D5417F2D34B00A705DF /* jmx-cli */;
productType = "com.apple.product-type.tool";
};
AA9BFA5E178F0FB2003673D9 /* JMXCore */ = {
@@ -1580,7 +1580,7 @@
8D1107260486CEB800E47090 /* JMX */,
AA9BFA5E178F0FB2003673D9 /* JMXCore */,
AA9BFAE5178F12C1003673D9 /* node.js */,
- AA417D5317F2D34B00A705DF /* jmx */,
+ AA417D5317F2D34B00A705DF /* jmx-cli */,
);
};
/* End PBXProject section */
@@ -2171,7 +2171,7 @@
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
- AA417D5F17F2D34B00A705DF /* Build configuration list for PBXNativeTarget "jmx" */ = {
+ AA417D5F17F2D34B00A705DF /* Build configuration list for PBXNativeTarget "jmx-cli" */ = {
isa = XCConfigurationList;
buildConfigurations = (
AA417D5D17F2D34B00A705DF /* Debug */,
diff --git a/core/JMXApplication.h b/core/JMXApplication.h
index c1d15d3..ab94df2 100644
--- a/core/JMXApplication.h
+++ b/core/JMXApplication.h
@@ -15,6 +15,7 @@
}
@property (nonatomic, readonly) BOOL batchMode;
+@property (nonatomic, copy) NSString *appName;
@end
diff --git a/core/JMXApplication.m b/core/JMXApplication.m
index 3301c27..2c3d8c3 100644
--- a/core/JMXApplication.m
+++ b/core/JMXApplication.m
@@ -39,6 +39,7 @@ int verbose = LOG_INFO;
self = [super init];
if (self) {
argv = [[NSMutableArray alloc] initWithCapacity:10];
+ self.appName = @"JMX";
}
return self;
}
diff --git a/core/JMXAttribute.mm b/core/JMXAttribute.mm
index f950fb8..68ffbc3 100644
--- a/core/JMXAttribute.mm
+++ b/core/JMXAttribute.mm
@@ -48,6 +48,13 @@ using namespace v8;
return self;
}
+- (NSXMLNode *)childAtIndex:(NSUInteger)index
+{
+ if (self.childCount > index)
+ return [self.children objectAtIndex:index];
+ return nil;
+}
+
#pragma mark V8
static v8::Handle<Value> GetValue(Local<String> name, const AccessorInfo& info)
diff --git a/core/JMXElement.mm b/core/JMXElement.mm
index 59505cb..51aec87 100644
--- a/core/JMXElement.mm
+++ b/core/JMXElement.mm
@@ -44,12 +44,6 @@ JMXV8_EXPORT_NODE_CLASS(JMXElement);
return self;
}
-- (id)init
-{
- self = [super init];
- return self;
-}
-
- (id)jmxInit
{
v8::Unlocker unlocker;
@@ -97,6 +91,13 @@ JMXV8_EXPORT_NODE_CLASS(JMXElement);
[idLock unlock];
}
+- (NSXMLNode *)childAtIndex:(NSUInteger)index
+{
+ if (self.childCount > index)
+ return [self.children objectAtIndex:index];
+ return nil;
+}
+
#pragma mark V8
using namespace v8;
diff --git a/core/JMXEntity.mm b/core/JMXEntity.mm
index e9ab506..07e7126 100644
--- a/core/JMXEntity.mm
+++ b/core/JMXEntity.mm
@@ -135,10 +135,10 @@ using namespace v8;
{
// TODO - start using debug messages activated by some flag
//NSLog(@"Initializing %@", [self class]);
- self = [super init];
+ self = [super initWithName:@"JMXEntity"];
if (self) {
owner = nil;
- self.name = @"JMXEntity";
+ //self.name = @"JMXEntity";
self.label = @"";
active = NO;
[self addAttribute:[JMXAttribute attributeWithName:@"class" stringValue:NSStringFromClass([self class])]];
@@ -157,6 +157,11 @@ using namespace v8;
return self;
}
+- (void)addChild:(NSXMLNode *)child
+{
+ [super addChild:child];
+}
+
- (void)dealloc
{
[self unregisterAllPins]; // NOTE: this must be done before detaching our children
diff --git a/core/JMXInputPin.m b/core/JMXInputPin.m
index c126b50..d72721c 100644
--- a/core/JMXInputPin.m
+++ b/core/JMXInputPin.m
@@ -23,6 +23,7 @@
#import "JMXInputPin.h"
#import "JMXOutputPin.h"
+#import "JMXAttribute.h"
@implementation JMXInputPin
@@ -46,7 +47,7 @@
if (self) {
producers = [[NSMutableArray alloc] init];
direction = kJMXInputPin;
- [self addAttribute:[NSXMLNode attributeWithName:@"direction" stringValue:@"input"]];
+ [self addAttribute:[JMXAttribute attributeWithName:@"direction" stringValue:@"input"]];
}
return self;
}
diff --git a/core/JMXOutputPin.m b/core/JMXOutputPin.m
index b470adc..9d27e9a 100644
--- a/core/JMXOutputPin.m
+++ b/core/JMXOutputPin.m
@@ -52,7 +52,7 @@
if (self) {
receivers = [[NSMutableDictionary alloc] init];
direction = kJMXOutputPin;
- [self addAttribute:[NSXMLNode attributeWithName:@"direction" stringValue:@"output"]];
+ [self addAttribute:[JMXAttribute attributeWithName:@"direction" stringValue:@"output"]];
}
return self;
}
diff --git a/core/JMXPin.mm b/core/JMXPin.mm
index e1e6e97..4f9f416 100644
--- a/core/JMXPin.mm
+++ b/core/JMXPin.mm
@@ -31,6 +31,7 @@
#import "JMXScriptEntity.h"
#import "JMXScriptPinWrapper.h"
#import "JMXByteArray.h"
+#import "JMXAttribute.h"
#import <libkern/OSAtomic.h>
using namespace v8;
@@ -212,10 +213,10 @@ using namespace v8;
currentSender = owner;
dataBuffer[offset] = [value retain];
}
- [self addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:[JMXPin nameForType:type]]];
- [self addAttribute:[NSXMLNode attributeWithName:@"multiple" stringValue:multiple ? @"YES" : @"NO" ]];
- [self addAttribute:[NSXMLNode attributeWithName:@"connected" stringValue:connected ? @"YES" : @"NO" ]];
- [self addAttribute:[NSXMLNode attributeWithName:@"label" stringValue:label]];
+ [self addAttribute:[JMXAttribute attributeWithName:@"type" stringValue:[JMXPin nameForType:type]]];
+ [self addAttribute:[JMXAttribute attributeWithName:@"multiple" stringValue:multiple ? @"YES" : @"NO" ]];
+ [self addAttribute:[JMXAttribute attributeWithName:@"connected" stringValue:connected ? @"YES" : @"NO" ]];
+ [self addAttribute:[JMXAttribute attributeWithName:@"label" stringValue:label]];
connections = [[JMXElement alloc] initWithName:@"connections"];
[self addChild:connections];
[self performSelectorOnMainThread:@selector(notifyCreation) withObject:nil waitUntilDone:NO];
@@ -230,6 +231,11 @@ using namespace v8;
return nil;
}
+- (void)addChild:(NSXMLNode *)child
+{
+ [super addChild:child];
+}
+
- (void)notifyCreation
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"JMXPinCreated" object:self];
diff --git a/core/JMXScript.mm b/core/JMXScript.mm
index d63e44e..c9b005b 100644
--- a/core/JMXScript.mm
+++ b/core/JMXScript.mm
@@ -55,6 +55,7 @@
#import "NSDictionary+V8.h"
#import "NSNumber+V8.h"
#import "NSObject+V8.h"
+#import "JMXApplication.h"
#include "node_natives_jmx.h"
#include "node_string.h"
@@ -566,10 +567,11 @@ static v8::Handle<Value> ClearTimeout(const Arguments& args)
@synthesize scriptEntity, runloopTimers, eventListeners, ctx;
-static char *argv[2] = { (char *)"JMX", NULL };
+static char *argv[2] = { NULL, NULL };
+ (void)initialize
{
+ argv[0] = (char *)((JMXApplication *)[NSApplication sharedApplication].delegate).appName.UTF8String;
// initialize node.js
node::Init(1, argv);
v8::V8::Initialize();
@@ -869,6 +871,7 @@ static Persistent<ObjectTemplate> ctxTemplate;
uint64_t sleepTime = (delta && delta < maxDelta) ? maxDelta - delta : 0;
if (sleepTime) {
+ Unlocker unlocker;
struct timespec time = { 0, 0 };
struct timespec remainder = { 0, static_cast<long>(sleepTime) };
do {
diff --git a/core/NSXMLNode+V8.mm b/core/NSXMLNode+V8.mm
index acae0e2..09793f9 100644
--- a/core/NSXMLNode+V8.mm
+++ b/core/NSXMLNode+V8.mm
@@ -98,7 +98,10 @@ static v8::Handle<Value>GetLastChild(Local<String> name, const AccessorInfo& inf
v8::Locker lock;
HandleScope handleScope;
NSXMLNode *node = (NSXMLNode *)info.Holder()->GetPointerFromInternalField(0);
- return handleScope.Close([[node childAtIndex:[node childCount]-1] jsObj]);
+ if (node.childCount)
+ return handleScope.Close([[node childAtIndex:[node childCount]-1] jsObj]);
+ else
+ return handleScope.Close(Undefined());
}
static v8::Handle<Value>GetPreviousSibling(Local<String> name, const AccessorInfo& info)
@@ -167,7 +170,9 @@ static v8::Handle<Value>GetLocalName(Local<String> name, const AccessorInfo& inf
v8::Locker lock;
HandleScope handleScope;
NSXMLNode *node = (NSXMLNode *)info.Holder()->GetPointerFromInternalField(0);
- return handleScope.Close(String::New([[node localName] UTF8String]));
+ if ([node localName])
+ return handleScope.Close(String::New([[node localName] UTF8String]));
+ return handleScope.Close(Undefined());
}
static v8::Handle<Value>GetOwnerDocument(Local<String> name, const AccessorInfo& info)
diff --git a/entities/JMXScriptEntity.mm b/entities/JMXScriptEntity.mm
index 7054b9f..37db55b 100644
--- a/entities/JMXScriptEntity.mm
+++ b/entities/JMXScriptEntity.mm
@@ -34,17 +34,17 @@ using namespace v8;
}
}
-- (id)initWithName:(NSString *)name
-{
- self = [super initWithName:name];
- if (self) {
- self.label = name;
- pinWrappers = [[NSMutableSet alloc] initWithCapacity:25];
- codeOutputPin = [self registerOutputPin:@"runningCode" withType:kJMXCodePin andSelector:@"code"];
- code = [[NSMutableString alloc] initWithCapacity:1024];
- }
- return self;
-}
+//- (id)initWithName:(NSString *)name
+//{
+// self = [super initWithName:name];
+// if (self) {
+// self.label = name;
+// pinWrappers = [[NSMutableSet alloc] initWithCapacity:25];
+// codeOutputPin = [self registerOutputPin:@"runningCode" withType:kJMXCodePin andSelector:@"code"];
+// code = [[NSMutableString alloc] initWithCapacity:1024];
+// }
+// return self;
+//}
- (id)init
{
diff --git a/gui/JMXBoardViewController.m b/gui/JMXBoardViewController.m
index 0fadb32..d0795e3 100644
--- a/gui/JMXBoardViewController.m
+++ b/gui/JMXBoardViewController.m
@@ -10,7 +10,7 @@
#import "JMXRunLoop.h"
#import "JMXEntitiesController.h"
#import "JMXScriptEntity.h"
-
+#import "JMXContext.h"
#include <math.h>
@@ -71,7 +71,11 @@
selected = [[NSMutableArray alloc] init];
entities = [[NSMutableArray alloc] init];
entitiesController = [[JMXEntitiesController alloc] init];
- scriptController = [[JMXScriptEntity alloc] initWithName:@"scriptController"];
+ scriptController = [[JMXScriptEntity alloc] init];//:@"scriptController"];
+ NSXMLElement *rootElement = [[[JMXContext sharedContext] dom] rootElement];
+ @synchronized(rootElement) {
+ [rootElement addChild:scriptController];
+ }
jsInput.target = self;
jsInput.action = @selector(execStatement);
jsInput.delegate = self;
diff --git a/jmx/main.m b/jmx/main.m
index 8b0c4f6..23dc00c 100644
--- a/jmx/main.m
+++ b/jmx/main.m
@@ -20,17 +20,19 @@ int main(int argc, const char * argv[])
@autoreleasepool {
JMXApplication *app =[[JMXApplication alloc] init];
+ app.appName = @"jmx-cli";
[NSApplication sharedApplication].delegate = app;
- openlog("JMX", LOG_PERROR, LOG_USER);
+ openlog("jmx-cli", LOG_PERROR, LOG_USER);
[app applicationWillFinishLaunching:[NSNotification notificationWithName:@"applicationWillFinishLaunching" object:nil]];
[app applicationDidFinishLaunching:[NSNotification notificationWithName:@"applicationDidFinishLaunching" object:nil]];
- scriptController = [[JMXScriptEntity alloc] initWithName:@"scriptController"];
+ scriptController = [[JMXScriptEntity alloc] init];
+ scriptController.name = @"scriptController";
NSXMLElement *rootElement = [[[JMXContext sharedContext] dom] rootElement];
@synchronized(rootElement) {
[rootElement addChild:scriptController];
}
scriptController.active = YES;
- [scriptController exec:@"echo('CIAO');"];
+ [scriptController exec:@""];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop run];
}
diff --git a/jsapi/JMX.js b/jsapi/JMX.js
index e1c082a..69a0879 100644
--- a/jsapi/JMX.js
+++ b/jsapi/JMX.js
@@ -5,33 +5,25 @@
* in any global context being executed
*/
-//echo("Initializing JMX Core API");
-/*
-include("VideoOutput.js");
-//echo("Registered class: VideoOutput");
-include("VideoFilter.js");
-//echo("Registered class: VideoFilter");
-include("AudioOutput.js");
-//echo("Registered class: AudioOutput");
-include("AudioCapture.js");
-//echo("Registered class: AudioCapture");
-include("VideoCapture.js");
-include("MovieFile.js");
-include("AudioFile.js");
-
-include("DOM.js"); // DOM related additions
-include("jquery.js");
-include("processing.js");
-*/
-/**
- * Extend the internal Pin class to allow 'stringifying' them
- * (so that "echo(array_variable)" will dump its content)
- * @addon
- */
-/*
-Pin.prototype.toString = function() {
+/*Pin.prototype.toString = function() {
return this.label;
}*/
+if (process.argv[0] == 'jmx-cli') {
+ global.print = function(str) {
+ if (typeof(str) == 'function')
+ process.stdout.write(str.toString());
+ else
+ process.stdout.write(str);
+ }
+
+ global.echo = function(str) {
+ if (typeof(str) == 'function')
+ process.stdout.write(str.toString() + "\n");
+ else
+ process.stdout.write(str + "\n");
+ }
+}
+
//echo("Done initializing JMX Core API");
diff --git a/node.js/lib/_third_party_main.js b/node.js/lib/_third_party_main.js
index b5c718a..f10c045 100644
--- a/node.js/lib/_third_party_main.js
+++ b/node.js/lib/_third_party_main.js
@@ -1,7 +1,7 @@
var Module = require('module');
// If -i or --interactive were passed, or stdin is a TTY.
-if (process._forceRepl || require('tty').isatty(0)) {
+if (process.argv[0] == 'jmx-cli' && require('tty').isatty(0)) {
// REPL
var opts = {
useGlobal: true,