Variant ClientBase::syncCall(ObjectID id, const string &name, const Variant &args, bool withResult) { LOG_DEBUG_FMT(0, "Call <object id %d>.%s(%s)", id % name % args.repr()); if(withResult) { sendCallRequest(RT_CALL_FUNC, getNextRequestID(), id, name, args); //return recvAnswer(); } else { sendCallRequest(RT_CALL_PROC, getNextRequestID(), id, name, args); } return Variant(); }
const TopRegionRequest* BasicMapRequester::getTopRegionRequest() { // have old top region request? if ( m_topRegionRequest.get() != NULL ) { return m_topRegionRequest.get(); } // No old top region request, request a new one TopRegionRequest* topRequest = new TopRegionRequest( getNextRequestID() ); putRequest( topRequest ); if ( topRequest->getStatus() == StringTable::OK ) { if ( topRequest->isCacheable() ) { m_topRegionRequest.reset( topRequest ); } else { // this will leak memory, but it's better than returning NULL // FIXME somehow. /* delete topRequest; topRequest = NULL; */ mc2log << warn << "[PTG] TopRegionRequest not cacheable" << endl; } } else { delete topRequest; topRequest = NULL; mc2log << warn << "[PTG] TopRegionRequest not OK, returning NULL" << endl; } return topRequest; }
Variant ClientBase::destroyObject(ObjectID id) { if(id == 0) return Variant(); std::ostringstream stream; unsigned int size = 0; char type = RT_DELOBJ; unsigned int requestID = getNextRequestID(); stream.write((const char*)&size, sizeof(size)); stream.write(&type, sizeof(type)); stream.write((const char*)&requestID, sizeof(requestID)); stream.write((const char*)&id, sizeof(id)); return sendBuffer(type, requestID, stream); }
Variant ClientBase::asyncCall(ObjectID id, const string &name, const Variant &args, bool withResult, float timeout, FutureResultPtr &written) { LOG_DEBUG_FMT(0, "Async call <object id %d>.%s(%s)", id % name % args.repr()); unsigned int requestID = getNextRequestID(); if(withResult) { FutureResultPtr future(new FutureResult); m_callbacks[requestID] = future; written = sendCallRequest(RT_CALL_FUNC, requestID, id, name, args).toFuture(); return future; } else { written = sendCallRequest(RT_CALL_PROC, requestID, id, name, args).toFuture(); } return Variant(); }
bool XMLParserThread::xmlParseSMSFormatRequest( DOMNode* cur, DOMNode* out, DOMDocument* reply, bool indent ) try { bool ok = true; int indentLevel = 1; MC2String indentStr( indentLevel*3, ' ' ); indentStr.insert( 0, "\n" ); XStr XindentStr( indentStr.c_str() ); bool smsMessage = false; bool routeMessage = false; bool wayfinderRouteSMS = false; bool wayfinderDestinationSMS = false; bool wayfinderFavouriteSMS = false; char* smsMessageText = NULL; char* phoneModelName = NULL; char* phoneManufacturerName = NULL; uint32 routeID = 0; uint32 routeCreateTime = 0; StringTable::languageCode language = StringTable::ENGLISH; char* signature = NULL; char* originString = NULL; char* originLocationString = NULL; char* destinationString = NULL; char* destinationLocationString = NULL; CellularPhoneModel* model = NULL; // For routeMessage bool wapLink = false; // For routeMessage int32 wayfinderSMSVersion = MAX_INT32; int32 wayfinderOriginLat = MAX_INT32; int32 wayfinderOriginLon = MAX_INT32; int32 wayfinderDestinationLat = MAX_INT32; int32 wayfinderDestinationLon = MAX_INT32; MC2String wayfinderOriginDescription; MC2String wayfinderDestinationDescription; MC2String errorCode = "-1"; MC2String errorMessage = "Failed to handle request."; int32 wayfinderFavouriteLat; int32 wayfinderFavouriteLon; MC2String wayfinderFavouriteName; MC2String wayfinderFavouriteShortName; MC2String wayfinderFavouriteDescription; MC2String wayfinderFavouriteCategory; MC2String wayfinderFavouriteMapIconName; // Create sms_format_reply element DOMElement* sms_format_reply = reply->createElement( X( "sms_format_reply" ) ); // Transaction ID sms_format_reply->setAttribute( X( "transaction_id" ), cur->getAttributes()->getNamedItem( X( "transaction_id" ) )->getNodeValue() ); out->appendChild( sms_format_reply ); if ( indent ) { // Newline out->insertBefore( reply->createTextNode( XindentStr.XMLStr() ), sms_format_reply ); } // Look for Wayfinder sms version DOMNamedNodeMap* attributes = cur->getAttributes(); DOMNode* attribute; for ( uint32 i = 0 ; i < attributes->getLength() ; i++ ) { attribute = attributes->item( i ); if ( XMLString::equals( attribute->getNodeName(), "wayfinder_sms_version" ) ) { MC2String tmpStr = XMLUtility::transcodefrom( attribute->getNodeValue() ); wayfinderSMSVersion = atoi( tmpStr.c_str() ); } } XMLSMSCommon::InviteData inviteData; // for invite_sms XMLSMSCommon::PlaceSMSData placeData; // for place_sms for ( DOMNode* child = cur->getFirstChild(); child != NULL && ok; child = child->getNextSibling() ) { if ( child->getNodeType() != DOMNode::ELEMENT_NODE ) { continue; } // See if the element is a known type if ( XMLString::equals( child->getNodeName(), "smsmessage" ) ) { smsMessageText = XMLUtility::getChildTextValue( child ); smsMessage = true; } else if ( XMLString::equals( child->getNodeName(), "phone_manufacturer" ) ) { phoneManufacturerName = XMLUtility::getChildTextValue( child ); } else if ( XMLString::equals( child->getNodeName(), "phone_model" ) ) { phoneModelName = XMLUtility::getChildTextValue( child ); } else if ( XMLString::equals( child->getNodeName(), "route_sms_message" ) ) { routeMessage = xmlParseSendSMSRequestRouteSMSMessage( child, model, wapLink ); } else if ( XMLString::equals( child->getNodeName(), "route_message_data" ) ) { routeMessage = XMLSMSCommon:: xmlParseSendSMSRequestRouteMessageData( child, routeID, routeCreateTime, language, signature, originString, originLocationString, destinationString, destinationLocationString ); } else if( XMLString::equals( child->getNodeName(), "wayfinder_route_sms" ) ) { wayfinderRouteSMS = XMLSMSCommon:: xmlParseWayfinderSMS( child, signature, wayfinderOriginLat, wayfinderOriginLon, wayfinderOriginDescription, wayfinderDestinationLat, wayfinderDestinationLon, wayfinderDestinationDescription, errorCode, errorMessage ); if ( ! wayfinderRouteSMS ) { ok = false; // errorCode and errorMessage is set by // xmlParseWayfinderSMS mc2log << warn << "XMLParserThread::" << "xmlParseSendSMSRequest failed to parse " << "wayfinder_route_sms." << endl; } } else if ( XMLString::equals( child->getNodeName(), "wayfinder_destination_sms" ) ) { wayfinderDestinationSMS = XMLSMSCommon:: xmlParseWayfinderSMS( child, signature, wayfinderOriginLat, wayfinderOriginLon, wayfinderOriginDescription, wayfinderDestinationLat, wayfinderDestinationLon, wayfinderDestinationDescription, errorCode, errorMessage ); if ( ! wayfinderDestinationSMS ) { ok = false; // errorCode and errorMessage is set by // xmlParseWayfinderSMS mc2log << warn << "XMLParserThread::" << "xmlParseSendSMSRequest failed to parse " << "wayfinder_destination_sms." << endl; } } else if( XMLString::equals( child->getNodeName(), "wayfinder_favourite_sms" ) ) { wayfinderFavouriteSMS = XMLSMSCommon:: xmlParseWayfinderFavouriteSMS( child, signature, wayfinderFavouriteLat, wayfinderFavouriteLon, wayfinderFavouriteName, wayfinderFavouriteShortName, wayfinderFavouriteDescription, wayfinderFavouriteCategory, wayfinderFavouriteMapIconName, errorCode, errorMessage ); if( ! wayfinderFavouriteSMS ) { // errorCode and errorMessage is set by // xmlParseWayfinderFavouriteSMS mc2log << warn << "XMLParserThread::" << "xmlParseSMSFormatRequest failed to parse " << "wayfinder_favourite_sms." << endl; } } else if ( XMLString::equals( child->getNodeName(), "invite_sms" ) ) { XMLTool::getAttribValue( inviteData.m_type, "type", child ); XMLTool::getNodeValue( inviteData.m_name, "name", child ); } else if ( XMLString::equals( child->getNodeName(), "place_sms" ) ) { ok = parsePlaceSMS( placeData, child, errorCode, errorMessage ); } else { mc2log << warn << "XMLParserThread::" "xmlParseSMSFormatRequest " "odd Element in sms_format_request element: " << child->getNodeName() << endl; } } // Handle request if ( ok ) { // The smses StringVector* smsVector = new StringVector(); if ( smsMessage ) { // ExpandStringItemVector? ok = false; errorMessage = "Formating of smsmessage is not yet supported."; } else if ( routeMessage ) { if ( !wapLink ) { ok = handleRouteMessage( this, routeID, routeCreateTime, language, smsVector, model, signature, errorMessage ); } else { ok = handleWAPLinkSMS( this, routeID, routeCreateTime, language, smsVector, model, signature, errorMessage ); } if ( ok ) { mc2log << info << "XMLParserThread::xmlParseSMSFormatRequest "; if ( !wapLink ) { mc2log << "routeID " << routeID << " routeCreateTime " << routeCreateTime; } else { mc2log << "wapLink true"; } mc2log << " signature " << signature << " model " << model->getName() << " nbrSMSes " << smsVector->getSize() << endl; // Add smses XMLSMSCommon::appendSMSList( sms_format_reply, reply, smsVector, indentLevel + 1, indent ); } // Not ok handled below } else if ( wayfinderDestinationSMS || wayfinderRouteSMS ) { // Make sms data WayfinderSMSRequest* wayReq = new WayfinderSMSRequest( getNextRequestID() ); MC2Coordinate origin( wayfinderOriginLat, wayfinderOriginLon ); MC2Coordinate dest( wayfinderDestinationLat, wayfinderDestinationLon ); wayReq->addMessage( "DUMMY", "NO_WAY", origin, wayfinderOriginDescription.c_str(), dest, wayfinderDestinationDescription.c_str(), signature, wayfinderSMSVersion ); smsVector->addLast( StringUtility::newStrDup( const_cast<char*>( wayReq->getLastDestinationMessage() ) ) ); // Add sms XMLSMSCommon::appendSMSList( sms_format_reply, reply, smsVector, indentLevel + 1, indent ); delete wayReq; } else if( wayfinderFavouriteSMS ) { // Make sms data WayfinderSMSRequest* wayReq = new WayfinderSMSRequest( getNextRequestID() ); MC2Coordinate coord( wayfinderFavouriteLat, wayfinderFavouriteLon ); wayReq->addFavouriteMessage( "DUMMY", "NO_WAY", coord, wayfinderFavouriteName, wayfinderFavouriteShortName, wayfinderFavouriteDescription, wayfinderFavouriteCategory, wayfinderFavouriteMapIconName, signature, wayfinderSMSVersion ); smsVector->addLast( StringUtility::newStrDup( const_cast<char*>( wayReq->getLastDestinationMessage() ) ) ); // Add sms XMLSMSCommon::appendSMSList( sms_format_reply, reply, smsVector, indentLevel + 1, indent ); delete wayReq; } else if ( !inviteData.m_type.empty() ) { XMLSMSCommon:: composeInviteSMS( sms_format_reply, reply, indentLevel + 1, indent, getCurrentUser(), inviteData ); } else if ( ! placeData.m_type.empty() ) { XMLSMSCommon:: composePlaceSMS( *this, sms_format_reply, reply, indentLevel + 1, indent, getCurrentUser(), placeData ); } else { // Couldn't get all needed indata ok = false; errorMessage = "Couldn't get all needed indata."; } if ( ok ) { mc2log << info << "SMSFormat: OK " << smsVector->getSize() << " SMSes "; if ( smsVector->getSize() > 0 ) { mc2log << "Last " << smsVector->getElementAt( 0 ); } mc2log << endl; } // Error printed below smsVector->deleteAllObjs(); delete smsVector; } // Not ok handled below if ( ! ok ) { mc2log << info << "SMSFormat: Error " << errorCode << "," << errorMessage << endl; // Error XMLServerUtility:: appendStatusNodes( sms_format_reply, reply, indentLevel + 1, indent, errorCode.c_str(), errorMessage.c_str() ); // Error handled ok = true; } if ( indent ) { // Newline and indent before end sms_format_reply tag sms_format_reply->appendChild( reply->createTextNode( XindentStr.XMLStr() ) ); } delete [] smsMessageText; delete [] phoneModelName; delete [] phoneManufacturerName; delete [] signature; delete [] originString; delete [] originLocationString; delete [] destinationString; delete [] destinationLocationString; delete model; return ok; } catch ( const XMLTool::Exception& e ) { return false; }