/** * Initializes this as a dynamic client */ bool DynamicClientInitializer::initializeClient() { if ( !basicInit() ) { LOG_ERR ( "Basic initialization failed" ); return false; } LOG ( "Basic initialization done" ); // Second: Creating an UDP socket, to send the NMS_INIT broadcast if ( !setupUdpSocket() ) { return false; } // Send the NMS_INIT message, and wait for an acceptable response, or the occurrence of a timeout LOG ( "Sending UDP" ); if ( !sendUdpMessage() ) { if ( getLastErrorCode() != ErrorCodes::TIMEOUT ) { LOG ( "Cannot send UDP message" ); setLastErrorCode ( 888 ); } else if ( getLastErrorCode() == ErrorCodes::TIMEOUT ) { LOG ( "Timeout ..." ); } return false; } if ( daemonFirstResponse == COMMAND_NOINIT ) // NOINIT ... unknown reasons { LOG ( "Not a valid response from daemon" ); return false; } if ( !analyzeResponse ( daemonFirstResponse.c_str() ) ) { LOG ( "Could not analyze the daemons response" ); return false; } return true; }
PRL_RESULT Task_EventLoopBase::run_body() { bool invoked = true; invoked &= QMetaObject::invokeMethod(this, "onFirstEvent", Qt::QueuedConnection); PRL_ASSERT(invoked); QThread::exec(); return getLastErrorCode(); }
/* Finalize task */ void Task_GetBackupTreeSource::finalizeTask() { Disconnect(); if (PRL_SUCCEEDED(getLastErrorCode())) { CProtoCommandPtr pResponse = CProtoSerializer::CreateDspWsResponseCommand(getRequestPackage(), PRL_ERR_SUCCESS); CProtoCommandDspWsResponse *pDspWsResponseCmd = CProtoSerializer::CastToProtoCommand<CProtoCommandDspWsResponse>(pResponse); pDspWsResponseCmd->SetBackupsTree(m_sBackupTree); getClient()->sendResponse( pResponse, getRequestPackage() ); } else { getClient()->sendResponseError( getLastError(), getRequestPackage() ); } }
/** * CSymbianTransportAgent::sendMessage() */ char* CSymbianTransportAgent::sendMessage(const char* msg) { LOG.debug("entering CSymbianTransportAgent::sendMessage"); // Check if user aborted current sync. if (getLastErrorCode() == KErrCancel) { LOG.debug("Leaving sendMessage - lastErrorCode is %d", getLastErrorCode()); User::Leave(KErrCancel); // leave is trapped at SyncActiveObject::RunL(). } // Just to be sure the response buffer is ok //TO BE VERIFIED!!!! delete iResponseBody; iResponseBody = NULL; // Set the POST body delete iPostBody; iPostBody = NULL; if (url.fullURL == NULL) { setErrorF(ERR_CONNECT, "Empty URL"); LOG.error("Transport Agent: empty URL"); return NULL; } char* response = NULL; RStringF method; RHTTPHeaders hdr; // Parse string to URI (as defined in RFC2396) TUriParser8 uri; HBufC8* fullUrl = charToNewBuf8(url.fullURL); TInt parseErr = uri.Parse(*fullUrl); if (parseErr != KErrNone) { setErrorF(ERR_CONNECT, "Malformed URL"); LOG.error("Transport Agent: malformed url"); goto finally; } { TPtrC8 ptr(reinterpret_cast<const TUint8*>(msg)); iPostBody = HBufC8::NewL(ptr.Length()); iPostBody->Des().Copy(ptr); } FConnection* connection = FConnection::getInstance(); if (connection->isConnected() == false) { int res = connection->startConnection(); if (res) { setErrorF(ERR_CONNECT, "Connection error (%d): please check your internet settings.", res); LOG.error("%s", getLastErrorMsg()); goto finally; } } // Get request method string for HTTP POST method = iHttpSession.StringPool().StringF( HTTP::EPOST, RHTTPSession::GetTable()); // Open transaction with previous method and parsed uri. This class will // receive transaction events in MHFRunL and MHFRunError. iHttpTransaction = iHttpSession.OpenTransactionL( uri, *this, method ); // Set headers for request; user agent, accepted content type and body's // content type. hdr = iHttpTransaction.Request().GetHeaderCollection(); SetHeaderL(hdr, HTTP::EUserAgent, _L8("Funambol Symbian SyncML client")); SetHeaderL(hdr, HTTP::EAccept, _L8("*/*")); SetHeaderL(hdr, HTTP::EContentType, _L8("application/vnd.syncml+xml")); LOG.debug("Sending message:"); LOG.debug("%s", msg); // Set data supplier for POST body // Please see » Symbian OS v9.1 » Symbian OS guide » Using HTTP Client » // Handling request body data for explanation on this part iDataSupplier = this; iHttpTransaction.Request().SetBody(*iDataSupplier); // Submit the transaction. After this the framework will give transaction // events via MHFRunL and MHFRunError. iHttpTransaction.SubmitL(); // Start the scheduler, once the transaction completes or is cancelled on an // error the scheduler will be stopped in the event handler // This is a trick to implement a synchronous method LOG.debug("starting ASync scheduler..."); iASWait->Start(); // TO BE VERIFIED!!!! LOG.debug("ASync scheduler stopped"); // Check if user aborted current sync. if (getLastErrorCode() == KErrCancel) { LOG.debug("Leaving sendMessage - lastErrorCode is %d", getLastErrorCode()); User::Leave(KErrCancel); // leave is trapped at SyncActiveObject::RunL(). } // when all is finished, return char* to be delete [] if(!iTransFailed) { TInt length = iResponseBody->Des().Length(); response = new char[length+1]; Mem::Copy(response, iResponseBody->Ptr(), length); response[length] = '\0'; LOG.debug("Message received:"); LOG.debug("%s", response); } else { LOG.debug("HTTP transaction failed"); setErrorF(ERR_HTTP, "HTTP request error: request timed out waiting for response"); } finally: // Transaction can be closed now. It's not needed anymore. LOG.debug("closing HTTP transaction"); iHttpTransaction.Close(); delete fullUrl; LOG.debug("exiting CSymbianTransportAgent::sendMessage"); return response; }
/* * Used to start the sync process. The argument is an array of SyncSources * that have to be synched with the sync process */ int SyncClient::sync(AbstractSyncConfig& config, SyncSource** sources) { resetError(); int ret = 0; if (!config.getAbstractSyncSourceConfigsCount()) { //sprintf(lastErrorMsg, "Error in sync() - configuration not set correctly."); ret = 1; setError(ret, "Error in sync() - configuration not set correctly."); LOG.error("%s", getLastErrorMsg()); return ret; } // // Synchronization report. // syncReport.setSyncSourceReports(config); // Set source report on each SyncSource (assign pointer) int i=0; while (sources[i]) { char* name = toMultibyte(sources[i]->getName()); SyncSourceReport *ssr = syncReport.getSyncSourceReport(name); ssr->setState(SOURCE_ACTIVE); sources[i]->setReport(ssr); delete[] name; i++; } SyncManager syncManager(config, syncReport); if ((ret = syncManager.prepareSync(sources))) { LOG.error("Error in preparing sync: %s", getLastErrorMsg()); goto finally; } ret = continueAfterPrepareSync(); if (ret) { LOG.error("SyncClient: continueAfterPrepareSync returns error code: %d.", ret); goto finally; } if ((ret = syncManager.sync())) { LOG.error("Error in syncing: %s", getLastErrorMsg()); goto finally; } ret = continueAfterSync(); if (ret) { LOG.error("SyncClient: continueAfterSync returns error code: %d.", ret); goto finally; } if ((ret = syncManager.endSync())) { LOG.error("Error in ending sync: %s", getLastErrorMsg()); goto finally; } finally: // Update SyncReport with last error from sync syncReport.setLastErrorCode(getLastErrorCode()); syncReport.setLastErrorMsg(getLastErrorMsg()); return ret; }
/* * Start the sync process. * SyncSources are managed (created, initialized, deleted) inside * this method. When SyncSource array is ready, the method 'sync(sources**)' * is called to start the sync process. * * @param sourceNames: optional, a NULL terminated array of source names that * we want to sync. If NULL, sources to sync are chosen * from the configuration object (config). * @return: 0 on success, an error otherwise */ int SyncClient::sync(AbstractSyncConfig& config, char** sourceNames) { AbstractSyncSourceConfig* sc = NULL; SyncSource **sources = NULL; const char* currName; int currSource = 0, numActive = 0, numSources = 0; int ret = 0; ret = prepareSync(config); if (ret) { LOG.error("SyncClient: prepareSync returned error code: %d.", ret); goto finally; } // Get number of sources: from passed parameter or (if NULL) from config. numSources = 0; if (sourceNames) { while (sourceNames[numSources]) { numSources ++; } } else { numSources = config.getAbstractSyncSourceConfigsCount(); } // make room for all potential sync sources sources = new SyncSource* [numSources + 1]; // iterate over all configs and add those which the client // wants to have synchronized while (currSource < numSources) { // use only sources indicated in 'sourceNames' param if (sourceNames) { currName = sourceNames[currSource]; if (! (sc = config.getAbstractSyncSourceConfig(currName)) ) { if (sources) delete [] sources; return getLastErrorCode(); } } // use all available sources from config else { if (! (sc = config.getAbstractSyncSourceConfig(currSource)) ) { if (sources) delete [] sources; return getLastErrorCode(); } currName = sc->getName(); } ret = createSyncSource(currName, currSource, sc, sources + numActive); if (ret) { LOG.error("SyncClient: createSyncSource returned error code: %d.", ret); goto finally; } if (sources[numActive]) { numActive++; } currSource++; } sources[numActive] = NULL; ret = beginSync(sources); if (ret) { LOG.error("SyncClient: beginSync returned error code: %d.", ret); goto finally; } // // ready to synchronize // ret = sync(config, sources); if (ret) { goto finally; } ret = endSync(sources); if (ret) { LOG.error("SyncClient: endSync returned error code: %d.", ret); } finally: if (sources) { for (int i=0; sources[i]; i++) { delete sources[i]; } delete [] sources; } return ret; }
void Task_MigrateCtTarget::finalizeTask() { IOSendJob::Handle hJob; SmartPtr<IOPackage> pPackage; // delete temporary registration if (m_nSteps & MIGRATE_VM_EXCL_PARAMS_LOCKED) CDspService::instance()->getVmDirManager().unlockExclusiveVmParameters(m_pVmInfo.getImpl()); int nRetCode = getLastErrorCode(); if (PRL_SUCCEEDED(nRetCode)) { if (m_pVm.getImpl()) { PRL_EVENT_TYPE evtType; /* restore Vm previous state */ switch (m_nPrevVmState) { case VMS_RUNNING: evtType = PET_DSP_EVT_VM_STARTED; break; case VMS_STOPPED: default: evtType = PET_DSP_EVT_VM_STOPPED; break; } CVmEvent cStateEvent(evtType, m_sVmUuid, PIE_DISPATCHER); SmartPtr<IOPackage> pUpdateVmStatePkg = DispatcherPackage::createInstance( PVE::DspVmEvent, cStateEvent.toString()); m_pVm->changeVmState(pUpdateVmStatePkg); CDspService::instance()->getClientManager(). sendPackageToVmClients(pUpdateVmStatePkg, m_sVzDirUuid, m_sVmUuid); if (m_nPrevVmState == VMS_STOPPED) { CDspService::instance()->getVmDirHelper().unregisterExclusiveVmOperation( m_sVmUuid, m_sVzDirUuid, PVE::DspCmdDirVmMigrate, getClient()); CDspVm::UnregisterVmObject(m_pVm); } else { /* lock running Vm (https://jira.sw.ru/browse/PSBM-7682) */ /* will do it via initial Vm creation command (https://jira.sw.ru/browse/PSBM-8222) */ m_pVm->replaceInitDspCmd(PVE::DspCmdVmStart, getClient()); } } /* notify source task about target task finish, will send reply to check precondition request. https://jira.sw.ru/browse/PSBM-9596 */ m_pCheckDispConnection->sendSimpleResponse(m_pCheckPackage, PRL_ERR_SUCCESS); /* migration initiator wait event from original Vm uuid */ CVmEvent cEvent(PET_DSP_EVT_VM_MIGRATE_FINISHED, m_sOriginVmUuid, PIE_DISPATCHER); pPackage = DispatcherPackage::createInstance(PVE::DspVmEvent, cEvent.toString()); CDspService::instance()->getClientManager().sendPackageToVmClients(pPackage, m_sVzDirUuid, m_sOriginVmUuid); } else { /* It is not possible to get Vm client list after deleteVmDirectoryItem(), and sendPackageToVmClients() does not work. Get list right now and will use sendPackageToClientList() call (https://jira.sw.ru/browse/PSBM-9159) */ QList< SmartPtr<CDspClient> > clientList = CDspService::instance()->getClientManager(). getSessionListByVm(m_sVzDirUuid, m_sVmUuid).values(); if (operationIsCancelled()) setLastErrorCode(PRL_ERR_OPERATION_WAS_CANCELED); /* if migration was not started, do not cleanup anything - we can remove 'already existed Vm' */ if (m_nSteps & MIGRATE_STARTED) { if (m_nSteps & MIGRATE_VM_APP_STARTED && m_pVm.getImpl()) { /* stop Vm */ CProtoCommandPtr pCmd = CProtoSerializer::CreateProtoVmCommandStop(m_sVmUuid, PSM_KILL, 0); pPackage = DispatcherPackage::createInstance( PVE::DspCmdVmStop, pCmd ); m_pVm->stop(getClient(), pPackage, PSM_KILL, true); // Wait until VM stopped while (m_pVm->isConnected()) { if (operationIsCancelled() && CDspService::instance()->isServerStopping()) break; QThread::msleep(1000); } } if (m_pVm.getImpl()) { CDspVm::UnregisterVmObject(m_pVm); m_pVm = SmartPtr<CDspVm>(0); } if (!CDspService::instance()->isServerStopping()) CDspService::instance()->getVmConfigWatcher().unregisterVmToWatch(m_sTargetVmHomePath); if ( !(m_nReservedFlags & PVM_DONT_COPY_VM) ) { CFileHelper::ClearAndDeleteDir(m_sTargetVmHomePath); } // Unregister VM dir item CDspService::instance()->getVmDirHelper().deleteVmDirectoryItem(m_sVzDirUuid, m_sVmUuid); CVmEvent cDelEvent(PET_DSP_EVT_VM_DELETED, m_sVmUuid, PIE_DISPATCHER); SmartPtr<IOPackage> pDelPackage = DispatcherPackage::createInstance(PVE::DspVmEvent, cDelEvent.toString()); CDspService::instance()->getClientManager().sendPackageToClientList( pDelPackage, clientList); } /* migration initiator wait event from original Vm uuid */ CVmEvent cEvent(PET_DSP_EVT_VM_MIGRATE_CANCELLED, m_sOriginVmUuid, PIE_DISPATCHER); pPackage = DispatcherPackage::createInstance(PVE::DspVmEvent, cEvent.toString()); CDspService::instance()->getClientManager().sendPackageToClientList(pPackage, clientList); if (m_pStartDispConnection.isValid()) hJob = m_pStartDispConnection->sendResponseError(getLastError(), getRequestPackage()); else hJob = m_pCheckDispConnection->sendResponseError(getLastError(), getRequestPackage()); CDspService::instance()->getIOServer().waitForSend(hJob, m_nTimeout); } }
Boolean UNIX_BGPService::getLastErrorCode(CIMProperty &p) const { p = CIMProperty(PROPERTY_LAST_ERROR_CODE, getLastErrorCode()); return true; }
const char* CalError::getLastErrorDescriptionInternal() { switch (getLastErrorCode()) { case OK: return "No error found"; break; case INTERNAL: return "Internal error"; break; case INVALID_HANDLE: return "Invalid handle as argument"; break; case MEMORY_ALLOCATION_FAILED: return "Memory allocation failed"; break; case FILE_NOT_FOUND: return "File not found"; break; case INVALID_FILE_FORMAT: return "Invalid file format"; break; case FILE_PARSER_FAILED: return "Parser failed to process file"; break; case INDEX_BUILD_FAILED: return "Building of the index failed"; break; case NO_PARSER_DOCUMENT: return "There is no document to parse"; break; case INVALID_ANIMATION_DURATION: return "The duration of the animation is invalid"; break; case BONE_NOT_FOUND: return "Bone not found"; break; case INVALID_ATTRIBUTE_VALUE: return "Invalid attribute value"; break; case INVALID_KEYFRAME_COUNT: return "Invalid number of keyframes"; break; case INVALID_ANIMATION_TYPE: return "Invalid animation type"; break; case FILE_CREATION_FAILED: return "Failed to create file"; break; case FILE_WRITING_FAILED: return "Failed to write to file"; break; case INCOMPATIBLE_FILE_VERSION: return "Incompatible file version"; break; case NO_MESH_IN_MODEL: return "No mesh attached to the model"; break; case BAD_DATA_SOURCE: return "Cannot read from data source"; break; case NULL_BUFFER: return "Memory buffer is null"; break; case INVALID_MIXER_TYPE: return "The CalModel mixer is not a CalMixer instance"; break; default: break; } return "Unknown error"; }