MojErr MojDbPerfCreateTest::run() { MojErr err = file.open(CreateTestFileName, MOJ_O_RDWR | MOJ_O_CREAT | MOJ_O_TRUNC, MOJ_S_IRUSR | MOJ_S_IWUSR); MojString buf; err = buf.format("MojoDb Create Performance Test,,,,,\n\nOperation,Kind,Total Time,Time Per Iteration,Time Per Object\n"); MojTestErrCheck(err); err = fileWrite(file, buf); MojTestErrCheck(err); err = testCreate(); MojTestErrCheck(err); err = MojPrintF("\n\n TOTAL TEST TIME: %llu microseconds\n\n", totalTestTime.microsecs()); MojTestErrCheck(err); err = MojPrintF("\n-------\n"); MojTestErrCheck(err); err = buf.format("\n\nTOTAL TEST TIME,,%llu,,,", totalTestTime.microsecs()); MojTestErrCheck(err); err = fileWrite(file, buf); MojTestErrCheck(err); err = file.close(); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbPerfUpdateTest::updateObjsViaPut(MojDb& db, const MojChar* kindId, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64)) { // register all the kinds MojTime time; MojErr err = putKinds(db, time); MojTestErrCheck(err); // put objects using createFn MojObject objs; err = putObjs(db, kindId, numInsertForPut, createFn, objs); MojTestErrCheck(err); MojObject midObj; bool found = objs.at(numInsertForPut/2, midObj); MojTestAssert(found); MojTime objTime; err = putObj(db, midObj, objTime); MojTestErrCheck(err); MojUInt64 putTime = objTime.microsecs(); err = MojPrintF("\n -------------------- \n"); MojTestErrCheck(err); err = MojPrintF(" putting single object - index %llu - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/2, kindId, numPutIterations, putTime); MojTestErrCheck(err); err = MojPrintF(" time per put: %llu microsecs", (putTime) / (numPutIterations)); MojTestErrCheck(err); err = MojPrintF("\n\n"); MojTestErrCheck(err); MojString buf; err = buf.format("Put single object - index %llu - %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/2, numPutIterations, kindId, putTime, putTime/numPutIterations, putTime/(1*numPutIterations)); MojTestErrCheck(err); err = fileWrite(file, buf); MojTestErrCheck(err); MojTime batchTime; MojObject::ArrayIterator beginArr; err = objs.arrayBegin(beginArr); MojErrCheck(err); err = batchPutObj(db, beginArr, beginArr + (numInsertForPut / 10), batchTime); putTime = batchTime.microsecs(); MojTestErrCheck(err); err = MojPrintF(" putting batch - %llu objects - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/10, kindId, numBatchPutIterations, putTime); MojTestErrCheck(err); err = MojPrintF(" time per batch put: %llu microsecs\n", (putTime) / (numBatchPutIterations)); MojTestErrCheck(err); err = MojPrintF(" time per object: %llu microsecs", (putTime) / (numInsertForPut/10 * numBatchPutIterations)); MojTestErrCheck(err); err = MojPrintF("\n\n"); MojTestErrCheck(err); err = buf.format("Batch put %llu objects %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/10, numBatchPutIterations, kindId, putTime, putTime/numBatchPutIterations, putTime/(numInsertForPut/10*numBatchPutIterations)); MojTestErrCheck(err); err = fileWrite(file, buf); MojTestErrCheck(err); return MojErrNone; }
void ImapActivityFactory::BuildScheduledSync(ActivityBuilder& ab, const MojObject& accountId, const MojObject& folderId, int seconds, bool requireFair) { MojErr err; ab.SetName( GetScheduledSyncName(accountId, folderId) ); MojString desc; err = desc.format("Scheduled sync every %d minutes", seconds/60); ErrorToException(err); ab.SetDescription(desc.data()); ab.SetExplicit(true); ab.SetPersist(true); ab.SetImmediate(true, "low"); SetNetworkRequirements(ab, requireFair); // Metadata MojObject metadata; SetMetadata(metadata, SCHEDULED_SYNC_NAME, accountId, folderId); ab.SetMetadata(metadata); // Wakeup ab.SetSyncInterval(0, seconds); // Callback MojObject params; err = params.put("accountId", accountId); ErrorToException(err); ab.SetCallback(SCHEDULED_SYNC_CALLBACK, params); }
MojErr MojDbKindEngine::formatKindId(const MojChar* id, MojString& dbIdOut) { MojErr err = dbIdOut.format(_T("_kinds/%s"), id); MojErrCheck(err); return MojErrNone; }
void MojoDatabase::GetSentEmails(Signal::SlotRef slot, const MojObject& outboxFolderId, MojInt32 limit) { MojErr err; MojDbQuery query; err = query.from(EmailSchema::Kind::EMAIL); ErrorToException(err); err = query.where(EmailSchema::FOLDER_ID, MojDbQuery::OpEq, outboxFolderId); ErrorToException(err); MojString sendStatus; err = sendStatus.format("%s.%s",EmailSchema::SEND_STATUS, EmailSchema::SendStatus::SENT); ErrorToException(err); err = query.where(sendStatus.data(), MojDbQuery::OpEq, true); ErrorToException(err); // Set limit if(limit > 0) { query.limit(limit); } slot.cancel(); // cancel existing slot in case we're in a callback err = m_dbClient.find(slot, query); ErrorToException(err); }
MojErr MojDbPerfUpdateTest::testUpdateKind(MojDb& db) { MojString buf; MojErr err = buf.format("\nUPDATE KIND,,,,,\n"); MojTestErrCheck(err); err = fileWrite(file, buf); MojTestErrCheck(err); err = updateKind(db, MojPerfSmKindId, MojPerfSmKindStr, MojPerfSmKindExtraIndex, &MojDbPerfTest::createSmallObj); MojTestErrCheck(err); err = updateKind(db, MojPerfMedKindId, MojPerfMedKindStr, MojPerfMedKindExtraIndex, &MojDbPerfTest::createMedObj); MojTestErrCheck(err); err = updateKind(db, MojPerfLgKindId, MojPerfLgKindStr, MojPerfLgKindExtraIndex, &MojDbPerfTest::createLargeObj); MojTestErrCheck(err); err = updateKind(db, MojPerfMedNestedKindId, MojPerfMedNestedKindStr, MojPerfMedNestedKindExtraIndex, &MojDbPerfTest::createMedNestedObj); MojTestErrCheck(err); err = updateKind(db, MojPerfLgNestedKindId, MojPerfLgNestedKindStr, MojPerfLgNestedKindExtraIndex, &MojDbPerfTest::createLargeNestedObj); MojTestErrCheck(err); err = updateKind(db, MojPerfMedArrayKindId, MojPerfMedArrayKindStr, MojPerfMedArrayKindExtraIndex, &MojDbPerfTest::createMedArrayObj); MojTestErrCheck(err); err = updateKind(db, MojPerfLgArrayKindId, MojPerfLgArrayKindStr, MojPerfLgArrayKindExtraIndex, &MojDbPerfTest::createLargeArrayObj); MojTestErrCheck(err); return MojErrNone; }
MojErr SmtpAccountDisableCommand::DeleteAccountWatchResponse(MojObject& response, MojErr err) { MojLogInfo(m_log, "SmtpAccountDisable replying"); try { if(err) { if(err == ENOENT) { MojLogWarning(m_log, "account watch activity doesn't exist"); } else { ResponseToException(response, err); } } m_msg->replySuccess(); Complete(); } catch (const std::exception& e) { m_msg->replyError(err, e.what()); Failure(e); } catch (...) { MojString error; error.format("uncaught exception in %s", __PRETTY_FUNCTION__); m_msg->replyError(MojErrInternal, error.data()); Failure(MailException("unknown exception in cancelling activities response", __FILE__, __LINE__)); } return MojErrNone; }
void NetworkStatusMonitor::CreateActivity() { ActivityBuilder ab; static MojInt64 uniqueId = 0; string serviceName = m_busClient.GetServiceName(); // FIXME if(serviceName.empty()) { throw MailException("no service name", __FILE__, __LINE__); } MojString name; MojErr err = name.format("%s network status check - %lld", serviceName.c_str(), ++uniqueId); ErrorToException(err); ab.SetName(name.data()); ab.SetDescription("Monitors network status"); ab.SetExplicit(false); ab.SetPersist(false); ab.SetForeground(true); ab.SetRequiresInternet(true); m_activity = Activity::PrepareNewActivity(ab, true, true); m_activity->SetSlots(m_activityUpdateSlot, m_activityErrorSlot); m_activity->Create(m_busClient); }
void SmtpActivityFactory::BuildOutboxWatch(ActivityBuilder& ab, const MojObject& accountId, const MojObject& folderId) { ActivityBuilder actBuilder; MojString name; name.format(OUTBOX_WATCH_ACTIVITY_FMT, AsJsonString(accountId).c_str()); ab.SetName(name); ab.SetDescription("Watches SMTP outbox for new emails"); ab.SetPersist(true); ab.SetExplicit(true); ab.SetRequiresInternet(false); // don't trigger until we also have connectivity ab.SetImmediate(true, ActivityBuilder::PRIORITY_LOW); // Callback MojObject callbackParams; MojErr err = callbackParams.put("accountId", accountId); ErrorToException(err); err = callbackParams.put("folderId", folderId); ErrorToException(err); ab.SetCallback(OUTBOX_BUS_METHOD, callbackParams); ab.SetMetadata(callbackParams); }
MojErr SmtpAccountDisableCommand::DeleteOutboxWatchResponse(MojObject& response, MojErr err) { MojLogInfo(m_log, "SmtpAccountDisable removing outbox watch"); try { if(err) { if(err == ENOENT) { MojLogWarning(m_log, "outbox watch activity doesn't exist"); } else { ResponseToException(response, err); } } MojObject payload; payload.put("activityName", m_accountWatchActivityName); m_client.SendRequest(m_deleteAccountWatchResponseSlot, "com.palm.activitymanager", "cancel", payload); } catch (const std::exception& e) { m_msg->replyError(err, e.what()); Failure(e); } catch (...) { MojString error; error.format("uncaught exception in %s", __PRETTY_FUNCTION__); m_msg->replyError(MojErrInternal, error.data()); Failure(MailException("unknown exception in cancelling activities response", __FILE__, __LINE__)); } return MojErrNone; }
MojString getTestDir() { MojString dir; MojErr err = dir.format("/tmp/mojodb-test-dir-%d", getpid()); assert( err == MojErrNone ); return dir; }
void MovePopEmailsCommand::RunImpl() { CommandTraceFunction(); try { if (!m_client.GetAccount().get()) { MojString err; err.format("Account is not loaded for '%s'", AsJsonString( m_client.GetAccountId()).c_str()); throw MailException(err.data(), __FILE__, __LINE__); } MojErr err = m_payload.getRequired("accountId", m_accountId); ErrorToException(err); m_activity = ActivityParser::GetActivityFromPayload(m_payload); if (m_activity.get()) { m_activity->SetSlots(m_activityUpdateSlot, m_activityErrorSlot); m_activity->Adopt(m_client); return; } else { GetEmailsToMove(); } } catch (const std::exception& ex) { m_msg->replyError(MojErrInternal, ex.what()); Failure(ex); } catch (...) { MailException ex("unknown exception", __FILE__, __LINE__); m_msg->replyError(MojErrInternal, ex.what()); Failure(ex); } }
void SyncAccountCommand::RunImpl() { try { if (!m_client.GetAccount().get()) { MojString err; err.format("Account is not loaded for '%s'", AsJsonString( m_client.GetAccountId()).c_str()); throw MailException(err.data(), __FILE__, __LINE__); } m_account = m_client.GetAccount(); if(m_account->HasPassword()) { m_accountId = m_account->GetAccountId(); MojObject inboxFolderId = m_account->GetInboxFolderId(); MojLogInfo(m_log, "Creating command to sync inbox emails"); MojErr err = m_payload.put(EmailSchema::FOLDER_ID, inboxFolderId); ErrorToException(err); m_client.SyncFolder(m_payload); } else { MojLogInfo(m_log, "No password! Sync aborted!"); } Complete(); } catch (const std::exception& ex) { Failure(ex); } catch (...) { Failure(MailException("Unknown exception", __FILE__, __LINE__)); } }
MojErr MojDbPerfUpdateTest::testMerge(MojDb& db) { MojString buf; MojErr err = buf.format("\nUPDATE VIA MERGE,,,,,\n"); MojTestErrCheck(err); err = fileWrite(file, buf); MojTestErrCheck(err); err = updateObjsViaMerge(db, MojPerfSmKindId, &MojDbPerfTest::createSmallObj); MojTestErrCheck(err); err = updateObjsViaMerge(db, MojPerfMedKindId, &MojDbPerfTest::createMedObj); MojTestErrCheck(err); err = updateObjsViaMerge(db, MojPerfLgKindId, &MojDbPerfTest::createLargeObj); MojTestErrCheck(err); err = updateObjsViaMerge(db, MojPerfMedNestedKindId, &MojDbPerfTest::createMedNestedObj); MojTestErrCheck(err); err = updateObjsViaMerge(db, MojPerfLgNestedKindId, &MojDbPerfTest::createLargeNestedObj); MojTestErrCheck(err); err = updateObjsViaMerge(db, MojPerfMedArrayKindId, &MojDbPerfTest::createMedArrayObj); MojTestErrCheck(err); err = updateObjsViaMerge(db, MojPerfLgArrayKindId, &MojDbPerfTest::createLargeArrayObj); MojTestErrCheck(err); return MojErrNone; }
MojString ImapActivityFactory::FormatName(const char* name, const MojObject& accountId, const MojObject& folderId) { MojString formattedName; MojErr err = formattedName.format("%s/accountId=%s/folderId=%s", name, AsJsonString(accountId).c_str(), AsJsonString(folderId).c_str()); ErrorToException(err); return formattedName; }
MojErr MojDbPerfUpdateTest::updateKind(MojDb& db, const MojChar* kindId, const MojChar* kindJson, const MojChar* extraIdxJson, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64)) { // register all the kinds MojTime time; MojErr err = putKinds(db, time); MojTestErrCheck(err); // put objects using createFn MojObject objs; err = putObjs(db, kindId, numObjectsBeforeUpdateKind, createFn, objs); MojTestErrCheck(err); // add an index MojObject kindObj; err = kindObj.fromJson(kindJson); MojTestErrCheck(err); MojObject indexes; kindObj.get(_T("indexes"), indexes); MojTestErrCheck(err); MojObject extraIdx; err = extraIdx.fromJson(extraIdxJson); MojTestErrCheck(err); indexes.push(extraIdx); err = kindObj.put(_T("indexes"), indexes); MojTestErrCheck(err); MojTime addIndexTime; MojTime dropIndexTime; err = timeUpdateKind(db, kindJson, kindObj, addIndexTime, dropIndexTime); MojTestErrCheck(err); MojUInt64 addTime = addIndexTime.microsecs(); MojUInt64 dropTime = dropIndexTime.microsecs(); err = MojPrintF("\n -------------------- \n"); MojTestErrCheck(err); err = MojPrintF(" updating kind %s - adding index %s %llu times took: %llu microsecs\n", kindId, extraIdxJson, numUpdateKindIterations, addTime); MojTestErrCheck(err); err = MojPrintF(" time per add/reindex: %llu microsecs\n", (addTime) / (numUpdateKindIterations)); MojTestErrCheck(err); err = MojPrintF(" updating kind %s - dropping index %s %llu times took: %llu microsecs\n", kindId, extraIdxJson, numUpdateKindIterations, dropTime); MojTestErrCheck(err); err = MojPrintF(" time per drop: %llu microsecs", (dropTime) / (numUpdateKindIterations)); MojTestErrCheck(err); err = MojPrintF("\n\n"); MojTestErrCheck(err); MojString buf; err = buf.format("Updating kind %s - adding index %s %llu times,%s,%llu,%llu,%llu,\nUpdating kind %s - dropping index %s %llu times,%s,%llu,%llu,%llu,\n", kindId, extraIdxJson, numUpdateKindIterations, kindId, addTime, addTime/numUpdateKindIterations, addTime/(1*numUpdateKindIterations), kindId, extraIdxJson, numUpdateKindIterations, kindId, dropTime, dropTime/numUpdateKindIterations, dropTime/(1*numUpdateKindIterations)); MojTestErrCheck(err); err = fileWrite(file, buf); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDb::checkDbVersion(const MojChar* path) { MojAssert(path); MojLogTrace(s_log); MojString version; MojString versionFileName; MojErr err = versionFileName.format(_T("%s/%s"), path, VersionFileName); MojErrCheck(err); err = MojFileToString(versionFileName, version); MojErrCatch(err, MojErrNotFound) { // if the version file is not found, create it // make sure the directory exists err = MojCreateDirIfNotPresent(path); MojErrCheck(err); err = version.format(_T("%lld"), DatabaseVersion); MojErrCheck(err); err = MojFileFromString(versionFileName, version); MojErrCheck(err); } else {
void SmtpActivityFactory::BuildSmtpConfigWatch(ActivityBuilder& ab, const MojObject& accountId, MojInt64 rev) { MojErr err; MojString name; err = name.format(ACCOUNT_WATCH_ACTIVITY_FMT, AsJsonString(accountId).c_str()); ErrorToException(err); // description of watch MojString desc; err = desc.format("Watches SMTP config on account %s", AsJsonString(accountId).c_str()); ErrorToException(err); // activity to setup watch ab.SetName(name); ab.SetDescription(desc.data()); ab.SetPersist(true); ab.SetExplicit(true); ab.SetRequiresInternet(false); // trigger even if we don't have a network connection ab.SetImmediate(true, ActivityBuilder::PRIORITY_LOW); // setup trigger // NOTE: how to trigger only on SMTP config change? MojDbQuery trigger; err = trigger.from("com.palm.mail.account:1"); ErrorToException(err); err = trigger.where("accountId", MojDbQuery::OpEq, accountId); ErrorToException(err); if (rev > 0) { trigger.where("_revSmtp", MojDbQuery::OpGreaterThan, rev); } ab.SetDatabaseWatchTrigger(trigger); MojObject params; err = params.put("accountId", accountId); ErrorToException(err); ab.SetCallback(ACCOUNT_UPDATED_BUS_METHOD, params); ab.SetMetadata(params); }
// This is used if we don't have any other activity to get network status from void ImapActivityFactory::BuildConnect(ActivityBuilder& ab, const MojObject& accountId, MojUInt64 uniqueId) { MojString name; MojErr err = name.format("%s - %lld", CONNECT_NAME, uniqueId); ErrorToException(err); ab.SetName( FormatName(name.data(), accountId) ); ab.SetDescription("Activity for connecting to server"); ab.SetExplicit(false); ab.SetPersist(false); ab.SetForeground(true); ab.SetRequiresInternet(false); }
void ScheduleRetryCommand::CancelActivities() { // Delete anything that includes the folderId in the name MojString folderIdSubstring; MojErr err = folderIdSubstring.format("folderId=%s", AsJsonString(m_folderId).c_str()); ErrorToException(err); MojString retryActivityName; m_client.GetActivityBuilderFactory()->GetFolderRetrySyncActivityName(retryActivityName, m_folderId); m_deleteActivitiesCommand.reset(new DeleteActivitiesCommand(m_client)); m_deleteActivitiesCommand->SetIncludeNameFilter(folderIdSubstring); m_deleteActivitiesCommand->SetExcludeNameFilter(retryActivityName); m_deleteActivitiesCommand->Run(m_deleteActivitiesSlot); }
void DownloadPartCommand::RunImpl() { try { if (!m_client.GetAccount().get()) { MojString err; err.format("Account is not loaded for '%s'", AsJsonString(m_client.GetAccountId()).c_str()); throw MailException(err.data(), __FILE__, __LINE__); } m_client.GetSession()->FetchEmail(m_emailId, m_partId, m_listener); Complete(); } catch (const std::exception& ex) { Failure(ex); } catch (...) { Failure(MailException("Unknown exception in downloading email", __FILE__, __LINE__)); } }
void ScheduleRetryCommand::RunImpl() { try { if (!m_client.GetAccount().get()) { MojString err; err.format("Account is not loaded for '%s'", AsJsonString( m_client.GetAccountId()).c_str()); throw MailException(err.data(), __FILE__, __LINE__); } ScheduleRetry(); } catch (const std::exception& ex) { Failure(ex); } catch (...) { Failure(MailException("Unknown exception in scheduling POP account retry", __FILE__, __LINE__)); } }
MojErr IMServiceHandler::onEnabled(MojServiceMessage* serviceMsg, const MojObject payload) { MojRefCountedPtr<OnEnabledHandler> handler(new OnEnabledHandler(m_service)); MojErr err = handler->start(payload); if (err == MojErrNone) { serviceMsg->replySuccess(); } else { MojString error; MojString msg; MojErrToString(err, error); msg.format(_T("OnEnabledHandler.start() failed: error %d - %s"), err, error.data()); MojLogError(IMServiceApp::s_log, _T("%s"), msg.data()); serviceMsg->replyError(err); } return MojErrNone; }
void SmtpSyncOutboxCommand::CheckNetworkConnectivity() { try { if (m_networkStatus->IsKnown()) { if (m_networkStatus->IsConnected()) { MojLogInfo(m_log, "CheckNetworkActivity: is connected, moving on"); GetAccount(); return; } else { MojLogInfo(m_log, "CheckNetworkActivity: is not connected, erroring out"); // Note that this account error explicitly doesn't delay the retry, on the assumption // that the next activity will be blocked until the network is available. m_error.errorCode = MailError::NO_NETWORK; m_error.errorOnAccount = true; m_error.errorOnEmail = false; m_error.internalError = "No network available for outbox sync"; m_error.errorText = ""; CompleteAndUpdateActivities(); return; } } else { MojLogInfo(m_log, "CheckNetworkActivity: state unknown, starting new activity"); MojLogInfo(m_log, "OutboxSyncer creating new network activity"); ActivityBuilder ab; MojString name; MojErr err = name.format("SMTP Internal Outbox Sync Network Activity for account %s", AsJsonString(m_accountId).c_str()); ErrorToException(err); ab.SetName(name); ab.SetDescription("Activity representing SMTP Outbox Sync Network Monitor"); ab.SetForeground(true); ab.SetRequiresInternet(false); ab.SetImmediate(true, ActivityBuilder::PRIORITY_LOW); m_networkActivity = Activity::PrepareNewActivity(ab); m_networkActivity->SetSlots(m_networkActivityUpdatedSlot, m_networkActivityErrorSlot); m_networkActivity->Create(m_client); } } catch (std::exception & e) { HandleException(e, __func__); } catch (...) { HandleException(__func__); } }
MojErr MojDbQuotaEngine::put(MojObject& obj, MojDbReq& req, bool putObj) { MojLogTrace(s_log); MojAssertWriteLocked(m_db->schemaLock()); // check for admin permission if (!req.admin()) { MojErrThrow(MojErrDbPermissionDenied); } // pull params out of object MojString owner; MojErr err = obj.getRequired(MojDbServiceDefs::OwnerKey, owner); MojErrCheck(err); MojInt64 size = 0; err = obj.getRequired(MojDbServiceDefs::SizeKey, size); MojErrCheck(err); // validate owner err = validateWildcard(owner, MojErrDbInvalidOwner); MojErrCheck(err); // put object if (putObj) { MojString id; err = id.format(_T("_quotas/%s"), owner.data()); MojErrCheck(err); err = obj.put(MojDb::IdKey, id); MojErrCheck(err); err = obj.putString(MojDb::KindKey, MojDbKindEngine::QuotaId); MojErrCheck(err); MojDbAdminGuard adminGuard(req); err = m_db->put(obj, MojDb::FlagForce, req); MojErrCheck(err); // defer commit of quota until txn commit MojRefCountedPtr<MojDbQuotaCommitHandler> handler(new MojDbQuotaCommitHandler(this, owner, size, req.txn())); MojAllocCheck(handler.get()); } else { err = commitQuota(owner, size); MojErrCheck(err); } return MojErrNone; }
void ImapActivityFactory::BuildSyncRetry(ActivityBuilder& ab, const MojObject& accountId, const MojObject& folderId, int seconds, const std::string& reason) { MojErr err; ab.SetName( GetSyncRetryName(accountId, folderId) ); MojString desc; err = desc.format("Retry sync after %d seconds", seconds); ErrorToException(err); ab.SetDescription(desc.data()); ab.SetExplicit(true); ab.SetPersist(true); ab.SetImmediate(true, "low"); SetNetworkRequirements(ab, seconds <= 5 * 60); // Metadata MojObject metadata; SetMetadata(metadata, SYNC_RETRY_NAME, accountId, folderId); ab.SetMetadata(metadata); // Wakeup ab.SetSyncInterval(seconds, 0); // Callback MojObject params; err = params.put("accountId", accountId); ErrorToException(err); err = params.put("folderId", folderId); ErrorToException(err); MojObject retry; if(!reason.empty()) { err = retry.putString("reason", reason.c_str()); ErrorToException(err); } err = retry.put("interval", seconds); ErrorToException(err); err = params.put("retry", retry); ErrorToException(err); ab.SetCallback(SYNC_RETRY_CALLBACK, params); }
MojErr MojLunaService::enableSubscriptionImpl(MojServiceMessage* msg) { LOG_TRACE("Entering function %s", __FUNCTION__); MojAssert(msg); MojAssertMutexUnlocked(m_mutex); MojString token; MojErr err = token.format(_T("%d"), msg->token()); MojErrCheck(err); MojLunaErr lserr; MojLunaMessage* lsMessage = static_cast<MojLunaMessage*>(msg); LSHandle* handle = LSMessageGetConnection(lsMessage->impl()); bool retVal = LSSubscriptionAdd(handle, token, lsMessage->impl(), lserr); MojLsErrCheck(retVal, lserr); return MojErrNone; }
void ScheduleRetryCommand::CancelActivities() { CommandTraceFunction(); // Delete anything that includes the folderId in the name MojString folderIdSubstring; MojErr err = folderIdSubstring.format("folderId=%s", AsJsonString(m_folderId).c_str()); ErrorToException(err); // Don't delete the retry activity ImapActivityFactory factory; MojString retryActivityName = factory.GetSyncRetryName(m_client.GetAccountId(), m_folderId); m_deleteActivitiesCommand.reset(new DeleteActivitiesCommand(m_client)); m_deleteActivitiesCommand->SetIncludeNameFilter(folderIdSubstring); m_deleteActivitiesCommand->SetExcludeNameFilter(retryActivityName); m_deleteActivitiesCommand->Run(m_deleteActivitiesSlot); }
void PopAccountEnableCommand::RunImpl() { try { if (!m_client.GetAccount().get()) { MojString err; err.format("Account is not loaded for '%s'", AsJsonString( m_client.GetAccountId()).c_str()); throw MailException(err.data(), __FILE__, __LINE__); } m_account = m_client.GetAccount(); m_accountId = m_account->GetAccountId(); FindSpecialFolders(); } catch (const std::exception& ex) { Failure(ex); } catch (...) { Failure(MailException("Unknown exception in enabling POP account", __FILE__, __LINE__)); } }
MojErr MojLunaService::sendImpl(MojServiceRequest* req, const MojChar* service, const MojChar* method, Token& tokenOut) { LOG_TRACE("Entering function %s", __FUNCTION__); MojAssert(req && service && method); MojAssert(m_service || m_handle); MojAssertMutexLocked(m_mutex); MojLunaRequest* lunaReq = static_cast<MojLunaRequest*>(req); const MojChar* json = lunaReq->payload(); LOG_DEBUG("[db_lunaService] request sent: %s", json); MojString uri; MojErr err = uri.format(_T("%s://%s/%s"), UriScheme, service, method); MojErrCheck(err); MojLunaErr lserr; LSMessageToken lsToken; LSHandle* handle = getHandle(lunaReq->onPublic()); if (req->numRepliesExpected() > 1) { if (!lunaReq->isProxyRequest()) { bool retVal = LSCall(handle, uri, json, &handleResponse, this, &lsToken, lserr); MojLsErrCheck(retVal, lserr); } else { bool retVal = LSCallFromApplication(handle, uri, json, lunaReq->getRequester(), &handleResponse, this, &lsToken, lserr); MojLsErrCheck(retVal, lserr); } } else { if (!lunaReq->isProxyRequest()) { bool retVal = LSCallOneReply(handle, uri, json, &handleResponse, this, &lsToken, lserr); MojLsErrCheck(retVal, lserr); } else { bool retVal = LSCallFromApplicationOneReply(handle, uri, json, lunaReq->getRequester(), &handleResponse, this, &lsToken, lserr); MojLsErrCheck(retVal, lserr); } } tokenOut = (Token) lsToken; return MojErrNone; }