bool Objects::GetChildId(int nId, const std::string& sChildName, int& nChildId) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; bool bResult = false; int nResult = sqlite3_prepare_v2(pDb, "SELECT id FROM objects WHERE parentid=? AND name=?", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); try { nResult = sqlite3_bind_int(pVm, 1, nId); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); nResult = sqlite3_bind_text(pVm, 2, sChildName.c_str(), sChildName.size(), SQLITE_STATIC); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); // get data if (sqlite3_step(pVm) == SQLITE_ROW) { bResult = true; nChildId = sqlite3_column_int(pVm, 0); } } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); return bResult; }
void DynamicLibrary::Load(const std::string& sLibName, bool bRawName /*= false*/) { STAFF_ASSERT(!m_pDynLib, "Library already loaded"); if (bRawName) { #ifdef WIN32 m_pDynLib = LoadLibraryA(sLibName.c_str()); #else m_pDynLib = dlopen(sLibName.c_str(), RTLD_LAZY); #endif } else { #ifdef WIN32 m_pDynLib = LoadLibraryA((sLibName + STAFF_LIBRARY_EXT).c_str()); #else std::string::size_type nPos = sLibName.find_last_of('/'); if (nPos == std::string::npos) { m_pDynLib = dlopen((STAFF_LIBRARY_PREFIX + sLibName + STAFF_LIBRARY_EXT).c_str(), RTLD_LAZY); } else { m_pDynLib = dlopen((sLibName.substr(nPos) + STAFF_LIBRARY_PREFIX + sLibName.substr(nPos + 1) + STAFF_LIBRARY_EXT).c_str(), RTLD_LAZY); } #endif } STAFF_ASSERT(m_pDynLib, "Failed load library [" + sLibName + "]: " + Error::GetLastLibraryErrorStr()); m_sName = sLibName; }
void Objects::GetParentId(int nId, int& nParentId) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; int nResult = sqlite3_prepare_v2(pDb, "SELECT parentid FROM objects WHERE id=?", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); try { nResult = sqlite3_bind_int(pVm, 1, nId); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); // get data STAFF_ASSERT(sqlite3_step(pVm) == SQLITE_ROW, "Object with id is not found: " + std::string(sqlite3_errmsg(pDb))); nParentId = sqlite3_column_int(pVm, 0); } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); }
void PostgresProvider::Init(const xml::Element& rConfig) { // initialize connection const xml::Element& rConnection = rConfig.GetChildElementByName("connection"); m_pImpl->m_sHost = rConnection.GetChildElementByName("host").GetTextValue(); m_pImpl->m_sPort = rConnection.GetChildElementByName("port").GetTextValue(); m_pImpl->m_sDataBase = rConnection.GetChildElementByName("db").GetTextValue(); m_pImpl->m_sLogin = rConnection.GetChildElementByName("login").GetTextValue(); m_pImpl->m_sPassword = rConnection.GetChildElementByName("password").GetTextValue(); STAFF_ASSERT(!m_pImpl->m_pConn, "Already connected"); m_pImpl->m_pConn = PQsetdbLogin(m_pImpl->m_sHost.c_str(), m_pImpl->m_sPort.c_str(), "", "", m_pImpl->m_sDataBase.c_str(), m_pImpl->m_sLogin.c_str(), m_pImpl->m_sPassword.c_str()); STAFF_ASSERT(m_pImpl->m_pConn, "Failed to set db login"); if (PQstatus(m_pImpl->m_pConn) != CONNECTION_OK) { std::string sError = std::string("Failed to login: "******"UTF8"); STAFF_ASSERT(nResult == 0, std::string("error setting encoding: ") + PQerrorMessage(m_pImpl->m_pConn)); }
void Objects::GetById(int nId, Object& rstObject) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; int nResult = sqlite3_prepare_v2(pDb, "SELECT id, name, description, parentid FROM objects WHERE id=?", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); try { nResult = sqlite3_bind_int(pVm, 1, nId); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); // get data STAFF_ASSERT(sqlite3_step(pVm) == SQLITE_ROW, "Object with id is not found: " + std::string(sqlite3_errmsg(pDb))); rstObject.nId = sqlite3_column_int(pVm, 0); const char* szTmp = reinterpret_cast<const char*>(sqlite3_column_text(pVm, 1)); STAFF_ASSERT(szTmp, "Failed to get object name"); rstObject.sName = szTmp; szTmp = reinterpret_cast<const char*>(sqlite3_column_text(pVm, 2)); rstObject.sDescription = szTmp != NULL ? szTmp : ""; rstObject.nParentId = sqlite3_column_int(pVm, 3); } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); }
void DbConn::Open() { ++m_nCounter; if (m_nCounter > 1) { return; } STAFF_ASSERT(m_pDb == NULL, "Staff database is already opened"); sqlite3_enable_shared_cache(1); // open db int nResult = sqlite3_open((Runtime::Inst().GetStaffHome() + "/db/staff.db").c_str(), &m_pDb); STAFF_ASSERT(nResult == SQLITE_OK, "Failed to open staff database"); sqlite3_stmt* pVm = NULL; nResult = sqlite3_prepare_v2(m_pDb, "PRAGMA foreign_keys = ON;", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(m_pDb)); try { STAFF_ASSERT(sqlite3_step(pVm) == SQLITE_DONE, "Failed to enable foreign keys: " + std::string(sqlite3_errmsg(m_pDb))); } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(m_pDb)); }
void Objects::Remove(int nId) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; int nResult = sqlite3_prepare_v2(pDb, "DELETE FROM objects WHERE id=?", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); try { nResult = sqlite3_bind_int(pVm, 1, nId); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); // get data STAFF_ASSERT(sqlite3_step(pVm) == SQLITE_DONE, "Object with id is not found: " + std::string(sqlite3_errmsg(pDb))); // get inserted object id nId = static_cast<int>(sqlite3_last_insert_rowid(pDb)); } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); }
void Objects::SetDescription(int nId, const std::string& sDescription) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; int nResult = sqlite3_prepare_v2(pDb, "UPDATE objects SET description = ? WHERE id=?", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); try { nResult = sqlite3_bind_text(pVm, 1, sDescription.c_str(), sDescription.size(), SQLITE_STATIC); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); nResult = sqlite3_bind_int(pVm, 2, nId); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); // get data STAFF_ASSERT(sqlite3_step(pVm) == SQLITE_DONE, "Failed to set object description: " + std::string(sqlite3_errmsg(pDb))); } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); }
void my_solarWrapper::Invoke(staff::Operation& rOperation, const std::string& sSessionId, const std::string& sInstanceId) { const staff::DataObject& rRequest = rOperation.Request(); const std::string& sOperationName = rOperation.GetName(); if (sOperationName == "GetServiceDescription") { rOperation.SetResponse(GetServiceDescription()); } else if (sOperationName == "CreateInstance") { staff::ServiceInstanceManager::Inst().CreateServiceInstance(sSessionId, m_sName, rRequest.GetChildTextByLocalName("sInstanceId")); } else if (sOperationName == "FreeInstance") { staff::ServiceInstanceManager::Inst().FreeServiceInstance(sSessionId, m_sName, rRequest.GetChildTextByLocalName("sInstanceId")); } else { staff::SharedPtr<my_solarImpl> tpServiceImpl = GetImpl(sSessionId, sInstanceId); if (sOperationName == "solarcreate") { rOperation.Result().SetValue(tpServiceImpl->solarcreate()); } else if (sOperationName == "solarinit") { int gen_mode_v = 0; int gen_status_v = 0; int panel_type_v = 0; STAFF_ASSERT(rRequest.GetChildValueByLocalName("gen_mode_v", gen_mode_v), "Invalid value for element gen_mode_v"); STAFF_ASSERT(rRequest.GetChildValueByLocalName("gen_status_v", gen_status_v), "Invalid value for element gen_status_v"); STAFF_ASSERT(rRequest.GetChildValueByLocalName("panel_type_v", panel_type_v), "Invalid value for element panel_type_v"); rOperation.Result().SetValue(tpServiceImpl->solarinit(gen_mode_v, gen_status_v, panel_type_v)); } else if (sOperationName == "solarsync") { int t0 = 0; int t1 = 0; STAFF_ASSERT(rRequest.GetChildValueByLocalName("t0", t0), "Invalid value for element t0"); STAFF_ASSERT(rRequest.GetChildValueByLocalName("t1", t1), "Invalid value for element t1"); rOperation.Result().SetValue(tpServiceImpl->solarsync(t0, t1)); } else { STAFF_THROW(staff::RemoteException, "Unknown Operation: " + rOperation.GetName()); } rOperation.GetResponse().SetNamespaceUriGenPrefix("http://tempui.org/my_solar"); } }
int main(int nArgs, const char* paszArgs[]) { std::string sRestMethod = "POST"; std::string sAddress = "http://localhost:9090/axis2/services/echo/echoString"; if (nArgs > 1) { if (strcmp(paszArgs[1], "-h") == 0) { std::cerr << "Usage: " << paszArgs[0] << "[ -m<REST_METHOD>][ <ENDPOINT_URL>]" << std::endl << " Valid <REST_METHOD> are: POST(default), GET, HEAD, DELETE, PUT" << std::endl << "NOTE: You can test for other HTTP methods by changing the services.xml of the echo service" << std::endl << " and providing the correct REST HTTP method and the location to be used for operation." << std::endl << " Also note that you have to restart the server after changing the services.xml." << std::endl; return 0; } for (int nArg = 1; nArg < nArgs; ++nArg) { if (strncmp(paszArgs[nArg], "-m", 2) == 0) { sRestMethod = paszArgs[nArg] + 2; } else { sAddress = paszArgs[nArg]; } } } std::cout << "Using method: " << sRestMethod << std::endl; std::cout << "Using address: " << sAddress << std::endl; try { std::auto_ptr< Echo > pEcho(::staff::ServiceFactory::Inst().GetService< Echo >(sAddress)); STAFF_ASSERT(pEcho.get(), "Cannot get client for service samples.Echo!"); // get service client to set REST method staff::ServiceClient* pClient = pEcho->GetClient(); STAFF_ASSERT(pClient, "Cannot get ServiceClient"); staff::Options& rOptions = pClient->GetOptions(); // setting rest method rOptions.SetHttpMethod(sRestMethod); // Invoke Your service here: std::string tEchoStringResult = pEcho->EchoString("Hello World!"); staff::LogInfo() << "EchoString result: " << tEchoStringResult; } STAFF_CATCH_ALL return 0; }
int main(int /*nArgs*/, const char* /*paszArgs*/[]) { try { std::auto_ptr< Echo > pEcho(::staff::ServiceFactory::Inst().GetService< Echo >()); STAFF_ASSERT(pEcho.get(), "Cannot get client for service echo!"); // Invoke Your service here: EchoEchoStringCallback tEchoEchoStringCallback; pEcho->EchoString("Hello World!", tEchoEchoStringCallback); // Wait for asynch call is completed // Please note, that you cannot call any operation of this client // until this asynchronous request is completed. // To call operation while request is processing, please use another copy of client. while (!tEchoEchoStringCallback.IsCompleted()) { staff::Thread::Sleep(1000); } } STAFF_CATCH_ALL return 0; }
virtual bool GetNextResult(StringList& rResult) { STAFF_ASSERT(m_pResult, "Execute was not called"); if (m_nCurrentRow == m_nRowsCount) { return false; } if (rResult.size() != m_nFieldsCount) { rResult.resize(m_nFieldsCount); } int nField = 0; const char* szResult = NULL; for (StringList::iterator itResult = rResult.begin(); itResult != rResult.end(); ++itResult, ++nField) { if (PQgetisnull(m_pResult, m_nCurrentRow, nField)) { *itResult = STAFF_DAS_NULL_VALUE; } else { szResult = PQgetvalue(m_pResult, m_nCurrentRow, nField); *itResult = szResult ? szResult : STAFF_DAS_NULL_VALUE; } } ++m_nCurrentRow; return true; }
IssuedTicketList CheckerImpl::GetAllTickets() const { IssuedTicketList lsResult; staff::SharedPtr<Issuer> pIssuer = staff::ServiceInstanceManager::Inst().ServiceInstance(this, "samples.sharedtypes.Issuer"); STAFF_ASSERT(pIssuer, "Service [samples.calc.Issuer] is not found"); ticket::TicketsList lsTickets = pIssuer->GetAllTickets(); for (ticket::TicketsList::const_iterator itTicket = lsTickets.begin(); itTicket != lsTickets.end(); ++itTicket) { IssuedTicket stTicket; stTicket.eType = itTicket->eType; stTicket.nId = itTicket->nId; stTicket.sOwner = itTicket->sOwner; IntSet::const_iterator itUsedTicket = m_setUsedIds.find(stTicket.nId); stTicket.bUsed = itUsedTicket != m_setUsedIds.end(); lsResult.push_back(stTicket); } return lsResult; }
void ProviderService::OnDestroy() { STAFF_ASSERT(m_pDataSource, "Not initialized"); const ProvidersInfoList& rlsProviders = m_pDataSource->GetProviders(); for (ProvidersInfoList::const_iterator itProvider = rlsProviders.begin(); itProvider != rlsProviders.end(); ++itProvider) { const xml::Element& rConfigElem = itProvider->tConfig; const xml::Element* pOnDestroy = rConfigElem.FindChildElementByName("ondestroy"); if (pOnDestroy) { const xml::Element* pScript = pOnDestroy->FindChildElementByName("script"); if (!pScript) { pScript = pOnDestroy->FindChildElementByName("execute"); } if (pScript) { ScriptExecuter tScriptExecuter(*m_pDataSource, GetProviders()); tScriptExecuter.SetSessionStorage(m_mSessionStorage, m_tSessionStorageMutex); tScriptExecuter.Process(*pScript); } } } }
int main(int /*nArgs*/, const char* /*paszArgs*/[]) { try { std::auto_ptr< ::samples::binarydata::KeyGenerator > pKeyGenerator(::staff::ServiceFactory::Inst().GetService< ::samples::binarydata::KeyGenerator >()); STAFF_ASSERT(pKeyGenerator.get(), "Cannot get client for service samples.binarydata.KeyGenerator!"); // Invoke Your service here: staff::hexBinary tHexKey = pKeyGenerator->GenerateHexKey(0x12345678); staff::LogInfo() << "Generated HexKey: " << tHexKey.ToString(); staff::LogInfo() << "HexKey is valid: " << pKeyGenerator->ValidateHexKey(tHexKey); // do some actions with binary data here staff::LogInfo() << "dump of HexKey:"; OutputData(tHexKey.GetBytes()); // do the same with base64 staff::base64Binary tBase64Key = pKeyGenerator->GenerateBase64Key(0x12345678); staff::LogInfo() << "GenerateBase64Key result: " << tBase64Key.ToString(); staff::LogInfo() << "Base64Key is valid: " << pKeyGenerator->ValidateBase64Key(tBase64Key); // do some actions with binary data here staff::LogInfo() << "dump of Base64Key:"; OutputData(tBase64Key.GetBytes()); } STAFF_CATCH_ALL return 0; }
void ProviderService::Invoke(const DataObject& rdoOperation, DataObject& rdoResult) { STAFF_ASSERT(m_pDataSource, "Not initialized"); ScriptExecuter tScriptExecuter(*m_pDataSource, GetProviders()); tScriptExecuter.SetSessionStorage(m_mSessionStorage, m_tSessionStorageMutex); tScriptExecuter.Process(rdoOperation, rdoResult); }
void* DynamicLibrary::GetSymbol(const std::string& sSymName) const { STAFF_ASSERT(m_pDynLib, "Library is not loaded"); void* pSym = #ifdef WIN32 #ifdef __MINGW32__ reinterpret_cast<void*>(GetProcAddress(reinterpret_cast<HMODULE>(m_pDynLib), sSymName.c_str())); #else GetProcAddress(reinterpret_cast<HMODULE>(m_pDynLib), sSymName.c_str()); #endif #else dlsym(m_pDynLib, sSymName.c_str()); #endif STAFF_ASSERT(pSym, "Failed to get symbol [" + sSymName + "]: " + Error::GetLastLibraryErrorStr()); return pSym; }
void DynamicLibrary::UnloadLibrary() { STAFF_ASSERT(m_pDynLib, "Library is not loaded"); #ifdef WIN32 FreeLibrary(reinterpret_cast<HMODULE>(m_pDynLib)); #else dlclose(m_pDynLib); #endif m_pDynLib = NULL; }
void Objects::GetByPathName(const std::string& sName, Object& rstObject) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; std::string sRequest = "0"; std::string::size_type nPos = sName.find_first_of('.'); std::string::size_type nBegin = 0; for (; nPos != std::string::npos; nBegin = nPos + 1, nPos = sName.find_first_of('.', nBegin)) { sRequest = "SELECT id FROM objects WHERE name = '" + sName.substr(nBegin, nPos - nBegin) + "' AND parentid = (" + sRequest + ")"; } sRequest = "SELECT id, name, description, parentid FROM objects WHERE name = '" + sName.substr(nBegin, nPos - nBegin) + "' AND parentid = (" + sRequest + ")"; int nResult = sqlite3_prepare_v2(pDb, sRequest.c_str(), sRequest.size(), &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); try { // get data STAFF_ASSERT(sqlite3_step(pVm) == SQLITE_ROW, "Object with id is not found: " + std::string(sqlite3_errmsg(pDb))); rstObject.nId = sqlite3_column_int(pVm, 0); const char* szTmp = reinterpret_cast<const char*>(sqlite3_column_text(pVm, 1)); STAFF_ASSERT(szTmp, "Failed to get object name"); rstObject.sName = szTmp; szTmp = reinterpret_cast<const char*>(sqlite3_column_text(pVm, 2)); rstObject.sDescription = szTmp != NULL ? szTmp : ""; rstObject.nParentId = sqlite3_column_int(pVm, 3); } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); }
virtual void GetFieldsNames(StringList& rNames) { STAFF_ASSERT(m_pResult, "Execute was not called"); if (rNames.size() != m_nFieldsCount) { rNames.resize(m_nFieldsCount); } const char* szFieldName = NULL; int nField = 0; for (StringList::iterator itItem = rNames.begin(); itItem != rNames.end(); ++itItem, ++nField) { szFieldName = PQfname(m_pResult, nField); STAFF_ASSERT(szFieldName, "Error while getting field name"); *itItem = szFieldName; } }
bool Objects::GetIdByPathName(const std::string& sName, int& nId) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; std::string sRequest = "0"; std::string::size_type nPos = sName.find_first_of('.'); std::string::size_type nBegin = 0; bool bFound = false; for (; nPos != std::string::npos; nBegin = nPos + 1, nPos = sName.find_first_of('.', nBegin)) { sRequest = "SELECT id FROM objects WHERE name = '" + sName.substr(nBegin, nPos - nBegin) + "' AND parentid = (" + sRequest + ")"; } sRequest = "SELECT id FROM objects WHERE name = '" + sName.substr(nBegin, nPos - nBegin) + "' AND parentid = (" + sRequest + ")"; int nResult = sqlite3_prepare_v2(pDb, sRequest.c_str(), sRequest.size(), &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); try { // get data if (sqlite3_step(pVm) == SQLITE_ROW) { nId = sqlite3_column_int(pVm, 0); bFound = true; } } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); return bFound; }
void DbConn::BeginTransaction() { sqlite3_stmt* pVm = NULL; int nResult = sqlite3_prepare_v2(m_pDb, "BEGIN TRANSACTION", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(m_pDb)); try { STAFF_ASSERT(sqlite3_step(pVm) == SQLITE_DONE, "Failed to begin transaction: " + std::string(sqlite3_errmsg(m_pDb))); } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(m_pDb)); }
void Objects::Add(const std::string& sName, const std::string& sDescription, int nParentId, int& nId) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; int nResult = sqlite3_prepare_v2(pDb, "INSERT INTO objects(name, description, parentid) VALUES(?, ?, ?)", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); try { nResult = sqlite3_bind_text(pVm, 1, sName.c_str(), sName.size(), SQLITE_STATIC); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); nResult = sqlite3_bind_text(pVm, 2, sDescription.c_str(), sDescription.size(), SQLITE_STATIC); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); nResult = sqlite3_bind_int(pVm, 3, nParentId); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); // get data STAFF_ASSERT(sqlite3_step(pVm) == SQLITE_DONE, "Failed to add object: " + std::string(sqlite3_errmsg(pDb))); // get inserted object id nId = static_cast<int>(sqlite3_last_insert_rowid(pDb)); } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); }
bool File::Mkdir() { int nRes = #ifndef WIN32 mkdir(m_sPath.c_str(), 0755); #else _mkdir(m_sPath.c_str()); #endif STAFF_ASSERT(nRes != -1 || errno == EEXIST, "Failed to create dir [" + m_sPath + "]: " + strerror(errno)); return !nRes; }
void Objects::GetChilds(int nId, ObjectsList& rlsChilds) { sqlite3* pDb = DbConn::GetDb(); sqlite3_stmt* pVm = NULL; int nResult = sqlite3_prepare_v2(pDb, "SELECT id, name, description, parentid FROM objects WHERE parentid=?", -1, &pVm, NULL); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); rlsChilds.clear(); try { nResult = sqlite3_bind_int(pVm, 1, nId); STAFF_ASSERT(nResult == SQLITE_OK, sqlite3_errmsg(pDb)); // get data while (sqlite3_step(pVm) == SQLITE_ROW) { Object stObject; stObject.nId = sqlite3_column_int(pVm, 0); const char* szTmp = reinterpret_cast<const char*>(sqlite3_column_text(pVm, 1)); STAFF_ASSERT(szTmp, "Failed to get object name"); stObject.sName = szTmp; szTmp = reinterpret_cast<const char*>(sqlite3_column_text(pVm, 2)); stObject.sDescription = szTmp != NULL ? szTmp : ""; stObject.nParentId = sqlite3_column_int(pVm, 3); rlsChilds.push_back(stObject); } } catch(...) { sqlite3_finalize(pVm); throw; } STAFF_ASSERT(sqlite3_finalize(pVm) == SQLITE_OK, sqlite3_errmsg(pDb)); }
int main(int nArgs, const char* paszArgs[]) { try { { SharedPtr< ::staff::das::DataAccessService > pDataAccessService = ::staff::ServiceFactory::Inst().GetService< ::staff::das::DataAccessService >(); STAFF_ASSERT(pDataAccessService, "Cannot get client for service staff.das.DataAccessService!"); // Invoke Your service here: std::cout << "Providers: \n"; ::staff::das::StringList lsProviders = pDataAccessService->GetProviders(); for (::staff::das::StringList::const_iterator itProvider = lsProviders.begin(); itProvider != lsProviders.end(); ++itProvider) { std::cout << " - " << *itProvider << "\n"; } std::cout << "DataSources: \n"; ::staff::das::StringList lsDataSources = pDataAccessService->GetDataSources(); for (::staff::das::StringList::const_iterator itDataSource = lsDataSources.begin(); itDataSource != lsDataSources.end(); ++itDataSource) { std::cout << " - " << *itDataSource << "\n"; } pDataAccessService->SetDataSource("staff.das.samples.Users"); staff::DataObject tdoInterface = pDataAccessService->GetInterface(); std::cout << "\n\n----------------------\n" << tdoInterface.ToString() << "\n------------------------\n\n"; staff::DataObject tdoRequest("GetAllUsers"); staff::DataObject tdoResult = pDataAccessService->Invoke(tdoRequest); std::cout << "\nRESULT:\n----------------------\n" << tdoResult.ToString() << "\n------------------------\n\n"; pDataAccessService->FreeDataSource(); } } catch(const staff::RemoteException& rEx) { LogError() << rEx.GetDescr(); } STAFF_CATCH_ALL return 0; }
void DbConn::Close() { if (m_nCounter > 1) { --m_nCounter; return; } STAFF_ASSERT(m_pDb != NULL, "Staff database is not opened"); // free all prepared ops sqlite3_stmt* pStmt = NULL; while ((pStmt = sqlite3_next_stmt(m_pDb, 0)) != NULL) { sqlite3_finalize(pStmt); } // close db int nResult = sqlite3_close(m_pDb); STAFF_ASSERT(nResult == SQLITE_OK, "Failed to close staff database"); m_pDb = NULL; --m_nCounter; }
void Fdisk::test(QString databaseName) { try { //qDebug() << "test fdisk connection"; std::auto_ptr< ::FdExport > pFdExport(::staff::ServiceFactory::Inst().GetService< ::FdExport >()); STAFF_ASSERT(pFdExport.get(), "Cannot get client for service FdExport!"); std::string bewerbsID=databaseName.toStdString(); staff::Optional<std::string> user = staff::Optional<std::string>("BewerbsexportZeilhofer"); staff::Optional<std::string> password = staff::Optional<std::string>("Ubu6Son6"); staff::Optional<std::string> instanz = staff::Optional<std::string>("LFKDO Niederösterreich"); const staff::Optional< ::FdWsAuthorizeReturn >& AuthorizeResponse = pFdExport->Authorize(user, password, instanz); //qDebug() << "authorize: " << strConv(AuthorizeResponse->statusMessage); staff::Optional<std::string> md5session = AuthorizeResponse->md5session; // save the session key! staff::Optional< ::FdWsPrepareDataRequest > xmlRequest; xmlRequest->type = FdWsExportType_Wasserdienstleistungsbewerbe; FdWsWasserdienstleistungsbewerbeRequest wdlbReq; wdlbReq.filterGroup = createFilter(bewerbsID); xmlRequest->wasserdienstleistungsbewerbe = wdlbReq; //qDebug() << "Prepare Data on Server for BewerbsID = " << strConv(bewerbsID) << "..."; const staff::Optional< ::FdWsPrepareDataReturn >& PrepareDataResponse = pFdExport->PrepareData(md5session, xmlRequest); //qDebug() << "PrepareData result: " << strConv(PrepareDataResponse->statusMessage); pFdExport->closeSession(md5session); //qDebug() << "session closed"; if(PrepareDataResponse->statusCode==StatusCodes_OK) { MainWindow::app()->infoscreen()->appendInfo(tr("FDISK-Verbindung erfolgreich getestet")); } else { MainWindow::app()->infoscreen()->appendError(tr("FDISK-Verbindung konnte nicht hergestellt werden")); } } catch(...) { MainWindow::app()->infoscreen()->appendError(tr("FDISK-Verbindung konnte nicht hergestellt werden")); } }
int main(int /*nArgs*/, const char* /*paszArgs*/[]) { try { std::auto_ptr< ::samples::simple::Echo > pEcho(::staff::ServiceFactory::Inst().GetService< ::samples::simple::Echo >()); STAFF_ASSERT(pEcho.get(), "Cannot get client for service samples.simple.Echo!"); // Invoke Your service here: std::string tEchoStringResult = pEcho->EchoString("Hello world!"); staff::LogInfo() << "EchoString result: " << tEchoStringResult; } STAFF_CATCH_ALL return 0; }
int main(int /*nArgs*/, const char* /*paszArgs*/[]) { try { std::auto_ptr< ::Test171 > pTest171(::staff::ServiceFactory::Inst().GetService< ::Test171 >()); STAFF_ASSERT(pTest171.get(), "Cannot get client for service Test171!"); // Invoke Your service here: // staff::Optional< ::testEnum > testEnum; // pTest171->test(testEnum); // staff::LogInfo() << "test called"; } STAFF_CATCH_ALL return 0; }