CPMALError CPIM::generatePIUID(iviLink::CUid const& profileUid, iviLink::Service::Uid const& serviceUID, iviLink::Profile::IUid & piuid) { bool remote = false; mIncomingPrfMapMutex.lock(); { if (!mIncomingPrfMap.empty()) { tIncomingPrfMap::iterator it = mIncomingPrfMap.find(std::make_pair(serviceUID, profileUid)); if (it != mIncomingPrfMap.end()) { piuid = it->second; mIncomingPrfMap.erase(it); remote = true; } } } mIncomingPrfMapMutex.unlock(); if (remote) return CPMALError::NoPMALError(gModuleName); CError err = PIM::getPIUID(piuid); if (!err.isNoError()) { LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); return CPMALError(CPMALError::ERROR_PIM_INTERNAL, gModuleName, "no piuid"); } return CPMALError::NoPMALError(gModuleName); }
BOOL CFolderDialog::DoModal(HWND hWnd, LPCTSTR lpszTitle, LPTSTR pDir) { BROWSEINFO bi = {}; bi.hwndOwner = hWnd; bi.lpfn = reinterpret_cast<BFFCALLBACK>(BrowseCallBackProc); bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; bi.lParam = reinterpret_cast<LPARAM>(pDir); bi.lpszTitle = lpszTitle; LPITEMIDLIST pItemID = SHBrowseForFolder(&bi); if (pItemID == nullptr) return FALSE; LPMALLOC pMalloc = nullptr; if (SHGetMalloc(&pMalloc) == E_FAIL) { CError error; error.Message(hWnd, _T("SHGetMalloc Error")); return FALSE; } SHGetPathFromIDList(pItemID, pDir); pMalloc->Free(pItemID); pMalloc->Release(); return TRUE; }
void CPIM::unloadAll() { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); typedef PIM::CProfileInstanceMap::tProfilesList PL; PL profiles; CError err = mInstanceMap.getAllRegisterd(profiles); if (!err.isNoError()) { LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); return; } IProfileManagerCallbacks* clbs = NULL; CPMALComponentMgr* mgr = CPMALComponentMgr::getInstance(); if (mgr) { clbs = mgr->getProfileManagerCallbacks(); } for (PL::iterator it = profiles.begin(); it != profiles.end(); ++it) { Profile::IUid const& piuid = it->first; Profile::CProfile* pp = static_cast<Profile::CProfile*>(it->second); unloadProfileThroughClient(clbs, pp, piuid); } }
// ** When an exception is thrown, execution of the current function is stopped and // jumps directly to the catch block of the innermost exception frame. The // exception mechanism bypasses the normal exit path from a function. Therefore, // you must be sure to delete those memory blocks that would be deleted in a // normal exit. // static void Library::ThrowAssertion(LPCSTR lpszFilename, int nLine, LPCSTR lpszExpression, LPCSTR lpszError/*=NULL*/) { // CAppException* pe = new CAppException(TRUE); // pass true if creating on the heap // Bug: can't just copy LPCTSTR pointer to string, because it might be a temporary object. // The error message was getting overwritten with FE EE's and didn't know what was going on - // a CString was being passed here and then going out of scope because of the throw - // so use strcpy or CStrings // pe->m_pszError = pszError; // store error message // pe->m_strError = "Assertion Failed"; // throw pe; // CError e(_T("Assertion Failed"), TRUE); // e.SetFileLocation(lpszFilename, nLine, lpszExpression); // HandleError(e); // CError e(FALSE); // false because created on the stack // e.SetName(_T("Assertion Failed")); // e.SetSeverity(TRUE); // e.SetFileLocation(lpszFilename, nLine, lpszExpression); // throw &e; CError* pe = new CError(TRUE); if (lpszError==NULL) pe->SetName(_T("Assertion Failed")); else pe->SetName(lpszError); pe->SetSeverity(TRUE); pe->SetFileLocation(lpszFilename, nLine, lpszExpression); throw pe; }
void InitModule() { g_pErrorCS = NULL; g_pModulesCS = NULL; g_pModules = NULL; g_pLocModules = NULL; g_pLocDlls = NULL; g_pNoMemoryError = NULL; ; ::KLSTD_CreateCriticalSection(&g_pModulesCS); g_pErrorCS = g_pModulesCS; ; g_pModules = new modules_t(c_nModulesHashSize); g_pLocModules = new modules_t(c_nModulesHashSize); g_pLocDlls = new map_locmodules_t(c_nModulesHashSize); ; { KLSTD::CAutoPtr<Error> pError; CError* p = NULL; pError.Attach(p = new RcClassImpl<CError>); if(p) { p->Initialize( 0, L"KLSTD", STDE_NOMEMORY, NULL, 0, L"Out Of memory", true); g_pNoMemoryError = pError; }; }; };
void CMediaControlServerProfile::onDisable() { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); CError err = iviLink::Channel::deallocateChannel(mChannelID); if (!err.isNoError()) { LOG4CPLUS_WARN(msLogger, "Unable to deallocate channel: " + static_cast<std::string> (err)); } }
std::tuple<OrmId_t, Orm_t> COrmManager::Create( HandleId_t handleid, const char *table, CError<COrm> &error) { static const std::tuple<OrmId_t, Orm_t> empty_ret(0, nullptr); if (CHandleManager::Get()->IsValidHandle(handleid) == false) { error.set(COrm::Error::INVALID_CONNECTION_HANDLE, "invalid connection handle"); return empty_ret; } if (table == nullptr || strlen(table) == 0) { error.set(COrm::Error::EMPTY_TABLE, "empty table name"); return empty_ret; } OrmId_t id = 1; while (m_Instances.find(id) != m_Instances.end()) ++id; return std::make_tuple(id, std::make_shared<COrm>(handleid, table)); }
LPVOID CFileMap::Open(HANDLE hFile, DWORD Mode) { // Create a file mapping object. if (Mode == FILE_READ) m_hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); else if (Mode == FILE_WRITE) m_hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); if (m_hFileMap == INVALID_HANDLE_VALUE) { CError error; error.Message(GetForegroundWindow(), _T("File mapping error.")); return NULL; } // Get start address of the map view. if (Mode == FILE_READ) m_lpFileMapBase = MapViewOfFile(m_hFileMap, FILE_MAP_READ, 0, 0, 0); else if (Mode == FILE_WRITE) m_lpFileMapBase = MapViewOfFile(m_hFileMap, FILE_MAP_WRITE, 0, 0, 0); if (m_lpFileMapBase == NULL) { CError error; error.Message(GetForegroundWindow(), _T("File mapping error.")); return NULL; } m_lpFileMap = m_lpFileMapBase; return m_lpFileMapBase; }
CConnectivityAgentProxy::CConnectivityAgentProxy() : CThread("CallbackTread"), mpIpc(NULL) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); static char const* const arr[] = { gpCA_UNIX_SOCK_PATH, first_lsn_path, second_lsn_path }; for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) { if (arr[i]) { LOG4CPLUS_INFO(logger, "Trying to connect to connectivity agent using address " + std::string(arr[i])); CIpc* pipc = new CIpc(arr[i], *this); CError err = pipc->connect(); if (err.isNoError()) { mpIpc = pipc; break; } else { LOG4CPLUS_WARN(logger, static_cast<std::string>(err)); delete pipc; } } } if (!mpIpc) { LOG4CPLUS_ERROR(logger, "Unable to connect to connectivity agent"); } start(); }
bool connect() { CError err = CError::NoError(); if (mpIpc == NULL) { char const * addr; if (gpNEGOTIATOR_IPC_ADDR != NULL) { addr = gpNEGOTIATOR_IPC_ADDR; } else { addr = ipcNegotiatorId; } mpIpc = new CIpc(addr, *this); } for (int tryNum = 1; tryNum <= MAX_TRY_COUNT; ++tryNum) { err = mpIpc->connect(); if (err.isNoError()) { return true; } sleep(2); } return false; }
int CProfileRepoServerClb::loop() { CError err = CError::NoError("ProfileRepository","loop"); for (int i = 1; ; ++i) { LOG4CPLUS_INFO(msLogger, "CProfileRepoServerClb::loop() : connection try number: "+ convertIntegerToString(i)); err = mpIpc->waitForConnection(); LOG4CPLUS_INFO(msLogger, "CProfileRepoServerClb::loop() : waitForConnectionEnded()"); if (err.isNoError()) { LOG4CPLUS_INFO(msLogger,"CProfileRepoServerClb::loop() :: *** client connected to server ***"); mConLostSem.wait(); LOG4CPLUS_INFO(msLogger,"CProfileRepoServerClb::loop() :: *** connection lost, exiting ***"); return 0; } else { LOG4CPLUS_INFO(msLogger, static_cast<std::string>(err)); } LOG4CPLUS_INFO(msLogger, "failed connection"); usleep (250000); } return 0; }
void CPmpProtocol::connect() { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); while (mBe) { LOG4CPLUS_INFO(msLogger, "connect attempt"); UInt32 chid = 0; CError err = iviLink::ChannelSupervisor::allocateChannel(this,mTag.c_str(), chid); if (err.isNoError()) { mChannelIdCond.lock(); LOG4CPLUS_INFO(msLogger, "ok chid = " + convertIntegerToString(static_cast<int>(chid))); mChannelId = chid; mChannelIdCond.broadcast(); mChannelIdCond.unlock(); mConnectionLostSem.wait(); } else { LOG4CPLUS_INFO(msLogger, static_cast<std::string>(err)); sleep(1); } } }
void CErrLogMgr::WriteErrLog(CError& exp) { if ( !CatchErrorEnabled() || !ErrLogEnabled() ) { puts(exp.ErrorTitle()); if( exp.ErrorMsg()[0] ) { putchar('\t'); puts(exp.ErrorMsg()); putchar('\n'); } } else { uint64 uCurTime = GetProcessTime(); //如果两次记录log的时间大于interval,我们就要换一个log来记录了 //如果小于这个值,我们仍然使用原来的文件记录 if(uCurTime - m_uLastLogTime > (uint64)m_uInterval) { CErrLogThreadMgr::Inst()->AddCloseErrlogJob(); CreateErrLogFile(); } CErrLogThreadMgr::Inst()->AddWriteErrlogJob(exp,m_strErrInfo.c_str()); m_uLastLogTime = uCurTime; } }
KLSTD_NOTHROW KLERR::ErrorPtr CreateError( const ErrLocAdapt* pLocInfo, const wchar_t* szwModule, int nId, const char* szaFile, int nLine, const wchar_t* szwMessage) throw() { KLSTD::CAutoPtr<KLERR::Error> pResult; try { CError* p = NULL; pResult.Attach(p = new CError); if(p) { p->Initialize(0, szwModule, nId, szaFile, nLine, szwMessage); if(pLocInfo) p->LocSetInfo(*pLocInfo); }; } catch(std::exception& err) { KLERR_TRACE_UNEXPECTED(); }; if(!pResult) pResult = KLERR::g_pNoMemoryError; if(!pResult) abort(); return pResult; };
void CAppManPmpIpcClient::loop() { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); mBe = true; CError err = CError::NoError("",""); for (int i = 1;mBe ; ++i) { LOG4CPLUS_INFO(msLogger, "loop() : connect trying number : " + convertIntegerToString(i)); err = mpIpc->connect(); LOG4CPLUS_INFO(msLogger, "loop() : connect ended"); if (mBe && err.isNoError()) { mNoConnection = false; mConLostSem.wait(); mNoConnection = true; } if (!mBe) { LOG4CPLUS_INFO(msLogger, "loop() :: mBe == false"); break; } LOG4CPLUS_WARN(msLogger, "loop() :: connection failed"); usleep(250000); } }
void CProfileRepoServerClb::addProfile(const RepoRequest * req, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); CError err = mProfileDB.addProfile(bufferToString(req->data)); UInt32 code = err.getCode(); memcpy (pResponseBuffer, &code,4); bufferSize = 4; }
void CClimateClientProfile::onDisable() { CError err = iviLink::Channel::deallocateChannel(mChannelID); if (!err.isNoError()) { LOG4CPLUS_WARN(msLogger, "Unable to deallocate channel: " + static_cast<std::string>(err)); } }
void CSourceFilesProcessor::Error( const CError& error ) { std::cerr << error.UserMessage() << std::endl; if( error.Severity() == ES_FatalError ) { file.clear( std::ios_base::eofbit ); std::cin.clear( std::ios_base::eofbit ); } }
CError write(std::pair<K, V> const& val) { CError err = write(val.first); if (!err.isNoError()) return err; err = write(val.second); if (!err.isNoError()) return err; return CError::NoError(moduleName); }
CError read(std::pair<K, V> & val) { CError err = read(val.first); if (!err.isNoError()) return err; err = read(val.second); if (!err.isNoError()) return err; return CError::NoError(moduleName); }
void ReceiverProfile<T,I>::onDisable() { LOG4CPLUS_TRACE_METHOD( (logger<T,I>()), __PRETTY_FUNCTION__ ); CError err = iviLink::Channel::deallocateChannel(mChannelID); if (!err.isNoError()) { LOG4CPLUS_ERROR((logger<T,I>()), "Unable to deallocate channel: " + static_cast<std::string>(err)); } else mChannelID = 0; }
void CMediaControlServerProfile::onChannelDeleted(const UInt32 channel_id) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); if (mChannelID == channel_id) mChannelID = 0; CError err = iviLink::Channel::deallocateChannel(channel_id); if (!err.isNoError()) { LOG4CPLUS_WARN(msLogger, "Unable to deallocate channel: " + static_cast<std::string> (err)); } }
void CProfileRepoServerClb::removeProfileImplementationPl(const RepoRequest * req, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); UID uid(bufferToString(req->data)); int pos = stringInBufSize(uid.value); std::string platform = bufferToString(req->data + pos); CError err = mProfileDB.removeProfileImplementation(uid,platform); UInt32 code = err.getCode(); memcpy (pResponseBuffer, &code, 4); bufferSize = 4; }
CError CBufferWriter::write<std::string>(std::string const& val) { UInt32 valSize = val.size(); CError err = write(valSize); if (!err.isNoError()) return err; if (valSize > mFullSize - mUsedSize) return CError(1, moduleName, CError::ERROR, "insufficient buffer size (from std::string write)"); memcpy(mpBuffer + mUsedSize, val.c_str(), valSize); mUsedSize += valSize; return CError::NoError(moduleName); }
CError CUndefinedReferenceValidator::Validate(C_FUNCTION_SYNTAX& syntax, C_CONTEXT& context) const { CError result; if (!ValidateReference(syntax.GetLiveNamespace(), syntax.GetName(), EIdentifierType::Function, context)) { result.SetSource(EErrorSource::Producing); result.SetLiveLine(syntax.GetLiveLine()); result.SetDescription(CWStringTemplate(L"Funtion:'%x' has not been defined").Format(syntax.GetName())); } return move(result); }
void ReceiverProfile<T,I>::onChannelDeleted(const UInt32 channel_id) { LOG4CPLUS_TRACE_METHOD((logger<T,I>()), __PRETTY_FUNCTION__ ); if (mChannelID == channel_id) mChannelID = 0; CError err = iviLink::Channel::deallocateChannel(channel_id); if (!err.isNoError()) { LOG4CPLUS_WARN((logger<T,I>()), "Unable to deallocate channel: " + static_cast<std::string>(err)); } }
void sendMessage(UInt8 const* pPayload, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize) { bool con_res = connect(); assert(con_res); CError err = mpIpc->request(id++, pPayload, payloadSize, pResponseBuffer, bufferSize); if (err.isNoError()) { } else { } mpIpc->disconnect(); }
void CProfileRepoServerClb::addProfileImplementation(const RepoRequest * req, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); UID uid(bufferToString(req->data)); int pos = stringInBufSize(uid.value); iviLink::LibDescriptor ld; ld.libPath = bufferToString(req->data + pos); pos += stringInBufSize(ld.libPath); ld.platform = bufferToString(req->data + pos); CError err = mProfileDB.addProfileImplementation(uid,ld); UInt32 code = err.getCode(); memcpy (pResponseBuffer, &code, 4); bufferSize = 4; }
CError CBufferReader::read<std::string>(std::string & val) { UInt32 valSize = 0; CError err = read(valSize); if (!err.isNoError()) return err; if (valSize > mFullSize - mUsedSize) return CError(1, moduleName, CError::ERROR, "insufficient buffer size (from std::string write)"); val.assign(reinterpret_cast<char const*>(mpBuffer + mUsedSize), valSize); mUsedSize += valSize; return err; }
CError CNullUnaryOperationValidator::Validate(C_OPERATION_SYNTAX& syntax, C_CONTEXT& context) const { CError result; if (syntax.GetRightOperandID() == NONE_ID) { result.SetSource(EErrorSource::Producing); result.SetLiveLine(syntax.GetLiveLine()); result.SetDescription(CWStringTemplate(L"operand of operation:'%x' is invalid"). Format(COperationTypeEnum(syntax.GetOperationType()).ToString())); } return move(result); }