Skip to content

Commit

Permalink
Merge pull request #66 from dcampbell-macadamian/TIMOB-8990
Browse files Browse the repository at this point in the history
TIMOB-8990: Ti functions don't work in event callbacks
  • Loading branch information
dcampbell-macadamian committed Jun 1, 2012
2 parents 23f6cc5 + 29b4d98 commit 71aa8b1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
7 changes: 4 additions & 3 deletions blackberry/tibb/TiRootObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ TiRootObject* TiRootObject::createRootObject()
return obj;
}

int TiRootObject::executeScript(NativeObjectFactory* objectFactory, const char* javaScript)
int TiRootObject::executeScript(NativeObjectFactory* objectFactory, const char* javaScript,
MESSAGELOOPENTRY messageLoopEntry, void* context)
{
HandleScope handleScope;
objectFactory_ = objectFactory;
initializeTiObject(NULL);
globalTemplate_ = ObjectTemplate::New();
globalTemplate_->SetInternalFieldCount(2);
TiV8EventContainerFactory* eventFactory = TiV8EventContainerFactory::createEventContainerFactory(globalTemplate_);
objectFactory->setEventContainerFactory(eventFactory);
onSetGetPropertyCallback(&globalTemplate_);
onSetFunctionCallback(&globalTemplate_);
context_ = Context::New(NULL, globalTemplate_);
context_->Global()->SetHiddenValue(String::New("globalTemplate_"), External::New(&globalTemplate_));
context_->Global()->SetHiddenValue(String::New("context_"), External::New(&context_));
setTiObjectToJsObject(context_->Global(), this);
Context::Scope context_scope(context_);

Expand All @@ -85,7 +86,7 @@ int TiRootObject::executeScript(NativeObjectFactory* objectFactory, const char*
return -1;
}
onStartMessagePump();
return 0;
return (messageLoopEntry)(context);
}

/* Methods defined by Global */
Expand Down
6 changes: 5 additions & 1 deletion blackberry/tibb/TiRootObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ struct FUNCTION_ENTRY;
*
* Root namespace in Titanium
*/

typedef int (*MESSAGELOOPENTRY)(void*);

class TiRootObject : public TiObject
{
public:
static TiRootObject* createRootObject();
int executeScript(NativeObjectFactory* objectFactory, const char* javaScript);
int executeScript(NativeObjectFactory* objectFactory, const char* javaScript,
MESSAGELOOPENTRY messageLoopEntry, void* context);

protected:
virtual ~TiRootObject();
Expand Down
26 changes: 17 additions & 9 deletions blackberry/tibb/TitaniumRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,26 @@ int TitaniumRuntime::internalRun(int argc, char** argv)
TiCascadesApp mainApp;
mainApp.initializeApp();
NativeObjectFactory objFactory(&mainApp);
obj->executeScript(&objFactory, javaScript_);
NativeObject* nativeObject = objFactory.getRootContainer();
mainApp.setScene(nativeObject);
if (nativeObject != NULL)
{
nativeObject->release();
}
// TODO: implement a message pump here
return bb::cascades::Application::exec();
objectFactory_ = &objFactory;
mainApp_ = &mainApp;
int ret = obj->executeScript(&objFactory, javaScript_, messageLoop, this);
// TODO: handle non-zero return code here
return ret;
}

void TitaniumRuntime::Log(const char* msg)
{
fprintf(stderr, "%s\n", msg);
}

int TitaniumRuntime::messageLoop(void* context)
{
TitaniumRuntime* self = (TitaniumRuntime*)context;
NativeObject* nativeObject = self->objectFactory_->getRootContainer();
self->mainApp_->setScene(nativeObject);
if (nativeObject != NULL)
{
nativeObject->release();
}
return bb::cascades::Application::exec();
}
6 changes: 6 additions & 0 deletions blackberry/tibb/TitaniumRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* Main runtime startup class
*/

class NativeObjectFactory;
class TiCascadesApp;

class TitaniumRuntime
{
public:
Expand All @@ -28,9 +31,12 @@ class TitaniumRuntime
virtual ~TitaniumRuntime();
int internalRun(int argc, char** argv);
void Log(const char* msg);
static int messageLoop(void* context);

char* javaScript_;
TiObjectScope rootObject_;
NativeObjectFactory* objectFactory_;
TiCascadesApp* mainApp_;
};

#endif /* TITANIUMRUNTIME_H_ */

0 comments on commit 71aa8b1

Please sign in to comment.