SampleSensorFactory::SampleSensorFactory() : m_sensorIDCount(0) { DataTypeManager& dataTypeMgr = DataTypeManager::GetSingleton(); DataTypeDescription typeDesc( "ZMQSensor", "ZMQ Sensor", "ZMQ Sensor Plugin" ); typeDesc.typeIsA.push_back( Types::Sensor ); Types::SampleSensor = dataTypeMgr.RegisterDataType( typeDesc, kSampleSensorGUID ); RegisterProperties(); SensorManager::GetSingleton().RegisterSensorFactory( kSensorTypeSampleSensor, this ); }
BOOL CCopyHandlerApp::InitInstance() { // ================================= Crash handling ======================================= SetUnhandledExceptionFilter(&MyUnhandledExceptionFilter); // ================================= Configuration ======================================== CString strPath; CString strCfgPath; CString strLogPath; // note that the GetProgramDataPath() below should create a directory; ExpandPath() could // depend on the directory to be created earlier if(!GetProgramDataPath(strPath)) { AfxMessageBox(_T("Cannot initialize Copy Handler (data path cannot be established)."), MB_ICONERROR | MB_OK); return FALSE; } strCfgPath = strPath + _T("\\ch.ini"); // initialize configuration file m_config.set_callback(ConfigPropertyChangedCallback, NULL); // read the configuration try { m_config.read(strCfgPath); } catch(...) { } // set working dir for the engine icpf::config& rConfig = GetConfig(); // rConfig.SetBasePath(strPath); // register all properties RegisterProperties(&rConfig); // ================================= Logging ======================================== // initialize the global log file if it is requested by configuration file strLogPath = strPath + + _T("\\ch.log"); chcore::TLogger& rLogger = chcore::TLogger::Acquire(); try { rLogger.init(strLogPath, (int_t)m_config.get_signed_num(PP_LOGMAXSIZE), (int_t)rConfig.get_unsigned_num(PP_LOGLEVEL), false, false); rLogger.Enable(m_config.get_bool(PP_LOGENABLELOGGING)); } catch(...) { BOOST_ASSERT(false); } LOG_INFO(_T("============================ Initializing Copy Handler ============================")); LOG_INFO(_T("")); // ================================= COM ======================================== LOG_INFO(_T("Initializing COM")); HRESULT hResult = CoInitializeEx(NULL, COINIT_MULTITHREADED); if(FAILED(hResult)) { CString strMsg; strMsg.Format(_T("Cannot initialize COM, the application will now exit (result = 0x%lx)"), hResult); LOG_ERROR(strMsg); AfxMessageBox(strMsg, MB_ICONERROR | MB_OK); return FALSE; } // ================================= Resource manager ======================================== LOG_INFO(_T("Initializing resource manager...")); ictranslate::CResourceManager& rResManager = ictranslate::CResourceManager::Acquire(); // set current language TCHAR szPath[_MAX_PATH]; rResManager.Init(AfxGetInstanceHandle()); rResManager.SetCallback(ResManCallback); rConfig.get_string(PP_PLANGUAGE, szPath, _MAX_PATH); TRACE(_T("Help path=%s\n"), szPath); if(!rResManager.SetLanguage(ExpandPath(szPath))) { TCHAR szData[2048]; _sntprintf(szData, 2048, _T("Couldn't find the language file specified in configuration file:\n%s\nPlease correct this path to point the language file to use.\nProgram will now exit."), szPath); LOG_ERROR(szData); AfxMessageBox(szData, MB_ICONSTOP | MB_OK); return FALSE; } UpdateHelpPaths(); // for dialogs ictranslate::CLanguageDialog::SetResManager(&rResManager); EnableHtmlHelp(); // ================================= Checking for running instances of CH ======================================== // check instance - return false if it's the second one LOG_INFO(_T("Checking for other running instances of Copy Handler")); if(!IsFirstInstance()) { LOG_WARNING(_T("Other instance of Copy Handler is already running. Exiting.")); MsgBox(IDS_ONECOPY_STRING); return FALSE; } // ================================= Common controls ======================================== LOG_INFO(_T("Initializing GUI common controls")); // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); // ================================= Shell extension ======================================== LOG_INFO(_T("Initializing shared memory for communication with shell extension")); m_hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CSharedConfigStruct), _T("CHLMFile")); if (m_hMapObject == NULL) return FALSE; // Get a pointer to the file-mapped shared memory. g_pscsShared=(CSharedConfigStruct*)MapViewOfFile(m_hMapObject, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); if (g_pscsShared == NULL) return FALSE; LOG_INFO(_T("Checking shell extension compatibility")); // calculate ch version long lCHVersion = PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4; // check the version of shell extension LONG lVersion = 0; BSTR bstrVersion = NULL; hResult = CoCreateInstance(CLSID_CShellExtControl, NULL, CLSCTX_ALL, IID_IShellExtControl, (void**)&m_piShellExtControl); if(SUCCEEDED(hResult) && !m_piShellExtControl) hResult = E_FAIL; if(SUCCEEDED(hResult)) hResult = m_piShellExtControl->GetVersion(&lVersion, &bstrVersion); if(SUCCEEDED(hResult) && lVersion == lCHVersion) hResult = m_piShellExtControl->SetFlags(eShellExt_Enabled, eShellExt_Enabled); if(FAILED(hResult) || lCHVersion != lVersion) { CString strMsg; strMsg.Format(_T("Shell extension has different version (0x%lx) than Copy Handler (0x%lx). Shell extension will be disabled."), lVersion, lCHVersion); LOG_WARNING(strMsg); MsgBox(IDS_SHELL_EXTENSION_MISMATCH_STRING); if(m_piShellExtControl) m_piShellExtControl->SetFlags(0, eShellExt_Enabled); } if(bstrVersion) ::SysFreeString(bstrVersion); // ================================= Initial settings ======================================== LOG_INFO(_T("Applying initial settings")); // set this process priority class HANDLE hProcess=GetCurrentProcess(); ::SetPriorityClass(hProcess, (DWORD)rConfig.get_signed_num(PP_PPROCESSPRIORITYCLASS)); #ifndef _DEBUG // for easier writing the program - doesn't collide with std CH // set "run with system" registry settings SetAutorun(rConfig.get_bool(PP_PRELOADAFTERRESTART)); #endif // ================================= Main window ======================================== LOG_INFO(_T("Creating main application window")); // create main window m_pMainWindow=new CMainWnd; if (!((CMainWnd*)m_pMainWindow)->Create()) return FALSE; // will be deleted at destructor m_pMainWnd = m_pMainWindow; CWinApp::InitInstance(); LOG_INFO(_T("Copy Handler initialized successfully")); return TRUE; }