本文整理汇总了C++中MojString类的典型用法代码示例。如果您正苦于以下问题:C++ MojString类的具体用法?C++ MojString怎么用?C++ MojString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MojString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: to_list
void EmailAdapter::ParseRecipients(const MojObject& recipients, Email& email)
{
MojErr err;
EmailAddressListPtr to_list(new EmailAddressList);
EmailAddressListPtr cc_list(new EmailAddressList);
EmailAddressListPtr bcc_list(new EmailAddressList);
MojObject::ConstArrayIterator it = recipients.arrayBegin();
for (; it != recipients.arrayEnd(); ++it) {
const MojObject& recipient = *it;
MojString type;
err = recipient.getRequired(Part::TYPE, type);
ErrorToException(err);
EmailAddressPtr addr = ParseAddress(recipient);
if(type.compareCaseless("to") == 0)
to_list->push_back(addr);
else if(type.compareCaseless("cc") == 0)
cc_list->push_back(addr);
else if(type.compareCaseless("bcc") == 0)
bcc_list->push_back(addr);
else // not a valid recipient type
throw MailException("invalid recipient type", __FILE__, __LINE__);
}
email.SetTo(to_list);
email.SetCc(cc_list);
email.SetBcc(bcc_list);
}
示例2: MojLogTrace
bool MojoCompareMatcher::Match(const MojObject& response)
{
MojLogTrace(s_log);
if (response.contains(m_key)) {
MojObject value;
MojString valueString;
response.get(m_key, value);
value.stringValue(valueString);
if (value != m_value) {
MojString oldValueString;
m_value.stringValue(oldValueString);
MojLogInfo(s_log, _T("Compare Matcher: Comparison key \"%s\" "
"value changed from \"%s\" to \"%s\". Firing."), m_key.data(),
oldValueString.data(), valueString.data());
return true;
} else {
MojLogInfo(s_log, _T("Compare Matcher: Comparison key \"%s\" "
"value \"%s\" unchanged."), m_key.data(), valueString.data());
}
} else {
MojLogInfo(s_log, _T("Compare Matcher: Comparison key (%s) not "
"present."), m_key.data());
}
return false;
}
示例3: MojLogInfo
void SmtpSendMailCommand::RunImpl()
{
try {
if (m_session.HasError()) {
if (m_session.GetError().errorOnEmail) {
// this doesn't make any sense, but if we don't mark the mail as bad, someone
// is going to loop...
m_error = m_session.GetError();
MojLogInfo(m_log, "SendMail dying off, marking mail as bad ...");
UpdateSendStatus();
} else {
MojLogInfo(m_log, "SendMail dying off, due to session error state ...");
m_doneSignal.fire(m_session.GetError());
Complete();
}
return;
}
MojString json;
m_emailId.toJson(json);
MojLogInfo(m_log, "running sendMail id=%s", json.data());
GetEmail();
} catch (const std::exception& e) {
HandleException(e, __func__, __FILE__, __LINE__);
} catch (...) {
HandleUnknownException();
}
}
示例4: CheckProperty
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty(
const MojObject& key, const MojObject& response, const MojObject& op,
const MojObject& val, MatchMode mode) const
{
if (key.type() == MojObject::TypeString) {
MojString keyStr;
MojErr err = key.stringValue(keyStr);
if (err) {
throw std::runtime_error("Failed to convert property lookup key "
"to string");
}
MojObject propVal;
bool found = response.get(keyStr.data(), propVal);
if (!found) {
return NoProperty;
}
return CheckMatch(propVal, op, val);
} else if (key.type() == MojObject::TypeArray) {
return CheckProperty(key, key.arrayBegin(), response, op, val, mode);
} else {
throw std::runtime_error("Key specified was neither a string or "
"array of strings");
}
}
示例5: TEST_F
TEST_F(QuotaTest, enforce)
{
MojObject obj;
// put quota
MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );
// make kind2 inherit from kind1
MojAssertNoErr( obj.fromJson(MojTestKind2Str3) );
MojExpectNoErr( db.putKind(obj) );
//// end of prerequisites form prev tests
// set quota size to current usage
MojInt64 quotaUsage1 = 0;
EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
MojAssertNoErr( obj.putString(_T("owner"), _T("com.foo.bar")) );
MojAssertNoErr( obj.putInt(_T("size"), quotaUsage1) );
MojExpectNoErr( db.putQuotas(&obj, &obj + 1) );
MojAssertNoErr( obj.fromJson(MojTestKind1Objects[3]) );
EXPECT_EQ( MojErrDbQuotaExceeded, db.put(obj) );
// Try to delete the kind
MojString kindStr;
MojAssertNoErr( kindStr.assign(_T("Test:1")) );
bool found = false;
EXPECT_EQ( MojErrDbKindHasSubKinds, db.delKind(kindStr, found) )
<< "The delete should be failure, because it contain sub kind \"Test2:1\"";
EXPECT_FALSE( found );
}
示例6: containers
MojErr ContainerManager::InfoToJson(MojObject& rep) const
{
MojObject containers(MojObject::TypeArray);
std::for_each(m_containers.begin(), m_containers.end(),
boost::bind(&ResourceContainer::PushJson,
boost::bind(&ContainerMap::value_type::second, _1),
boost::ref(containers)));
MojErr err = rep.put(_T("containers"), containers);
MojErrCheck(err);
MojObject entityMap(MojObject::TypeArray);
for (EntityContainerMap::const_iterator iter = m_entityContainers.begin();
iter != m_entityContainers.end(); ++iter) {
MojObject mapping(MojObject::TypeObject);
MojString containerName;
err = containerName.assign(iter->second->GetName().c_str());
MojErrCheck(err);
err = mapping.put(iter->first->GetName().c_str(), containerName);
MojErrCheck(err);
err = entityMap.push(mapping);
MojErrCheck(err);
}
err = rep.put(_T("entityMap"), entityMap);
MojErrCheck(err);
return MojErrNone;
}
示例7: getTestDir
MojString getTestDir()
{
MojString dir;
MojErr err = dir.format("/tmp/mojodb-test-dir-%d", getpid());
assert( err == MojErrNone );
return dir;
}
示例8: MojLogInfo
void SmtpSyncOutboxCommand::StartSync()
{
if (m_clear) {
MojLogInfo(m_log, "Clearing account before running sync");
m_client.GetSession()->ClearAccount();
}
MojString folderIdJson;
m_folderId.toJson(folderIdJson);
MojLogInfo(m_log, "syncing outbox %s", folderIdJson.data());
m_error.clear();
// Set up error code that will be logged on account if we fall over without managing to elsewise
// report an error code -- just in case.
m_error.errorCode = MailError::INTERNAL_ERROR;
m_error.errorOnAccount = true;
m_error.errorOnEmail = false;
m_error.internalError = "Unknown error in smtp outbox processing";
m_error.errorText = "";
// FIXME: Shouldn't this be done before we reply to the sync
// message, or adopt the activity, or something? There's a
// lot of hysteresis in sleep, so this is unlikely to be
// critical, it just feels wrong to do this this late,
// without overlapping it over anything else.
m_client.GetPowerManager().StayAwake(true, "smtp outbox sync");
CheckNetworkConnectivity();
}
示例9: MojErrCheck
/*
* Save the new incoming IM message to the DB
*
* @return MojErr if error - caller will log it
*/
MojErr IncomingIMHandler::saveNewIMMessage(MojRefCountedPtr<IMMessage> IMMessage) {
MojErr err;
// The message we are handling
m_IMMessage = IMMessage;
// save it
MojObject dbObject;
err = m_IMMessage->createDBObject(dbObject);
MojErrCheck(err);
//add our kind to the object
//luna://com.palm.db/put '{"objects":[{"_kind":"com.palm.test:1","foo":1,"bar":1000}]}'
err = dbObject.putString(_T("_kind"), PALM_DB_IMMESSAGE_KIND);
MojErrCheck(err);
// log it - OK to show body in debug log
MojString json;
err = dbObject.toJson(json);
MojErrCheck(err);
MojLogDebug(IMServiceApp::s_log, _T("saving message to db: %s"), json.data());
MojLogInfo(IMServiceApp::s_log, _T("saving message to db"));
// save it
// the save generates a call to the save result handler
err = m_dbClient.put(this->m_IMSaveMessageSlot, dbObject);
MojErrCheck(err);
return MojErrNone;
}
示例10: run
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);
allTestsTime += totalTestTime;
err = MojPrintF("\n\n TOTAL TEST TIME: %llu nanoseconds. | %10.3f seconds.\n\n", totalTestTime, totalTestTime / 1000000000.0f);
MojTestErrCheck(err);
err = MojPrintF("\n-------\n");
MojTestErrCheck(err);
err = buf.format("\n\nTOTAL TEST TIME,,%llu,,,", totalTestTime);
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
err = file.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例11: LOG_AM_TRACE
bool MojoCompareMatcher::Match(const MojObject& response)
{
LOG_AM_TRACE("Entering function %s", __FUNCTION__);
if (response.contains(m_key)) {
MojObject value;
MojString valueString;
response.get(m_key, value);
value.stringValue(valueString);
if (value != m_value) {
MojString oldValueString;
m_value.stringValue(oldValueString);
LOG_AM_DEBUG("Compare Matcher: Comparison key \"%s\" value changed from \"%s\" to \"%s\". Firing.",
m_key.data(),
oldValueString.data(), valueString.data());
return true;
} else {
LOG_AM_DEBUG("Compare Matcher: Comparison key \"%s\" value \"%s\" unchanged.",
m_key.data(), valueString.data());
}
} else {
LOG_AM_DEBUG("Compare Matcher: Comparison key (%s) not present.",
m_key.data());
}
return false;
}
示例12: getQuotaUsage
MojErr MojDbQuotaTest::testEnforce(MojDb& db)
{
// set quota size to current usage
MojInt64 quotaUsage1 = 0;
MojErr err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojObject obj;
err = obj.putString(_T("owner"), _T("com.foo.bar"));
MojErrCheck(err);
err = obj.putInt(_T("size"), quotaUsage1);
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
err = put(db, MojTestKind1Objects[3]);
MojTestErrExpected(err, MojErrDbQuotaExceeded);
// Try to delete the kind
MojString kindStr;
err = kindStr.assign(_T("Test:1"));
MojTestErrCheck(err);
bool found = false;
err = db.delKind(kindStr, found);
//The delete should be failure, because it contain sub kind "Test2:1"
MojTestErrExpected(err,MojErrDbKindHasSubKinds);
MojTestAssert(!found);
return MojErrNone;
}
示例13: MailException
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);
}
示例14: MojLogTrace
/*
* New incoming IM message
*/
bool IMServiceHandler::incomingIM(const char* serviceName, const char* username, const char* usernameFrom, const char* message)
{
MojLogTrace(IMServiceApp::s_log);
// log the parameters
// don't log the message text
MojLogInfo (IMServiceApp::s_log, _T("incomingIM - IM received. serviceName: %s username: %s usernameFrom: %s"), serviceName, username, usernameFrom);
// no error - process the IM
MojRefCountedPtr<IMMessage> imMessage(new IMMessage);
// set the message fields based on the incoming parameters
MojErr err = imMessage->initFromCallback(serviceName, username, usernameFrom, message);
if (!err) {
// handle the message
MojRefCountedPtr<IncomingIMHandler> incomingIMHandler(new IncomingIMHandler(m_service));
err = incomingIMHandler->saveNewIMMessage(imMessage);
}
if (err) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("incomingIM failed: %d - %s"), err, error.data());
MojErrCheck(err);
return false;
}
return true;
}
示例15: CancelShutdown
MojErr PopBusDispatcher::CredentialsChanged(MojServiceMessage* msg, MojObject& payload)
{
// cancel shut down if it is in shut down state
CancelShutdown();
MojLogTrace(s_log);
MojString json;
MojErr err = payload.toJson(json);
ErrorToException(err);
MojLogInfo(s_log, "PopBusDispatcher::CredentialsChanged: payload=%s", json.data());
MojObject accountId;
err = payload.getRequired("accountId", accountId);
ErrorToException(err);
try {
ClientPtr client = GetOrCreateClient(accountId);
// Calling UpdateAccount will force a folder sync.
client->UpdateAccount(payload, true);
} catch (const std::exception& e) {
MojErrThrowMsg(MojErrInternal, "%s", e.what());
}
return msg->replySuccess();
}