int WebEmberRunner::runEmber(std::string windowhandle) { FBLOG_INFO("WebEmberRunner::runEmber", "Starting Ember."); std::string prefix(getPrefix()); #ifdef USE_X11 std::string libpath(prefix + "/lib"); //change directory for rpath compatibility. chdir(libpath.c_str()); #endif if (mLinker.link(prefix.c_str()) == 0) { int ret = mLinker.callRunEmber(windowhandle.c_str(), prefix.c_str()); if (ret) { FBLOG_INFO("WebEmberRunner::runEmber", "Shut down WebEmber with error code: " << ret); } else { FBLOG_INFO("WebEmberRunner::runEmber", "Shut down WebEmber normally."); } } //send quit to message queue { WebEmberMessageQueuePtr queue(mQueue.lock()); if (queue) { queue->stop(); } } mLinker.unlink(); sRunning = false; return 0; }
/////////////////////////////////////////////////////////////////////////////// /// @fn DNSSDPluginAPI::DNSSDPluginAPI(const DNSSDPluginPtr& plugin, const FB::BrowserHostPtr host) /// /// @brief Constructor for your JSAPI object. You should register your methods, properties, and events /// that should be accessible to Javascript from here. /// /// @see FB::JSAPIAuto::registerMethod /// @see FB::JSAPIAuto::registerProperty /// @see FB::JSAPIAuto::registerEvent /////////////////////////////////////////////////////////////////////////////// DNSSDPluginAPI::DNSSDPluginAPI(const DNSSDPluginPtr& plugin, const FB::BrowserHostPtr& host) : m_plugin(plugin), m_host(host) { bool safe = true; std::string msg = "DNSSDPlugin: "; std::string location = m_host->getDOMWindow()->getLocation(); msg.append("running from "); msg.append(location); #ifndef DEBUG safe = (location == MOZILLA_CHROME_URI || location.find("chrome-extension://") == 0); #endif msg.append(safe ? " presumed safe" : " presumed unsafe"); FBLOG_INFO("DNSSDPluginAPI()", msg); if (!safe) return; registerMethod("plugin_version", make_method(this, &DNSSDPluginAPI::plugin_version)); registerMethod("daemon_version", make_method(this, &DNSSDPluginAPI::daemon_version)); registerMethod("browse_domains", make_method(this, &DNSSDPluginAPI::enum_browse)); registerMethod("browse", make_method(this, &DNSSDPluginAPI::browse)); registerMethod("resolve", make_method(this, &DNSSDPluginAPI::resolve)); }
void XN_CALLBACK_TYPE Calibration_End(xn::SkeletonCapability& capability, XnUserID nId, XnBool bSuccess, void* pCookie) { if (bSuccess) { printf("User calibrated\n"); FBLOG_INFO("Calibration_End", "User calibrated"); g_UserGenerator.GetSkeletonCap().StartTracking(nId); (*((hiKinect *)pCookie)->callbackPtr)->InvokeAsync("", FB::variant_list_of("CALIBRATION_SUCCESS")); } else { printf("Failed to calibrate user %d\n", nId); FBLOG_INFO("Calibration_End", "Failed to calibrate user"); g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(POSE_TO_USE, nId); (*((hiKinect *)pCookie)->callbackPtr)->InvokeAsync("", FB::variant_list_of("CALIBRATION_FAIL")); } }
void XN_CALLBACK_TYPE Calibration_Start(xn::SkeletonCapability& capability, XnUserID nId, void* pCookie) { (*((hiKinect *)pCookie)->callbackPtr)->InvokeAsync("", FB::variant_list_of("START_CALIBRATION")); printf("Starting calibration for user %d\n", nId); FBLOG_INFO("Calibration_Start", "Starting calibration"); }
XnStatus hiKinect::init(const FB::JSObjectPtr &cb){ XnStatus nRetVal = XN_STATUS_OK; callbackPtr = &cb; nRetVal = context.Init(); (*callbackPtr)->InvokeAsync("", FB::variant_list_of("CONTEXT_INIT") (nRetVal)(xnGetStatusString(nRetVal))); if (nRetVal != XN_STATUS_OK) return nRetVal; // Create the user generator nRetVal = g_UserGenerator.Create(context); (*callbackPtr)->InvokeAsync("", FB::variant_list_of("USERGENERATOR_CREATE") (nRetVal)(xnGetStatusString(nRetVal))); if (nRetVal != XN_STATUS_OK) return nRetVal; XnCallbackHandle h1, h2, h3; g_UserGenerator.RegisterUserCallbacks(User_NewUser, User_LostUser, this, h1); g_UserGenerator.GetPoseDetectionCap() .RegisterToPoseCallbacks(Pose_Detected, NULL, this, h2); g_UserGenerator.GetSkeletonCap() .RegisterCalibrationCallbacks(Calibration_Start, Calibration_End, this, h3); // Set the profile g_UserGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL); FBLOG_INFO("contextInit", "Init finish"); // Start generating nRetVal = context.StartGeneratingAll(); (*callbackPtr)->InvokeAsync("", FB::variant_list_of("START_GENERATING") (nRetVal)(xnGetStatusString(nRetVal))); if (nRetVal != XN_STATUS_OK) return nRetVal; while (getTrackedUserID() == 0){ contextWaitAndUpdateAll(); } return nRetVal; }
void FBTestMathPlugin::StaticDeinitialize() { FBLOG_INFO("FBTestMathPlugin::StaticInit", "Static Deinitialize"); // Place one-time deinitialization stuff here. This should be called just before // the plugin library is unloaded }
void XN_CALLBACK_TYPE Pose_Detected(xn::PoseDetectionCapability& pose, const XnChar* strPose, XnUserID nId, void* pCookie) { printf("Pose %s for user %d\n", strPose, nId); FBLOG_INFO("Pose_Detected()", "Pose_Detected"); g_UserGenerator.GetPoseDetectionCap().StopPoseDetection(nId); g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE); (*((hiKinect *)pCookie)->callbackPtr)->InvokeAsync("", FB::variant_list_of("POSE_DETECTED")); }
void FBTestPlugin::StaticDeinitialize() { #ifdef HAS_LEAKFINDER DeinitLeakFinder(pOut.get()); pOut.reset(); #endif FBLOG_INFO("StaticInit", "Static Deinitialize"); // Place one-time deinitialization stuff here. This should be called just before // the plugin library is unloaded }
void FB::BrowserHost::htmlLog(const std::string& str) { FBLOG_INFO("BrowserHost", "Logging to HTML: " << str); if (m_htmlLogEnabled) { try { this->ScheduleAsyncCall(&FB::BrowserHost::AsyncHtmlLog, new FB::AsyncLogRequest(shared_from_this(), str)); } catch (const std::exception&) { // This fails during shutdown; ignore it } } }
void WebEmberLinker::callQuitEmber() { //There is a small chance for a race condition, when the user quits ember manually in ember. //when the user changes webpage when the FreeLibrary is called it would make segfault. boost::mutex::scoped_lock lck(mUnloadLibraryMutex); if (mModuleHandle) { assert(pQuitWebEmber); pQuitWebEmber(); }else{ FBLOG_INFO("WebEmberLinker::callQuitEmber", "Failed to quit ember, because ember is already shut down!"); } }
void FBTestPlugin::StaticInitialize() { FBLOG_INFO("StaticInit", "Static Initialize"); // Place one-time initialization stuff here; As of FireBreath 1.4 this should only // be called once per process #ifdef HAS_LEAKFINDER #ifdef XML_LEAK_FINDER pOut.swap(boost::scoped_ptr<LeakFinderXmlOutput>(new LeakFinderXmlOutput(L"C:\\code\\firebreath_mem.xml"))); #endif InitLeakFinder(); #endif }
void XN_CALLBACK_TYPE User_NewUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie) { printf("New User: %d\n", nId); FBLOG_INFO("User_NewUser", nId); XnUInt16 nUsers = g_UserGenerator.GetNumberOfUsers(); XnUserID aUsers[nUsers]; g_UserGenerator.GetUsers(aUsers, nUsers); for (int i = 0; i < nUsers; ++i) { if (g_UserGenerator.GetSkeletonCap().IsTracking(aUsers[i])) { return; } } g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(POSE_TO_USE, nId); (*((hiKinect *)pCookie)->callbackPtr)->InvokeAsync("", FB::variant_list_of("NEW_USER")); }
/// Closes the device. void PluginAPI::close(const FB::JSAPIPtr &device, const FB::JSObjectPtr &callbacks) { try { FBLOG_INFO("close()", "Closing device"); acquire_plugin() ->communicator(boost::static_pointer_cast<DeviceAPI>(device)->device) ->close(callbacks); } catch (const std::exception &e) { FBLOG_ERROR("close()", "Exception caught"); FBLOG_ERROR("close()", e.what()); callbacks->InvokeAsync("error", FB::variant_list_of(e.what())); } }
/// Calls the device. void PluginAPI::call(const FB::JSAPIPtr &device, bool use_timeout, const std::string &type_name, const FB::VariantMap &message_map, const FB::JSObjectPtr &callbacks) { try { FBLOG_INFO("call()", "Calling device"); acquire_plugin() ->communicator(boost::static_pointer_cast<DeviceAPI>(device)->device) ->call(use_timeout, type_name, message_map, callbacks); } catch (const std::exception &e) { FBLOG_ERROR("call()", "Exception caught"); FBLOG_ERROR("call()", e.what()); callbacks->InvokeAsync("error", FB::variant_list_of(e.what())); } }
int WebEmberLinker::link(const char* prefix) { assert(!mModuleHandle); std::string libdir(prefix); #ifdef _WIN32 if(!libdir.empty()) { #if defined(_DEBUG) && defined(SEPARATE_BUILDS) //In msvc I prefer to separate release/debug builds to prevent mixing the runtime. //Set SEPARATE_BUILDS to enable this feature. libdir += "\\bin_d"; #else libdir += "\\bin"; #endif SetDllDirectoryA(libdir.c_str()); SetCurrentDirectoryA(libdir.c_str()); libdir += "\\"; } //normally the browsers are disabling verbose popup messages from the OS on errors, //but to get more info on what is the missing DLL when linking recursively, we need to enable this. UINT browserErrorMode = GetErrorMode(); SetErrorMode(0); #else if (!libdir.empty()) { libdir += "/lib/"; } #endif std::string libfile(libdir + sLibName); FBLOG_INFO("WebEmberLinker::runEmber", "Loading library: " << libfile); //Loads the specified module into the address space of the calling process. mModuleHandle = LoadLib(libfile.c_str()); if (mModuleHandle == NULL) { #ifndef _WIN32 FBLOG_ERROR("WebEmberLinker::runEmber", "dlerror: " << dlerror()); #endif FBLOG_ERROR("WebEmberLinker::runEmber", "Unable to load " << libfile); return 1; } //Retrieves the address of an exported function or variable from the specified DLL. pStartWebEmber = (funcTypeStart)GetFunction(mModuleHandle, sFuncNameStart); if (pStartWebEmber == NULL) { #ifndef _WIN32 FBLOG_ERROR("WebEmberLinker::runEmber", "dlerror: " << dlerror()); #endif FBLOG_ERROR("WebEmberLinker::runEmber", "Unable to load function " << sFuncNameStart << " in " << libfile); UnloadLib(mModuleHandle); return 2; } //same as above pQuitWebEmber = (funcTypeQuit)GetFunction(mModuleHandle, sFuncNameQuit); if (pQuitWebEmber == NULL) { #ifndef _WIN32 FBLOG_ERROR("WebEmberLinker::runEmber", "dlerror: " << dlerror()); #endif FBLOG_ERROR("WebEmberLinker::runEmber", "Unable to load function " << sFuncNameQuit << " in " << libfile); UnloadLib(mModuleHandle); return 3; } #ifdef _WIN32 //SetErrorMode of the process back to the original. SetErrorMode(browserErrorMode); #endif return 0; }
bool OpenGLExampleX11::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindowX11 *win) { FBLOG_WARN("", "AttachedEvent start"); // Initialize GTK/GDK on this thread //boost::scoped_array<char> argv(new char[1][20]); int argc = 0; //strcpy(argv[0], "--sync"); //gboolean initSucceeded = gtk_init_check(&argc, argv.get()); gdk_threads_enter(); FBLOG_WARN("", "Starting Render Thread"); //gboolean initSucceeded = gdk_gl_init_check(&argc, NULL); //FBLOG_WARN("", "gdk_gl_init_check returned " << initSucceeded); drawing_area = gtk_drawing_area_new(); gtk_widget_set_size_request(drawing_area, 500, 500); GdkGLConfigMode glconf = static_cast<GdkGLConfigMode>( GDK_GL_MODE_RGB | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_DEPTH ); //FBLOG_WARN("", "Trying to config"); //glConfig = gdk_gl_config_new_by_mode(glconf); //FBLOG_WARN("", "Created config: " << glConfig); //if (!glConfig) { //FBLOG_WARN("", "Double-buffer didn't work. Trying single."); glconf = static_cast<GdkGLConfigMode>( GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH ); glConfig = gdk_gl_config_new_by_mode(glconf); FBLOG_WARN("", "Created config: " << glConfig); if (!glConfig) { FBLOG_WARN("", "Couldn't initialize opengl. No idea why, sorry!"); return false; } else { FBLOG_INFO("", "Single-buffer opengl"); } //} else { //FBLOG_INFO("", "Double-buffer opengl"); //} FBLOG_WARN("", "Setting GL capability on Widget: " << drawing_area); gtk_widget_set_gl_capability (drawing_area, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE); gtk_container_add(win->getGtkContainer(), drawing_area); gtk_widget_show(drawing_area); FBLOG_WARN("", "Getting GL Context"); GdkGLContext *glcontext = gtk_widget_get_gl_context (drawing_area); FBLOG_WARN("", "Got GL Context: " << glcontext << " Now getting Drawable:"); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (drawing_area); FBLOG_WARN("", "Got GL Drawable: " << gldrawable); // Attach our OpenGL context to the widget gdk_threads_leave(); rThread = boost::thread(&OpenGLExampleX11::renderThread, this); FBLOG_WARN("", "AttachedEvent end"); }
void FB::BrowserHost::htmlLog(const std::string& str) { FBLOG_INFO("BrowserHost", "Logging to HTML: " << str); this->ScheduleAsyncCall(&FB::BrowserHost::AsyncHtmlLog, new FB::AsyncLogRequest(shared_ptr(), str)); }
void FBTestMathPlugin::StaticInitialize() { FBLOG_INFO("FBTestMathPlugin::StaticInit", "Static Initialize"); // Place one-time initialization stuff here; As of FireBreath 1.4 this should only // be called once per process }