bool SybCTnewDAImpl::IntDoGetConnection(SybCTnewDA *&pSyb, bool &bIsOpen, const String &server, const String &user) { StartTrace(SybCTnewDAImpl.IntDoGetConnection); pSyb = NULL; bIsOpen = false; if ( !server.Length() || !user.Length() || !IntGetOpen(pSyb, bIsOpen, server, user) ) { // favour unused connection against open connection of different server/user if ( fgListOfSybCT["Unused"].GetSize() ) { Trace("removing first unused element"); pSyb = SafeCast(fgListOfSybCT["Unused"][0L].AsIFAObject(), SybCTnewDA); fgListOfSybCT["Unused"].Remove(0L); } else { String strEmpty; if ( IntGetOpen(pSyb, bIsOpen, strEmpty, strEmpty) ) { Trace("connection of different server or user"); // if this call would return false we could possibly delete and recreate an object pSyb->Close(); } } } Trace("returning &" << (long)(IFAObject *)pSyb); if ( pSyb == NULL ) { SYSERROR("could not get a valid SybCTnewDA"); } return (pSyb != NULL); }
Application *Application::GetGlobalApplication(String &applicationName) { StartTrace(Application.GetGlobalApplication); Application *application = 0; if (!fgConfig.IsNull()) { Anything applicationConf; if (fgConfig.LookupPath(applicationConf, "Application") ) { for (long i = 0, sz = applicationConf.GetSize() && !application; i < sz; ++i) { // iterate over the applicationname list applicationName = applicationConf[i].AsCharPtr(0); if ( applicationName.Length() > 0 ) { // return the first application object found by name application = Application::FindApplication(applicationName); break; } } } else { // if no application object is configured in the config any // return the first in the list RegistryIterator ri(MetaRegistry::instance().GetRegistry("Application"), false); for ( ; ri.HasMore() && !application ; application = SafeCast(ri.Next(applicationName), Application)); } } return application; }
typename std::enable_if< std::is_floating_point<T>::value, void>::type round_to(const std::array<T, N> &src, std::array<U, N> &dst) { auto it_src = src.cbegin(); auto it_dst_end = dst.end(); for (auto it_dst = dst.begin(); it_dst != it_dst_end; ++it_src, ++it_dst) #if _MSC_VER > 1700 // from VS2013 *it_dst = static_cast<U>(std::round(*it_src)); #else // up to VS2013 if (*it_src >= 0) SafeCast(std::floor(*it_src + 0.5), *it_dst); else SafeCast(std::ceil(*it_src - 0.5), *it_dst); #endif }
void HandleRequest::DoInit(ROAnything workerInit) { StartTrace(HandleRequest.DoInit); // request independant setup fProcessor = SafeCast(workerInit["processor"].AsIFAObject(0), RequestProcessor); fClientSocket = 0; fRequestNumber = 0; }
void Casting() { Console::WriteLine("=== Beginning of Casting Sample ===\n"); DynamicCast(); SafeCast(); ExplicitTypeConversion(); Console::WriteLine("\n=== End of Casting Sample ==="); }
void RequestThreadsManager::DoAllocPool(ROAnything args) { StartTrace(RequestThreadsManager.DoAllocPool); TraceAny(args, "args"); RequestProcessor *processor = SafeCast(args["processor"].AsIFAObject(0), RequestProcessor); if (processor) { fProcessor = processor; } else { const char *msg = "OOPS, couldn't find a RequestProcessor in args"; Trace(msg); SYSERROR(msg); } fRequests = new HandleRequest[GetPoolSize()]; }
bool SybCTnewDAImpl::CheckCloseOpenedConnections(long lTimeout) { StartTrace(SybCTnewDAImpl.CheckCloseOpenedConnections); bool bRet = false; Anything anyTimeStamp(coast::storage::Global()); TimeStamp aStamp; aStamp -= lTimeout; Trace("current timeout " << lTimeout << "s, resulting time [" << aStamp.AsString() << "]"); LockUnlockEntry me(fgStructureMutex); if ( fgInitialized ) { TraceAny(fgListOfSybCT, "current list of connections"); if ( fgListOfSybCT.LookupPath(anyTimeStamp, "Open") && anyTimeStamp.GetSize() ) { SybCTnewDA *pSyb = NULL; long lTS = 0L; // if we still have open connections and the last access is older than lTimeout seconds while ( anyTimeStamp.GetSize() && ( aStamp > TimeStamp(anyTimeStamp.SlotName(lTS)) ) ) { Anything anyTS(coast::storage::Global()); anyTS = anyTimeStamp[lTS]; TraceAny(anyTS, "stamp of connections to close [" << anyTimeStamp.SlotName(0L) << "]"); while ( anyTS.GetSize() ) { pSyb = SafeCast(anyTS[0L][0L].AsIFAObject(), SybCTnewDA); anyTS.Remove(0L); if ( pSyb != NULL ) { Trace("closing timeouted connection"); if ( pSyb->Close() ) { bRet = true; } } else { SYSWARNING("Sybase connection with address " << (long)pSyb << " not valid anymore!"); } fgListOfSybCT["Unused"].Append((IFAObject *)pSyb); } anyTimeStamp.Remove(lTS); } } } else { SYSERROR("SybCTnewDAImpl not initialized!"); } return bRet; }
bool SybCTnewDAImpl::IntGetOpen(SybCTnewDA *&pSyb, bool &bIsOpen, const String &server, const String &user) { StartTrace1(SybCTnewDAImpl.IntGetOpen, "server [" << server << "] user [" << user << "]"); pSyb = NULL; bIsOpen = false; Anything anyTimeStamp(coast::storage::Global()), anyEntry(coast::storage::Global()); TraceAny(fgListOfSybCT, "current list of connections"); if ( fgListOfSybCT.LookupPath(anyTimeStamp, "Open") && anyTimeStamp.GetSize() ) { String strToLookup(server); if ( strToLookup.Length() && user.Length() ) { strToLookup << '.' << user; } Trace("Lookup name [" << strToLookup << "]"); for (long lIdx = 0; lIdx < anyTimeStamp.GetSize(); ++lIdx) { Anything anyTS(coast::storage::Global()); anyTS = anyTimeStamp[lIdx]; for (long lTimeSub = 0L; lTimeSub < anyTS.GetSize(); ++lTimeSub) { if ( ( strToLookup.Length() <= 0 ) || strToLookup == anyTS[lTimeSub][1L].AsString() ) { Trace("removing subentry :" << lIdx << ":" << lTimeSub); anyEntry = anyTS[lTimeSub]; anyTS.Remove(lTimeSub); // we do not have to close the connection before using because the SybCTnewDA is for the same server and user bIsOpen = ( strToLookup.Length() > 0 ); break; } } if ( !anyEntry.IsNull() ) { pSyb = SafeCast(anyEntry[0L].AsIFAObject(), SybCTnewDA); if ( anyTS.GetSize() == 0L ) { anyTimeStamp.Remove(lIdx); } break; } } } return !anyEntry.IsNull(); }
int RegistrationHandler::onRequestRetry(resip::ClientRegistrationHandle h, int retryMinimum, const resip::SipMessage& msg) { return SafeCast(h).onRequestRetry(h, retryMinimum, msg); }
void RegistrationHandler::onRemoved(resip::ClientRegistrationHandle h, const resip::SipMessage& response) { SafeCast(h).onRemoved(h, response); }
//------------------------------------------------------------------------- // 解析一个json格式的文件 FKCW_Json_Object* FKCW_Json_Object::Create( const string& p_strPath ) { CCObject* obj = FKCW_Json_Parser::Load(p_strPath); return SafeCast(obj); }
//------------------------------------------------------------------------- // 解析一个json格式的内存字符串 // 若这个json内存是一个数组,则这个数组将会作为一个键为"array"的数组填充 FKCW_Json_Object* FKCW_Json_Object::Create( const char* p_szJson, size_t p_unLength ) { CCObject* obj = FKCW_Json_Parser::Load(p_szJson, p_unLength); return SafeCast(obj); }
static TObjectType* SafeCast2(const CObject* /*selector*/, void* ptr) { return SafeCast(static_cast<CObject*>(ptr)); }
static const TObjectType* SafeCast2(TTypeInfo /*selector*/, const void* ptr) { return SafeCast(static_cast<TTypeInfo>(ptr)); }