ErrorPtr P44JsonApiRequest::sendResult(ApiValuePtr aResult) { LOG(LOG_DEBUG, "cfg <- vdcd (JSON) result sent: result=%s", aResult ? aResult->description().c_str() : "<none>"); JsonApiValuePtr result = boost::dynamic_pointer_cast<JsonApiValue>(aResult); if (result) { P44VdcHost::sendCfgApiResponse(jsonComm, result->jsonObject(), ErrorPtr()); } else { // always return SOMETHING P44VdcHost::sendCfgApiResponse(jsonComm, JsonObject::newNull(), ErrorPtr()); } return ErrorPtr(); }
ErrorPtr VdcJsonApiConnection::sendRequest(const string &aMethod, ApiValuePtr aParams, VdcApiResponseCB aResponseHandler) { JsonApiValuePtr params = boost::dynamic_pointer_cast<JsonApiValue>(aParams); ErrorPtr err; if (aResponseHandler) { // method call expecting response err = jsonRpcComm->sendRequest(aMethod.c_str(), params->jsonObject(), boost::bind(&VdcJsonApiConnection::jsonResponseHandler, this, aResponseHandler, _1, _2, _3)); LOG(LOG_INFO,"vdSM <- vDC (JSON) method call sent: requestid='%d', method='%s', params=%s\n", jsonRpcComm->lastRequestId(), aMethod.c_str(), aParams ? aParams->description().c_str() : "<none>"); } else { // notification err = jsonRpcComm->sendRequest(aMethod.c_str(), params->jsonObject(), NULL); LOG(LOG_INFO,"vdSM <- vDC (JSON) notification sent: method='%s', params=%s\n", aMethod.c_str(), aParams ? aParams->description().c_str() : "<none>"); } return err; }
ErrorPtr VdcJsonApiRequest::sendError(uint32_t aErrorCode, string aErrorMessage, ApiValuePtr aErrorData) { LOG(LOG_INFO,"vdSM <- vDC (JSON) error sent: requestid='%s', error=%d (%s)\n", requestId().c_str(), aErrorCode, aErrorMessage.c_str()); JsonApiValuePtr errorData; if (aErrorData) errorData = boost::dynamic_pointer_cast<JsonApiValue>(aErrorData); return jsonConnection->jsonRpcComm->sendError(requestId().c_str(), aErrorCode, aErrorMessage.size()>0 ? aErrorMessage.c_str() : NULL, errorData ? errorData->jsonObject() : JsonObjectPtr()); }
ErrorPtr VdcJsonApiRequest::sendResult(ApiValuePtr aResult) { LOG(LOG_INFO,"vdSM <- vDC (JSON) result sent: requestid='%s', result=%s\n", requestId().c_str(), aResult ? aResult->description().c_str() : "<none>"); JsonApiValuePtr result = boost::dynamic_pointer_cast<JsonApiValue>(aResult); return jsonConnection->jsonRpcComm->sendResult(requestId().c_str(), result ? result->jsonObject() : NULL); }