本文整理汇总了C++中MojObject::get方法的典型用法代码示例。如果您正苦于以下问题:C++ MojObject::get方法的具体用法?C++ MojObject::get怎么用?C++ MojObject::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojObject
的用法示例。
在下文中一共展示了MojObject::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
MojErr
TestCategoryHandler::WhereMatchTest(MojServiceMessage *msg, MojObject &payload)
{
ACTIVITY_SERVICEMETHOD_BEGIN();
MojObject response;
bool found = payload.get(_T("response"), response);
if (!found) {
throw std::runtime_error("Please provide a \"response\" and a "
"\"where\" clause to test against it");
}
MojObject where;
found = payload.get(_T("where"), where);
if (!found) {
throw std::runtime_error("Please provide a \"where\" clause to test "
"the response against");
}
MojoNewWhereMatcher matcher(where);
bool matched = matcher.Match(response);
MojObject reply;
MojErr err = reply.putBool(_T("matched"), matched);
MojErrCheck(err);
err = msg->reply(reply);
MojErrCheck(err);
ACTIVITY_SERVICEMETHOD_END(msg);
return MojErrNone;
}
示例2: dispatchReply
MojErr MojService::dispatchReply(MojServiceMessage* msg)
{
MojAssert(msg);
MojAssertMutexUnlocked(m_mutex);
MojLogTrace(s_log);
// parse payload
MojObjectBuilder builder;
MojObject payload;
MojErr err = MojErrNone;
MojInt64 errCode = MojErrNone;
errCode = err = msg->payload(builder);
MojErrCatchAll(err);
if (errCode == MojErrNone)
payload = builder.object();
// get errCode
bool retVal = false;
if (payload.get(MojServiceMessage::ReturnValueKey, retVal) && !retVal) {
if (!payload.get(MojServiceMessage::ErrorCodeKey, errCode))
errCode = MojErrUnknown;
}
// find request
MojRefCountedPtr<MojServiceRequest> req;
err = getRequest(msg, req);
MojErrCheck(err);
// do the dispatch
err = dispatchReplyImpl(req.get(), msg, payload, (MojErr) errCode);
MojErrCatchAll(err);
return MojErrNone;
}
示例3: handleStats
MojErr MojDbServiceHandler::handleStats(MojServiceMessage* msg, MojObject& payload, MojDbReq& req)
{
MojAssert(msg);
MojLogTrace(s_log);
MojString forKind;
bool verify = false;
payload.get(MojDbServiceDefs::VerifyKey, verify);
MojString *pKind = NULL;
bool found = false;
MojErr err = payload.get(MojDbServiceDefs::KindKey, forKind, found);
MojErrCheck(err);
if (found)
pKind = &forKind;
MojObject results;
err = m_db.stats(results, req, verify, pKind);
MojErrCheck(err);
MojObjectVisitor& writer = msg->writer();
err = writer.beginObject();
MojErrCheck(err);
err = writer.boolProp(MojServiceMessage::ReturnValueKey, true);
MojErrCheck(err);
err = writer.objectProp(MojDbServiceDefs::ResultsKey, results);
MojErrCheck(err);
err = writer.endObject();
MojErrCheck(err);
return MojErrNone;
}
示例4: ValidateClause
void MojoWhereMatcher::ValidateClause(const MojObject& clause) const
{
MojLogTrace(s_log);
MojLogInfo(s_log, _T("Validating where clause \"%s\""),
MojoObjectJson(clause).c_str());
if (!clause.contains(_T("prop"))) {
throw std::runtime_error("Each where clause must contain a property "
"to operate on");
}
MojObject prop;
clause.get(_T("prop"), prop);
ValidateKey(prop);
if (!clause.contains(_T("op"))) {
throw std::runtime_error("Each where clause must contain a test "
"operation to perform");
}
MojObject op;
clause.get(_T("op"), op);
ValidateOp(op);
if (!clause.contains(_T("val"))) {
throw std::runtime_error("Each where clause must contain a value to "
"test against");
}
}
示例5: fromObjectImpl
MojErr MojDbPropExtractor::fromObjectImpl(const MojObject& obj, const MojDbPropExtractor& defaultConfig, const MojChar* locale)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
// super
MojErr err = MojDbExtractor::fromObject(obj, locale);
MojErrCheck(err);
// default value
m_default = defaultConfig.m_default;
MojObject defaultVal;
if (obj.get(DefaultKey, defaultVal)) {
MojObject::Type type = defaultVal.type();
MojDbKey key;
if (type == MojObject::TypeArray) {
// if the value is an array, act on its elements rather than the array object itself
MojObject::ConstArrayIterator end = defaultVal.arrayEnd();
for (MojObject::ConstArrayIterator j = defaultVal.arrayBegin(); j != end; ++j) {
err = key.assign(*j);
MojErrCheck(err);
err = m_default.put(key);
MojErrCheck(err);
}
} else {
err = key.assign(defaultVal);
MojErrCheck(err);
err = m_default.put(key);
MojErrCheck(err);
}
}
// tokenizer
m_tokenizer = defaultConfig.m_tokenizer;
MojString tokenize;
bool found = false;
err = obj.get(TokenizeKey, tokenize, found);
MojErrCheck(err);
if (found) {
if (tokenize == AllKey || tokenize == DefaultKey) {
m_tokenizer.reset(new MojDbTextTokenizer);
MojAllocCheck(m_tokenizer.get());
err = m_tokenizer->init(locale);
MojErrCheck(err);
} else {
MojErrThrow(MojErrDbInvalidTokenization);
}
}
// collator
if (m_collation == MojDbCollationInvalid)
m_collation = defaultConfig.m_collation;
err = updateLocale(locale);
MojErrCheck(err);
// set prop
err = prop(m_name);
MojErrCheck(err);
return MojErrNone;
}
示例6: inviteBuddy
/*
* inviteBuddy: tell libpurple to add the buddy
* add buddy to buddyStatus and contact DB kinds
*
* imcommand:
* {
"params" : {
"group" : {"type" : "string",
"optional" : true,
"description" : "The name of the group to put the buddy in."},
"message" : {"type" : "string",
"optional" : true,
"description" : "If the IM transport supports custom invite messages."}
}
* }
*
*/
LibpurpleAdapter::SendResult SendOneCommandHandler::inviteBuddy(const MojObject imCmd) {
bool found = false;
// params
MojObject params;
MojString group;
found = imCmd.get(MOJDB_PARAMS, params);
IMServiceHandler::logMojObjectJsonString(_T("command params: %s"),params);
if (found) {
params.get(XPORT_GROUP, group, found);
}
MojLogInfo (IMServiceApp::s_log, "sending addBuddy command to transport. id: %s, serviceName: %s, username: %s, buddyUsername: %s, groupName: %s",
m_currentCmdDbId.data(), m_serviceName.data(), m_username.data(), m_buddyName.data(), group.data());
// Note, libpurple does not return errors on send - adapter only checks that the parameters are valid and that the user is logged in
// otherwise assume success...
LibpurpleAdapter::SendResult retVal = LibpurpleAdapter::addBuddy(m_serviceName.data(), m_username.data(), m_buddyName.data(), group.data());
// Note: if the remote user rejects our invite, buddy gets deleted on the server but we do not get notified, so the contact will remain, but the buddy list gets re-synced on the next login
if (LibpurpleAdapter::SENT == retVal) {
// add to buddyStatus and contacts list. They will get removed later if the invite is rejected
addBuddyToDb();
}
return retVal;
}
示例7: blockBuddy
/*
* blockBuddy command: Send the blockBuddy command off to libPurple
* remove buddy from buddyStatus and contact DB kinds
* imcommand
* {
"params" : {
"block" : {"type" : "boolean",
"description" : "whether to block or unblock the buddy."}
}
* }
*/
LibpurpleAdapter::SendResult SendOneCommandHandler::blockBuddy(const MojObject imCmd) {
bool found = false;
// params
MojObject params;
found = imCmd.get(MOJDB_PARAMS, params);
IMServiceHandler::logMojObjectJsonString(_T("command params: %s"),params);
bool block = true;
found = params.get(XPORT_BLOCK, block);
MojLogInfo (IMServiceApp::s_log, "sending blockBuddy command to transport. id: %s, serviceName: %s, username: %s, buddyUsername: %s, block: %d",
m_currentCmdDbId.data(), m_serviceName.data(), m_username.data(), m_buddyName.data(), block);
// Note, libpurple does not return errors on send - adapter only checks that the parameters are valid and that the user is logged in
// otherwise assume success...
LibpurpleAdapter::SendResult retVal = LibpurpleAdapter::blockBuddy(m_serviceName.data(), m_username.data(), m_buddyName.data(), block);
if (LibpurpleAdapter::SENT == retVal) {
// if the buddy was blocked, remove from buddyStatus and contacts list, otherwise add it
if (block)
removeBuddyFromDb();
// Note: we don't actually have UI to unblock a buddy as of 6/28/2010 so this is not used...
else addBuddyToDb();
}
return retVal;
}
示例8: ValidateClause
void MojoWhereMatcher::ValidateClause(const MojObject& clause) const
{
LOG_AM_TRACE("Entering function %s", __FUNCTION__);
LOG_AM_DEBUG("Validating where clause \"%s\"",
MojoObjectJson(clause).c_str());
if (!clause.contains(_T("prop"))) {
throw std::runtime_error("Each where clause must contain a property "
"to operate on");
}
MojObject prop;
clause.get(_T("prop"), prop);
ValidateKey(prop);
if (!clause.contains(_T("op"))) {
throw std::runtime_error("Each where clause must contain a test "
"operation to perform");
}
MojObject op;
clause.get(_T("op"), op);
ValidateOp(op);
if (!clause.contains(_T("val"))) {
throw std::runtime_error("Each where clause must contain a value to "
"test against");
}
}
示例9: CheckClause
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckClause(
const MojObject& clause, const MojObject& response, MatchMode mode) const
{
LOG_AM_TRACE("Entering function %s", __FUNCTION__);
if (clause.type() == MojObject::TypeArray) {
return CheckClauses(clause, response, mode);
} else if (clause.type() != MojObject::TypeObject) {
throw std::runtime_error("Clauses must be either an object or array "
"of objects");
}
LOG_AM_DEBUG("Checking clause '%s' against response '%s' (%s)",
MojoObjectJson(clause).c_str(), MojoObjectJson(response).c_str(),
(mode == AndMode) ? "and" : "or");
if (clause.contains(_T("and"))) {
MojObject andClause;
clause.get(_T("and"), andClause);
return CheckClause(andClause, response, AndMode);
} else if (clause.contains(_T("or"))) {
MojObject orClause;
clause.get(_T("or"), orClause);
return CheckClause(orClause, response, OrMode);
}
MojObject prop;
bool found = clause.get(_T("prop"), prop);
if (!found) {
throw std::runtime_error("Clauses must contain \"and\", \"or\", "
"or a comparison to make");
}
MojObject op;
found = clause.get(_T("op"), op);
if (!found) {
throw std::runtime_error("Clauses must specify a comparison operation "
"to perform");
}
MojObject val;
found = clause.get(_T("val"), val);
if (!found) {
throw std::runtime_error("Clauses must specify a value to compare "
"against");
}
MatchResult result = CheckProperty(prop, response, op, val, mode);
LOG_AM_DEBUG("Where Trigger: Clause %s %s",
MojoObjectJson(clause).c_str(), (result == Matched) ? "matched" :
"did not match");
return result;
}
示例10: NetworkStatusUpdate
/*
* networkStatusQuery
*
* {
* "extended" : {
* ...
* "state" : "noservice" | "limited" | "service"
* ...
* }
* }
*
*/
void TelephonyProxy::NetworkStatusUpdate(MojServiceMessage *msg,
const MojObject& response, MojErr err)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
LOG_DEBUG("Network status update message: %s",
MojoObjectJson(response).c_str());
if (err != MojErrNone) {
if (MojoCall::IsPermanentFailure(msg, response, err)) {
LOG_WARNING(MSGID_TIL_NWSTATUS_QUERY_ERR,0,
"TIL experienced an uncorrectable failure : %s", MojoObjectJson(response).c_str());
m_networkStatusQuery.reset();
} else {
LOG_WARNING(MSGID_TIL_NWSTATUS_QUERY_RETRY, 0,
"Subscription to TIL failed, retrying - %s", MojoObjectJson(response).c_str() );
m_networkStatusQuery->Call();
}
return;
}
MojObject extended;
bool found;
found = response.get(_T("extended"), extended);
if (!found) {
/* Way to have 2 different formats for the same thing! First
* response names the property "extended". All subsequent ones
* name it "eventNetwork". */
found = response.get(_T("eventNetwork"), extended);
}
if (found) {
MojString status;
MojErr err2;
err2 = extended.get(_T("state"), status, found);
if (err2) {
LOG_WARNING(MSGID_TIL_NWSTATE_ERR, 1 ,
PMLOGKFV("NWSTATE","%d",err2),
"Error attempting to retrieve network state");
} else if (found) {
if (status == "service") {
m_haveTelephonyService = true;
} else {
m_haveTelephonyService = false;
}
UpdateTelephonyState();
} else {
LOG_WARNING(MSGID_TIL_NO_NWSTATE, 0 ,
"Network status update message did not include network state: %s", MojoObjectJson(response).c_str());
}
}
}
示例11: configure
MojErr MojLogEngine::configure(const MojObject& conf, const MojChar* name)
{
MojAssert(name);
MojErr err = MojErrNone;
MojLogger::Level defaultLevel = MojLogger::LevelDefault;
MojAutoPtr<MojLogAppender> appender;
LevelMap levels;
// validate entire configuration before we apply any changes
MojObject logConf;
if (conf.get(LogKey, logConf)) {
// appender
MojObject obj;
if (logConf.get(AppenderKey, obj)) {
err = createAppender(obj, name, appender);
MojErrCheck(err);
}
// levels
if (logConf.get(LevelsKey, obj)) {
// configure loggers
MojString str;
for (MojObject::ConstIterator i = obj.begin(); i != obj.end(); ++i) {
MojLogger::Level level = MojLogger::LevelNone;
err = i.value().stringValue(str);
MojErrCheck(err);
err = MojLogger::levelFromString(str, level);
MojErrCheck(err);
if (i.key() == DefaultKey) {
defaultLevel = level;
} else {
err = levels.put(i.key(), level);
MojErrCheck(err);
}
}
}
}
// apply changes
MojThreadGuard guard(m_mutex);
// update name
err = m_name.assign(name);
MojErrCheck(err);
// update appender
updateAppender(appender);
// update levels
m_levels = levels;
m_defaultLogger.level(defaultLevel);
updateLoggers();
return MojErrNone;
}
示例12: GetObjectValue
bool MojoWhereMatcher::GetObjectValue(const MojObject& key,
const MojObject& response, MojObject& value) const
{
if (key.type() == MojObject::TypeString) {
MojString keyStr;
MojErr err = key.stringValue(keyStr);
if (err) {
throw std::runtime_error("Error attempting to retrieve key name "
"getting object value");
}
if (response.contains(keyStr)) {
return response.get(keyStr, value);
} else {
return false;
}
} else if (key.type() == MojObject::TypeArray) {
MojObject cur = response;
for (MojObject::ConstArrayIterator iter = key.arrayBegin();
iter != key.arrayEnd(); ++iter) {
const MojObject& keyObj = *iter;
if (keyObj.type() != MojObject::TypeString) {
throw std::runtime_error("Non-string found in property "
"specifiction array");
}
MojString keyStr;
MojErr err = keyObj.stringValue(keyStr);
if (err) {
throw std::runtime_error("Failed to access lookup key");
}
if (cur.contains(keyStr)) {
MojObject tmp;
if (!cur.get(keyStr, tmp)) {
return false;
} else {
cur = tmp;
}
} else {
return false;
}
}
value = cur;
return true;
} else {
throw std::runtime_error("Property specification must be the "
"property name or array of property names");
}
}
示例13: handleMerge
MojErr MojDbServiceHandler::handleMerge(MojServiceMessage* msg, MojObject& payload, MojDbReq& req)
{
MojAssert(msg);
MojLogTrace(s_log);
MojErr err = MojErrNone;
MojUInt32 count = 0;
MojObject obj;
if (payload.get(MojDbServiceDefs::ObjectsKey, obj)) {
if (payload.contains(MojDbServiceDefs::QueryKey))
MojErrThrowMsg(MojErrInvalidArg, _T("db: cannot have both an objects param and a query param"));
MojObject::ArrayIterator begin;
bool ignoreM = false;
payload.get(MojDbServiceDefs::IgnoreMissingKey, ignoreM);
MojUInt32 mflags = MojDb::FlagNone;
if (ignoreM)
mflags = mflags | MojDb::FlagIgnoreMissing;
err = obj.arrayBegin(begin);
MojErrCheck(err);
MojObject::ConstArrayIterator end = obj.arrayEnd();
err = m_db.merge(begin, end, mflags, req);
MojErrCheck(err);
err = formatPut(msg, begin, end); // TO DO: we need to drop non-existing objects
MojErrCheck(err);
}
else if (payload.get(MojDbServiceDefs::QueryKey, obj)) {
MojObject props;
err = payload.getRequired(MojDbServiceDefs::PropsKey, props);
MojErrCheck(err);
bool ignoreM = false;
if (payload.get(MojDbServiceDefs::IgnoreMissingKey, ignoreM))
MojErrThrowMsg(MojErrInvalidArg, _T("db: ignoreMissing - invalid option for merge query"));
MojDbQuery query;
err = query.fromObject(obj);
MojErrCheck(err);
MojUInt32 queryCount = 0;
err = m_db.merge(query, props, queryCount, MojDb::FlagNone, req);
MojErrCheck(err);
count += queryCount;
err = formatCount(msg, count);
MojErrCheck(err);
}
else {
MojErrThrowMsg(MojErrInvalidArg, _T("db: either objects or query param required for merge"));
}
return MojErrNone;
}
示例14: ValidateAccount
MojErr PopBusDispatcher::ValidateAccount(MojServiceMessage* msg, MojObject& payload)
{
// cancel shut down if it is in shut down state
CancelShutdown();
MojLogTrace(s_log);
boost::shared_ptr<PopAccount> account(new PopAccount());
try {
MojObject accountId;
if(payload.get("accountId", accountId)) {
MojRefCountedPtr<FirstUseValidator> firstUseValidator(new FirstUseValidator(*this, m_dbInterface, accountId, msg, payload));
firstUseValidator->Validate();
} else {
// NOT First Use
boost::shared_ptr<PopAccount> account(new PopAccount());
GetAccountFromPayload(account, payload);
ValidatePopAccount(account, msg, payload);
}
} catch (const std::exception& e) {
MojErrThrowMsg(MojErrInternal, "%s", e.what());
}
return MojErrNone;
}
示例15: getAccountConfigResult
MojErr OnEnabledHandler::getAccountConfigResult(MojObject& payload, MojErr err)
{
MojLogTrace(IMServiceApp::s_log);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogCritical(IMServiceApp::s_log, "getAccountConfig failed: error %d - %s", err, error.data());
}
else
{
MojObject results;
payload.get("results", results);
if (!results.empty())
{
m_config = *results.arrayBegin();
}
}
if (m_enable) {
err = accountEnabled();
} else {
err = accountDisabled();
}
return err;
}