本文整理汇总了C++中HeaderOptions::end方法的典型用法代码示例。如果您正苦于以下问题:C++ HeaderOptions::end方法的具体用法?C++ HeaderOptions::end怎么用?C++ HeaderOptions::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HeaderOptions
的用法示例。
在下文中一共展示了HeaderOptions::end方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printHeaderOptions
//Function to print the headerOptions received from the server
void printHeaderOptions(const HeaderOptions& headerOptions)
{
for (auto it = headerOptions.begin(); it != headerOptions.end(); ++it)
{
if(it->getOptionID() == API_VERSION)
{
std::cout << "Server API version in GET response: " <<
it->getOptionData() << std::endl;
}
}
}
示例2: assembleHeaderOptions
void InProcClientWrapper::assembleHeaderOptions(OCHeaderOption options[],
const HeaderOptions& headerOptions)
{
int i = 0;
for (auto it=headerOptions.begin(); it != headerOptions.end(); ++it)
{
options[i].protocolID = OC_COAP_ID;
options[i].optionID = static_cast<uint16_t>(it->getOptionID());
options[i].optionLength = (it->getOptionData()).length() + 1;
memcpy(options[i].optionData, (it->getOptionData()).c_str(),
(it->getOptionData()).length() + 1);
i++;
}
}
示例3: sendResponse
OCStackResult InProcServerWrapper::sendResponse(
const std::shared_ptr<OCResourceResponse> pResponse)
{
auto cLock = m_csdkLock.lock();
OCStackResult result = OC_STACK_ERROR;
if(!pResponse)
{
result = OC_STACK_MALFORMED_RESPONSE;
throw OCException(OC::Exception::STR_NULL_RESPONSE, OC_STACK_MALFORMED_RESPONSE);
}
else
{
OCEntityHandlerResponse response;
// OCRepPayload* payLoad = pResponse->getPayload();
HeaderOptions serverHeaderOptions = pResponse->getHeaderOptions();
response.requestHandle = pResponse->getRequestHandle();
response.resourceHandle = pResponse->getResourceHandle();
response.ehResult = pResponse->getResponseResult();
response.payload = reinterpret_cast<OCPayload*>(pResponse->getPayload());
response.persistentBufferFlag = 0;
response.numSendVendorSpecificHeaderOptions = serverHeaderOptions.size();
int i = 0;
for (auto it=serverHeaderOptions.begin(); it != serverHeaderOptions.end(); ++it)
{
response.sendVendorSpecificHeaderOptions[i].protocolID = OC_COAP_ID;
response.sendVendorSpecificHeaderOptions[i].optionID =
static_cast<uint16_t>(it->getOptionID());
response.sendVendorSpecificHeaderOptions[i].optionLength =
(it->getOptionData()).length() + 1;
std::string optionData = it->getOptionData();
std::copy(optionData.begin(),
optionData.end(),
response.sendVendorSpecificHeaderOptions[i].optionData);
response.sendVendorSpecificHeaderOptions[i].optionData[it->getOptionData().length()]
= '\0';
i++;
}
if(OC_EH_RESOURCE_CREATED == response.ehResult)
{
pResponse->getNewResourceUri().copy(response.resourceUri,
sizeof (response.resourceUri) - 1);
response.resourceUri[pResponse->getNewResourceUri().length()] = '\0';
}
if(cLock)
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
result = OCDoResponse(&response);
}
else
{
OICFree(response.payload);
result = OC_STACK_ERROR;
}
if(result != OC_STACK_OK)
{
oclog() << "Error sending response\n";
}
return result;
}
}
示例4: entityHandler
virtual OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if(request)
{
// Get the header options from the request
HeaderOptions headerOptions = request->getHeaderOptions();
std::string clientAPIVersion;
std::string clientToken;
// Search the header options map and look for API version and Client token
for (auto it = headerOptions.begin(); it != headerOptions.end(); ++it)
{
uint16_t optionID = it->getOptionID();
if(optionID == API_VERSION)
{
clientAPIVersion = it->getOptionData();
std::cout << " Client API version: " << clientAPIVersion << std::endl;
}
else if(optionID == TOKEN)
{
clientToken = it->getOptionData();
std::cout << " Client token: " << clientToken << std::endl;
}
else
{
std::cout << " Invalid header option " << std::endl;
}
}
// In this case Server entity handler verifies API version
// and client token. If they are valid, client requests are handled.
if(clientAPIVersion == FRIDGE_CLIENT_API_VERSION && clientToken == FRIDGE_CLIENT_TOKEN)
{
HeaderOptions serverHeaderOptions;
try
{
// Set API version from server side
HeaderOption::OCHeaderOption apiVersion(API_VERSION, FRIDGE_CLIENT_API_VERSION);
serverHeaderOptions.push_back(apiVersion);
}
catch(OCException& e)
{
std::cout << "Error creating HeaderOption in server: " << e.what() << std::endl;
}
if(request->getRequestHandlerFlag() == RequestHandlerFlag::RequestFlag)
{
auto pResponse = std::make_shared<OC::OCResourceResponse>();
pResponse->setRequestHandle(request->getRequestHandle());
pResponse->setResourceHandle(request->getResourceHandle());
pResponse->setHeaderOptions(serverHeaderOptions);
if(request->getRequestType() == "GET")
{
std::cout<<"DeviceResource Get Request"<<std::endl;
pResponse->setErrorCode(200);
pResponse->setResponseResult(OC_EH_OK);
pResponse->setResourceRepresentation(get(), "");
if(OC_STACK_OK == OCPlatform::sendResponse(pResponse))
{
ehResult = OC_EH_OK;
}
}
else if(request->getRequestType() == "DELETE")
{
std::cout<<"DeviceResource Delete Request"<<std::endl;
if(deleteDeviceResource() == OC_STACK_OK)
{
pResponse->setErrorCode(200);
pResponse->setResponseResult(OC_EH_RESOURCE_DELETED);
ehResult = OC_EH_OK;
}
else
{
pResponse->setResponseResult(OC_EH_ERROR);
ehResult = OC_EH_ERROR;
}
OCPlatform::sendResponse(pResponse);
}
else
{
std::cout <<"DeviceResource unsupported request type "
<< request->getRequestType() << std::endl;
pResponse->setResponseResult(OC_EH_ERROR);
OCPlatform::sendResponse(pResponse);
ehResult = OC_EH_ERROR;
}
}
else
{
std::cout << "DeviceResource unsupported request flag" <<std::endl;
}
}
else
{
std::cout << "Unsupported/invalid header options/values" << std::endl;
}
}
//.........这里部分代码省略.........