VError VJSONObject::CloneProperties( VJSONCloner& inCloner, VJSONObject *inDestination) const { VError err = VE_OK; if (inDestination != NULL) { MapType clonedMap( fMap); for( MapType::iterator i = clonedMap.begin() ; (i != clonedMap.end()) && (err == VE_OK) ; ++i) { if (i->second.first.IsObject()) { VJSONObject *theOriginalObject = RetainRefCountable( i->second.first.GetObject()); err = inCloner.CloneObject( theOriginalObject, i->second.first); VJSONGraph::Connect( &inDestination->fGraph, i->second.first); ReleaseRefCountable( &theOriginalObject); } else if (i->second.first.IsArray()) { VJSONArray *theOriginalArray = RetainRefCountable( i->second.first.GetArray()); err = theOriginalArray->Clone( i->second.first, inCloner); VJSONGraph::Connect( &inDestination->fGraph, i->second.first); ReleaseRefCountable( &theOriginalArray); } } if (err == VE_OK) inDestination->fMap.swap( clonedMap); } return err; }
void testMySQLConnectorCreateSessionWithInCorrectPassword() { CSQLConnector* connector = (CSQLConnector*) ( VComponentManager::RetainComponent ( 'MYSQ', 'SQL ' ) ); VJSONObject* params = new VJSONObject(); params->SetProperty ( "hostname", MYSQL_HOST ); params->SetProperty ( "user", MYSQL_USER ); params->SetProperty ( "password", MYSQL_CORRECT_PASSWORD ); params->SetProperty ( "database", MYSQL_DATABASE ); params->SetProperty ( "port", MYSQL_PORT ); params->SetProperty ( "ssl", MYSQL_SSL_FALSE ); ISQLSession* session = connector->CreateSession ( params ); if ( session != NULL ) { printf ( "connection to mysql server was successful ..\n" ); ReleaseRefCountable ( &session ); } else { printf ( "connection to mysql server failed ..\n" ); } ReleaseRefCountable ( ¶ms ); ReleaseRefCountable ( &connector ); }
VFile *VProcess::RetainFile( EFolderKind inPrimarySelector, const VString& inFileName, EFolderKind inSecondarySelector) const { VFile *file = NULL; VFolder *parent = RetainFolder( inPrimarySelector); if (testAssert( parent != NULL)) { file = new VFile( *parent, inFileName); if ( (file != NULL) && !file->Exists()) ReleaseRefCountable( &file); } ReleaseRefCountable( &parent); if ( (file == NULL) && (inSecondarySelector != 0) ) { parent = RetainFolder( inSecondarySelector); if ( (parent != NULL) && parent->Exists()) { file = new VFile( *parent, inFileName); if ( (file != NULL) && !file->Exists()) ReleaseRefCountable( &file); } ReleaseRefCountable( &parent); } return file; }
WAKDebuggerServerMessage* VRemoteDebugPilot::WaitFrom(OpaqueDebuggerContext inContext) { WAKDebuggerServerMessage* res = NULL; RemoteDebugPilotMsg_t msg; VChromeDbgHdlPage* page = NULL; msg.type = WAIT_FROM_MSG; msg.ctx = inContext; msg.outpage = &page; VError err = Send(msg); if (!err && page) { fPendingContextsNumberSem.Unlock(); res = page->WaitFrom(); fLock.Lock(); if (res->fType == WAKDebuggerServerMessage::SRV_CONNEXION_INTERRUPTED) { std::map< OpaqueDebuggerContext, VContextDescriptor* >::iterator ctxIt = fContextArray.find(inContext); if (ctxIt != fContextArray.end()) { ReleaseRefCountable(&(*ctxIt).second->fPage); } } ReleaseRefCountable(&page); fLock.Unlock(); fPendingContextsNumberSem.Lock(); } else { //int a=1; } return res; }
XBOX::VError VRemoteDebugPilot::TreatWS(IHTTPResponse* ioResponse, uLONG inPageNb ) { VError err; RemoteDebugPilotMsg_t msg; VChromeDbgHdlPage* page = NULL; XBOX::VSemaphore* sem = NULL; msg.type = TREAT_WS_MSG; msg.pagenb = inPageNb; msg.outpage = &page; msg.outsem = &sem; err = Send( msg ); if (testAssert(err == VE_OK)) { if (testAssert(sem && page)) { // page and sem are already retained // the debugging page WebSocket is handled thanks to the (HTTP server) calling thread if (page->TreatWS(ioResponse,sem)) { } //fLock.Lock(); ReleaseRefCountable(&sem); ReleaseRefCountable(&page); //fLock.Unlock(); } } return VE_OK; }
bool VProjectItemFolder::ConformsTo( const XBOX::VString& inFileKindID) const { bool result = false; if (fOwner != NULL) { VString extension; fOwner->GetExtension( extension); VFileKind *itemKind = VFileKindManager::Get()->RetainFirstFileKindMatchingWithExtension( extension); if (itemKind == NULL) itemKind = VFileKindManager::Get()->RetainFileKind( L"public.folder"); if (itemKind != NULL) { VFileKind *refKind = VFileKindManager::Get()->RetainFileKind( inFileKindID); if (refKind != NULL) { result = itemKind->ConformsTo( *refKind); ReleaseRefCountable( &refKind); } ReleaseRefCountable( &itemKind); } } return result; }
VRPCService::~VRPCService() { xbox_assert(fMethodsRequestHandler == NULL); xbox_assert(fProxyRequestHandler == NULL); ReleaseRefCountable( &fMethodsRequestHandler); ReleaseRefCountable( &fProxyRequestHandler); }
VError XMacFileSystemNotification::StartWatchingForChanges( const VFolder &inFolder, VFileSystemNotifier::EventKind inKindFilter, VFileSystemNotifier::IEventHandler *inHandler, sLONG inLatency ) { // We need to get the folder's path into an array for us to pass along to the OS call. VString posixPathString; inFolder.GetPath( posixPathString, FPS_POSIX); VStringConvertBuffer buffer( posixPathString, VTC_UTF_8); std::string posixPath( buffer.GetCPointer()); CFStringRef pathRef = posixPathString.MAC_RetainCFStringCopy(); CFArrayRef pathArray = CFArrayCreate( NULL, (const void **)&pathRef, 1, NULL ); FSEventStreamContext context = { 0 }; // The latency the user passed us is expressed in milliseconds, but the OS call requires the latency to be // expressed in seconds. CFTimeInterval latency = (inLatency / 1000.0); // Now we can make our change data object XMacChangeData *data = new XMacChangeData( inFolder.GetPath(), posixPath, inKindFilter, VTask::GetCurrent(), inHandler, this); context.info = data; data->fStreamRef = FSEventStreamCreate( NULL, &FSEventCallback, &context, pathArray, kFSEventStreamEventIdSinceNow, latency, kFSEventStreamCreateFlagNone ); if (data->fStreamRef == NULL) { CFRelease( pathArray ); CFRelease( pathRef ); ReleaseRefCountable( &data); return MAKE_NATIVE_VERROR( errno ); } // We also need to take an initial snapshot of the directory for us to compare again CreateDirectorySnapshot( posixPath, data->fSnapshot, true ); // Now we can add the data object we just made to our list fOwner->PushChangeData( data); // Next, we can schedule this to run on the main event loop FSEventStreamScheduleWithRunLoop( data->fStreamRef, CFRunLoopGetMain(), kCFRunLoopDefaultMode ); CFRelease( pathArray ); CFRelease( pathRef ); // Now that we've scheduled the stream to run on a helper thread, all that is left is to // start executing the stream VError err; if (FSEventStreamStart( data->fStreamRef )) { err = VE_OK; } else { err = MAKE_NATIVE_VERROR( errno ); } ReleaseRefCountable( &data); return err; }
void testMySQLConnectorBench() { CSQLConnector* connector = (CSQLConnector*) ( VComponentManager::RetainComponent ( 'MYSQ', 'SQL ' ) ); VJSONObject* params = new VJSONObject(); params->SetProperty ( "hostname", MYSQL_HOST ); params->SetProperty ( "user", MYSQL_USER ); params->SetProperty ( "password", MYSQL_CORRECT_PASSWORD ); params->SetProperty ( "database", MYSQL_DATABASE ); params->SetProperty ( "port", MYSQL_PORT ); params->SetProperty ( "ssl", MYSQL_SSL_FALSE ); ISQLSession* session = connector->CreateSession ( params ); if ( session != NULL ) { VString query ( "SELECT * FROM people" ); clock_t startClock = clock(); VError error = session->ExecuteQuery ( query ); clock_t endClock = clock(); sLONG Dt = 1000 * ( endClock - startClock ) / CLOCKS_PER_SEC; printf ( "fetching all rows takes %d milliseconds\n", Dt ); fflush ( stderr ); startClock = clock(); ReleaseRefCountable ( &session ); endClock = clock(); Dt = 1000 * ( endClock - startClock ) / CLOCKS_PER_SEC; printf ( "releasing all rows takes %d milliseconds\n", Dt ); fflush ( stderr ); } ReleaseRefCountable ( ¶ms ); ReleaseRefCountable ( &connector ); }
/* static */ void VJSONGraph::ReleaseDependenciesIfNecessary( IRefCountable *inTarget, const std::vector<VJSONObject*>& inObjects, const std::vector<VJSONArray*>& inArrays, sLONG inReferencesTotal) { sLONG refCountObjectTotal = 0; for( std::vector<VJSONObject*>::const_iterator i = inObjects.begin() ; i != inObjects.end() ; ++i) refCountObjectTotal += (*i)->GetRefCount(); sLONG refCountArrayTotal = 0; for( std::vector<VJSONArray*>::const_iterator i = inArrays.begin() ; i != inArrays.end() ; ++i) refCountArrayTotal += (*i)->GetRefCount(); xbox_assert( inReferencesTotal <= refCountObjectTotal + refCountArrayTotal); // if number of references is equal after release of this inObject // that means some inObject children would leak. if (inReferencesTotal == refCountObjectTotal + refCountArrayTotal) { // leak caused by cyclic structure detected // need to cut all references for( std::vector<VJSONObject*>::const_iterator i = inObjects.begin() ; i != inObjects.end() ; ++i) { (*i)->Retain(); ReleaseRefCountable( (*i)->GetGraph()); } for( std::vector<VJSONArray*>::const_iterator i = inArrays.begin() ; i != inArrays.end() ; ++i) { (*i)->Retain(); ReleaseRefCountable( (*i)->GetGraph()); } for( std::vector<VJSONObject*>::const_iterator i = inObjects.begin() ; i != inObjects.end() ; ++i) (*i)->Clear(); for( std::vector<VJSONArray*>::const_iterator i = inArrays.begin() ; i != inArrays.end() ; ++i) (*i)->Clear(); #if VERSIONDEBUG for( std::vector<VJSONObject*>::const_iterator i = inObjects.begin() ; i != inObjects.end() ; ++i) xbox_assert( ((*i == inTarget) && (*i)->GetRefCount() == 2) || ((*i != inTarget) && (*i)->GetRefCount() == 1) ); for( std::vector<VJSONArray*>::const_iterator i = inArrays.begin() ; i != inArrays.end() ; ++i) xbox_assert( ((*i == inTarget) && (*i)->GetRefCount() == 2) || ((*i != inTarget) && (*i)->GetRefCount() == 1) ); #endif for( std::vector<VJSONObject*>::const_iterator i = inObjects.begin() ; i != inObjects.end() ; ++i) (*i)->Release(); for( std::vector<VJSONArray*>::const_iterator i = inArrays.begin() ; i != inArrays.end() ; ++i) (*i)->Release(); } }
void VJSONValue::_Dispose() { switch( fType) { case JSON_string: fString.Dispose(); break; case JSON_array: ReleaseRefCountable( &fArray); break; case JSON_object: ReleaseRefCountable( &fObject); break; } }
void VRemoteDebugPilot::RemoveContext(std::map< OpaqueDebuggerContext, VContextDescriptor* >::iterator& inCtxIt) { XBOX::VError err; XBOX::VString resp; if (fState != STOPPED_STATE) { // ctx could already have been removed by ABORT if (inCtxIt != fContextArray.end()) { if ((*inCtxIt).second->fPage) { ReleaseRefCountable(&(*inCtxIt).second->fPage); } if (fState == CONNECTED_STATE) { resp = CVSTR("{\"method\":\"removeContext\",\"contextId\":\""); resp.AppendLong8((sLONG8)((*inCtxIt).first)); resp += CVSTR("\",\"id\":\""); resp += fClientId; resp += CVSTR("\"}"); err = SendToBrowser( resp ); if (err) { fWS->Close(); fState = DISCONNECTING_STATE; } } inCtxIt->second->Release(); fContextArray.erase(inCtxIt); } } }
XBOX::VError VRemoteDebugPilot::BreakpointReached( OpaqueDebuggerContext inContext, int inLineNumber, RemoteDebuggerPauseReason inDebugReason, XBOX::VString& inException, XBOX::VString& inSourceUrl, XBOX::VectorOfVString& inSourceData) { VError err = VE_INVALID_PARAMETER; XBOX::VSemaphore* sem = NULL; VContextDebugInfos debugInfos; debugInfos.fFileName = inSourceUrl; VURL::Decode( debugInfos.fFileName ); VIndex idx = debugInfos.fFileName.FindUniChar( L'/', debugInfos.fFileName.GetLength(), true ); if (idx > 1) { VString tmpStr; debugInfos.fFileName.GetSubString(idx+1,debugInfos.fFileName.GetLength()-idx,tmpStr); debugInfos.fFileName = tmpStr; } debugInfos.fLineNb = inLineNumber+1; debugInfos.fReason = ( inDebugReason == EXCEPTION_RSN ? "exception" : (inDebugReason == BREAKPOINT_RSN ? "breakpoint" : "dbg statement" ) ); debugInfos.fComment = "To Be Completed"; debugInfos.fSourceLine = ( inLineNumber < inSourceData.size() ? inSourceData[inLineNumber] : " NO SOURCE AVAILABLE " ); err = ContextUpdated(inContext,debugInfos,&sem); if (err == VE_OK) { fPendingContextsNumberSem.Unlock(); // if sem not NULL then wait for a browser page granted for debug if (sem) { sem->Lock(); ReleaseRefCountable(&sem); } RemoteDebugPilotMsg_t msg; msg.type = BREAKPOINT_REACHED_MSG; msg.ctx = inContext; msg.linenb = inLineNumber; msg.datavectstr = inSourceData; msg.datastr = inException; msg.urlstr = inSourceUrl; err = Send( msg ); //testAssert(err == VE_OK); fPendingContextsNumberSem.Lock(); } VString trace = VString("VRemoteDebugPilot::BreakpointReached ctx activation pb for ctxid="); trace.AppendLong8((unsigned long long)inContext); trace += " ,ok="; trace += (!err ? "1" : "0" ); sPrivateLogHandler->Put( (err ? WAKDBG_ERROR_LEVEL : WAKDBG_INFO_LEVEL),trace); return err; }
void VJSONValue::_Dispose() { switch( fType) { case JSON_string: fString.Dispose(); break; case JSON_array: ReleaseRefCountable( &fArray); break; case JSON_object: ReleaseRefCountable( &fObject); break; case JSON_number: case JSON_null: case JSON_true: case JSON_false: case JSON_undefined: case JSON_date: break; } }
VRIAServerSolution* VRIAServerSolution::OpenSolution( VError& outError, VSolutionStartupParameters *inStartupParameters) { outError = VE_OK; VRIAServerSolution *solution = NULL; VSolution *designSolution = VSolutionManager::Get()->OpenSolution( inStartupParameters); if (designSolution != NULL) { solution = new VRIAServerSolution(); if (solution != NULL) { VRIAServerSolutionOpeningParameters *openingParams = new VRIAServerSolutionOpeningParameters( inStartupParameters); outError = solution->_Open( designSolution, openingParams); ReleaseRefCountable( &openingParams); } else { VSolutionManager::Get()->CloseSolution( designSolution); delete designSolution; designSolution = NULL; outError = ThrowError( VE_MEMORY_FULL); } } else { outError = VE_UNKNOWN_ERROR; } return solution; }
void VJSGlobalClass::do_ProgressIndicator(VJSParms_callStaticFunction& ioParms, VJSGlobalObject *inContext) { VString sessiontile; VString windowtile, userinfo; bool caninterrupt = false; Real maxvalue = -1; VError err = VE_OK; if (ioParms.IsNumberParam(1)) ioParms.GetRealParam(1, &maxvalue); else err = vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1"); if (err == VE_OK ) { if (ioParms.IsStringParam(2)) ioParms.GetStringParam(2, sessiontile); else err = vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "2"); } caninterrupt = ioParms.GetBoolParam( 3, L"Can Interrupt", "Cannot Interrupt"); //VProgressIndicator* progress = inContext->GetRuntimeDelegate()->CreateProgressIndicator( windowtile); if (err == VE_OK) { VProgressIndicator* progress = new VProgressIndicator(); if (progress != NULL) { if (ioParms.CountParams() >= 4) { if (ioParms.IsStringParam(4)) { ioParms.GetStringParam(4, windowtile); progress->SetTitle(windowtile); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "4"); } if (ioParms.CountParams() >= 5) { if (ioParms.IsStringParam(5)) { ioParms.GetStringParam(5, userinfo); progress->SetUserInfo(userinfo); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "5"); } progress->BeginSession((sLONG8)maxvalue, sessiontile, caninterrupt); } ioParms.ReturnValue(VJSProgressIndicator::CreateInstance(ioParms.GetContextRef(), progress)); ReleaseRefCountable( &progress); } else ioParms.ReturnNullValue(); }
VProcess::~VProcess() { #if WITH_RESOURCE_FILE ReleaseRefCountable( &fProcessResFile); #endif sLONG val = 0; GetCommandLineArgumentAsLong( "-memDebugLeaks", &val); if (val != 0) { VObject::GetAllocator()->DumpLeaks(); #if WITH_VMemoryMgr VMemory::GetManager()->DumpLeaks(); #endif } else { #if VERSIONDEBUG #if DUMP_LEAKS VObject::GetAllocator()->DumpLeaks(); VMemory::DumpLeaks(); #endif #endif } if (fInitCalled) _DeInit(); }
void VJSStream::do_BinaryStream(VJSParms_callStaticFunction& ioParms) { VFile* file = ioParms.RetainFileParam( 1); bool forwrite = ioParms.GetBoolParam( 2, L"Write", L"Read"); if (file != NULL) { VError err = VE_OK; if (forwrite) { if (!file->Exists()) err = file->Create(); } VFileStream* stream = new VFileStream(file); if (err == VE_OK) { if (forwrite) err = stream->OpenWriting(); else err = stream->OpenReading(); } if (err == VE_OK) { ioParms.ReturnValue(VJSStream::CreateInstance(ioParms.GetContextRef(), stream)); } else { delete stream; } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); ReleaseRefCountable( &file); }
bool VUTI::ConformsToExtension(const VString& inExtension) { bool conformsToExtension = false; VUTI * highestParentThatConformsToExtension = GetHighestParentThatConformsToExtension(inExtension); if(highestParentThatConformsToExtension != NULL) conformsToExtension = true; ReleaseRefCountable(&highestParentThatConformsToExtension); return conformsToExtension; }
bool VUTI::ConformsToMIMEType(const VString& inMIMEType) { bool conformsToMIMEType = false; VUTI * highestParentThatConformsToMIMEType = GetHighestParentThatConformsToMIMEType(inMIMEType); if(highestParentThatConformsToMIMEType != NULL) conformsToMIMEType = true; ReleaseRefCountable(&highestParentThatConformsToMIMEType); return conformsToMIMEType; }
/* static */ VFolder *VFolder::CreateAndResolveAlias( const VFolder& inParentFolder, const VString& inFolderName) { VFolder *folder = new VFolder( inParentFolder, inFolderName); VError error = ResolveAliasFolder( &folder, true); if (error != VE_OK) ReleaseRefCountable( &folder); return folder; }
void XWinFileSystemNotification::LaunchTaskIfNecessary() { if ( (fTask == NULL) || fTask->IsDying() ) { ReleaseRefCountable( &fTask); fTask = new VTask( this, 0, eTaskStylePreemptive, TaskRunner ); fTask->SetKindData( (sLONG_PTR)this ); fTask->Run(); } }
XWinFileSystemNotification::~XWinFileSystemNotification() { if (fTask != NULL) { fTask->Kill(); ::PostThreadMessage( fTask->GetSystemID(), WM_QUIT, 0, 0 ); fTask->WaitForDeath( 3000); } ReleaseRefCountable( &fTask); }
JS4D::ObjectRef JS4D::VFileToObject( ContextRef inContext, XBOX::VFile *inFile, ValueRef *outException) { JS4DFileIterator* file = (inFile == NULL) ? NULL : new JS4DFileIterator( inFile); ObjectRef value; if (file != NULL) value = JSObjectMake( inContext, VJSFileIterator::Class(), file); else value = JSValueToObject( inContext, JSValueMakeNull( inContext), outException); ReleaseRefCountable( &file); return value; }
JS4D::ObjectRef JS4D::VFolderToObject( ContextRef inContext, XBOX::VFolder *inFolder, ValueRef *outException) { JS4DFolderIterator* folder = (inFolder == NULL) ? NULL : new JS4DFolderIterator( inFolder); ObjectRef value; if (folder != NULL) value = JSObjectMake( inContext, VJSFolderIterator::Class(), folder); else value = JSValueToObject( inContext, JSValueMakeNull( inContext), outException); ReleaseRefCountable( &folder); return value; }
void VJSSessionStorageObject::SetKeyVValueSingle( const XBOX::VString &inKey, const XBOX::VValueSingle& inValue) { XBOX::StLocker<XBOX::VCriticalSection> lock(&fMutex); VJSStructuredClone *clone = VJSStructuredClone::RetainCloneForVValueSingle( inValue); if (clone != NULL) { fKeysValues[inKey] = VRefPtr<VJSStructuredClone>(clone); ReleaseRefCountable( &clone); } }
void VJSSessionStorageObject::SetKeyVValueBag( const XBOX::VString &inKey, const XBOX::VValueBag& inBag, bool inUniqueElementsAreNotArrays) { XBOX::StLocker<XBOX::VCriticalSection> lock(&fMutex); VJSStructuredClone *clone = VJSStructuredClone::RetainCloneForVValueBag( inBag, inUniqueElementsAreNotArrays); if (clone != NULL) { fKeysValues[inKey] = VRefPtr<VJSStructuredClone>(clone); ReleaseRefCountable( &clone); } }
void VJSDirectory::_getInternalStore( XBOX::VJSParms_getProperty& ioParms, CUAGDirectory* inDirectory) { CDB4DBase* base = inDirectory->RetainAndExposeDB(); if (base != NULL) { ioParms.ReturnValue(base->CreateJSDatabaseObject(ioParms.GetContext())); ReleaseRefCountable( &base); // sc 20/06/2012 } else ioParms.ReturnNullValue(); }
void VUTI::_Detach() { //Release all the parent UTIs std::map< VString, VUTI * >::iterator parentUTIsIterator = fParentUTIsMap.begin(); while(parentUTIsIterator != fParentUTIsMap.end()) { VUTI * parentUTI = parentUTIsIterator->second; fParentUTIsMap.erase(parentUTIsIterator); parentUTIsIterator = fParentUTIsMap.begin(); ReleaseRefCountable(&parentUTI); } //Release all the children std::map< VString, VUTI * >::iterator childUTIsIterator = fChildrenUTIsMap.begin(); while(childUTIsIterator != fChildrenUTIsMap.end()){ VUTI * childUTI = childUTIsIterator->second; fChildrenUTIsMap.erase(childUTIsIterator); childUTIsIterator = fChildrenUTIsMap.begin(); ReleaseRefCountable(&childUTI); } }
JS4D::ObjectRef JS4D::VFilePathToObjectAsFileOrFolder( ContextRef inContext, const XBOX::VFilePath& inPath, ValueRef *outException) { ObjectRef value; if (inPath.IsFolder()) { VFolder *folder = new VFolder( inPath); value = VFolderToObject( inContext, folder, outException); ReleaseRefCountable( &folder); } else if (inPath.IsFile()) { VFile *file = new VFile( inPath); value = VFileToObject( inContext, file, outException); ReleaseRefCountable( &file); } else { value = JSValueToObject( inContext, JSValueMakeNull( inContext), outException); // exception instead ? } return value; }