#include <stdexcept>
#include <ocstack.h>
+#include "StringConstants.h"
namespace OC
{
switch(m_reason)
{
case OC_STACK_OK:
- return "No Error";
+ return OC::InitException::NO_ERROR;
case OC_STACK_INVALID_URI:
- return "Invalid URI";
+ return OC::InitException::INVALID_URI;
case OC_STACK_INVALID_IP:
- return "Invalid IP";
+ return OC::InitException::INVALID_IP;
case OC_STACK_INVALID_PORT:
- return "Invalid Port";
+ return OC::InitException::INVALID_PORT;
case OC_STACK_INVALID_CALLBACK:
- return "Invalid Callback";
+ return OC::InitException::INVALID_CB;
case OC_STACK_INVALID_METHOD:
- return "Invalid Method";
+ return OC::InitException::INVALID_METHOD;
case OC_STACK_ERROR:
- return "General Fault";
+ return OC::InitException::GENERAL_FAULT;
default:
- return "Unknown Error";
+ return OC::InitException::UNKNOWN_ERROR;
}
}
};
}
-#endif
\ No newline at end of file
+#endif
#include "ocstack.h"
#include "OCHeaderOption.h"
#include <OCException.h>
-
+#include "StringConstants.h"
#include "oc_logger.hpp"
namespace OC
}
else
{
- throw OCException("Array type should have at least []");
+ throw OCException(OC::Exception::INVALID_ARRAY);
}
}
}
else
{
- throw OCException("Array type should have at least []");
+ throw OCException(OC::Exception::INVALID_ARRAY);
}
}
}
else
{
- throw OCException("Array type should have at least []");
+ throw OCException(OC::Exception::INVALID_ARRAY);
}
}
}
else
{
- throw OCException("Array type should have at least []");
+ throw OCException(OC::Exception::INVALID_ARRAY);
}
}
}
else
{
- throw OCException("Array type should have at least []");
+ throw OCException(OC::Exception::INVALID_ARRAY);
}
}
// TODO this expects the representation oc:{} and not oc:[{}]
// this representation is fine when setting for simple resource.
- boost::property_tree::ptree payload = root.get_child("oc", boost::property_tree::ptree());
+ boost::property_tree::ptree payload = root.get_child(OC::Key::OCKEY, boost::property_tree::ptree());
for(auto& item: payload)
{
#include <stdexcept>
#include <ocstack.h>
+#include "StringConstants.h"
namespace OC
{
if(isUriMissing())
{
- ret += "Missing URI;";
+ ret += OC::InitException::MISSING_URI;
}
if(isTypeMissing())
{
- ret += "Missing Resource Type;";
+ ret += OC::InitException::MISSING_TYPE;
}
if(isInterfaceMissing())
{
- ret += "Missing Interface;";
+ ret += OC::InitException::MISSING_INTERFACE;
}
if(isClientWrapperMissing())
{
- ret += "Missing ClientWrapper;";
+ ret += OC::InitException::MISSING_CLIENT_WRAPPER;
}
return ret.c_str();
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef _STRING_CONSTANTS_H_
+#define _STRING_CONSTANTS_H_
+
+#include <string>
+
+using namespace std;
+
+namespace OC
+{
+ namespace InitException
+ {
+ static const std::string NO_ERROR = "No Error";
+ static const std::string INVALID_URI = "Invalid URI";
+ static const std::string INVALID_PORT = "Invalid Port";
+ static const std::string INVALID_IP = "Invalid IP";
+ static const std::string INVALID_CB = "Invalid Callback";
+ static const std::string INVALID_METHOD = "Invalid Method";
+ static const std::string GENERAL_FAULT = "General Fault";
+ static const std::string UNKNOWN_ERROR = "Unknown Error";
+
+ static const std::string STACK_INIT_ERROR = "Error Initializing Stack";
+ static const std::string NOT_CONFIGURED_AS_SERVER =
+ "Cannot static construct a Server when configured as a client";
+ static const std::string INVALID_PARAM = "Invalid Param";
+ static const std::string MISSING_URI = "Missing URI;";
+ static const std::string MISSING_TYPE = "Missing Resource Type;";
+ static const std::string MISSING_INTERFACE = "Missing Interface;";
+ static const std::string MISSING_CLIENT_WRAPPER = "Missing ClientWrapper;";
+ }
+
+ namespace Exception // Not To Be Confused With 'InitException'
+ {
+ static const std::string SVCTYPE_OUTOFPROC = "ServiceType::OutOfProc";
+ static const std::string BIND_TYPE_FAILED = "Bind Type to resource failed";
+ static const std::string BIND_INTERFACE_FAILED = "Bind Interface to resource failed";
+ static const std::string START_PRESENCE_FAILED = "startPresence failed";
+ static const std::string END_PRESENCE_FAILED = "stopPresence failed";
+ static const std::string INVALID_ARRAY = "Array type should have at least []";
+ static const std::string STR_NULL_RESPONSE = "Response is NULL";
+ static const std::string STR_PAYLOAD_OVERFLOW = "Payload overflow";
+
+
+ static const std::string NO_ERROR = "No Error";
+ static const std::string RESOURCE_CREATED = "Resource Created";
+ static const std::string RESOURCE_DELETED = "Resource Deleted";
+ static const std::string INVALID_URI = "Invalid URI";
+ static const std::string INVALID_IP = "Invalid IP";
+ static const std::string INVALID_PORT = "Invalid Port";
+ static const std::string INVALID_CB = "Invalid Callback";
+ static const std::string INVALID_METHOD = "Invalid Method";
+ static const std::string INVALID_QUERY = "Invalid Query";
+ static const std::string INVALID_PARAM = "Invalid Param";
+ static const std::string INVALID_OBESERVE = "Invalid Observe Param";
+ static const std::string NO_MEMORY = "No Memory";
+ static const std::string COMM_ERROR = "Communication Error";
+ static const std::string NOT_IMPL = "Not Implemented";
+ static const std::string NOT_FOUND = "Resource Not Found";
+ static const std::string RESOURCE_ERROR = "Resource Error";
+ static const std::string SLOW_RESOURCE = "Slow Resource";
+ static const std::string NO_OBSERVERS = "No Observers";
+ static const std::string OBSV_NO_FOUND = "Stack observer not found";
+ static const std::string OBSV_NOT_ADDED = "Stack observer not added";
+ static const std::string OBSV_NOT_REMOVED = "Stack observer not removed";
+ static const std::string STACK_RESOURCE_DELETED = "The specified resource has been deleted";
+ static const std::string PRESENCE_STOPPED = "Stack presence stopped";
+ static const std::string PRESENCE_NOT_HANDLED = "Stack presence should not be handled";
+ static const std::string INVALID_OPTION = "Invalid option";
+ static const std::string GENERAL_FAULT = "General Fault";
+ static const std::string MALFORMED_STACK_RESPONSE = "Response from OC_STACK is malformed";
+ static const std::string UNKNOWN_ERROR = "Unknown Error";
+ }
+
+ namespace Error
+ {
+ static const std::string INVALID_IP = "Invalid IP";
+ }
+
+ namespace PlatformCommands
+ {
+ static const std::string GET = "GET";
+ static const std::string PUT = "PUT";
+ static const std::string POST = "POST";
+ static const std::string DELETE = "DELETE";
+ }
+
+ namespace Key
+ {
+ static const std::string OCKEY = "oc";
+ static const std::string URIKEY = "href";
+ static const std::string OBSERVABLEKEY = "obs";
+ static const std::string RESOURCETYPESKEY = "rt";
+ static const std::string INTERFACESKEY = "if";
+ static const std::string PROPERTYKEY = "prop";
+ static const std::string REPKEY = "rep";
+ }
+
+}
+
+#endif // _STRING_CONSTANTS_H_
#include <InProcClientWrapper.h>
#include <OutOfProcServerWrapper.h>
#include <InProcServerWrapper.h>
+#include "StringConstants.h"
namespace OC
{
return std::make_shared<InProcServerWrapper>(owner, csdkLock, cfg);
break;
case ServiceType::OutOfProc:
- throw OC::OCException("ServiceType::OutOfProc", OC_STACK_NOTIMPL);
+ throw OC::OCException(OC::Exception::SVCTYPE_OUTOFPROC, OC_STACK_NOTIMPL);
break;
}
return nullptr;
if(OC_STACK_OK != result)
{
- throw InitializeException("Error Initializing Stack", result);
+ throw InitializeException(OC::InitException::STACK_INIT_ERROR, result);
}
m_threadRun = true;
}
else
{
- return "INVALID IP";
+ return OC::Error::INVALID_IP;
}
}
};
- const std::string URIKEY = "href";
- const std::string OBSERVABLEKEY = "obs";
- const std::string RESOURCETYPESKEY= "rt";
- const std::string INTERFACESKEY = "if";
- const std::string PROPERTYKEY = "prop";
- const std::string REPKEY = "rep";
-
std::shared_ptr<OCResource> InProcClientWrapper::parseOCResource(
IClientWrapper::Ptr clientWrapper, const std::string& host,
const boost::property_tree::ptree resourceNode)
{
- std::string uri = resourceNode.get<std::string>(URIKEY, "");
- bool obs = resourceNode.get<int>(OBSERVABLEKEY,0) == 1;
+ std::string uri = resourceNode.get<std::string>(OC::Key::URIKEY, "");
+ bool obs = resourceNode.get<int>(OC::Key::OBSERVABLEKEY,0) == 1;
std::vector<std::string> rTs;
std::vector<std::string> ifaces;
boost::property_tree::ptree properties =
- resourceNode.get_child(PROPERTYKEY, boost::property_tree::ptree());
+ resourceNode.get_child(OC::Key::INTERFACESKEY, boost::property_tree::ptree());
boost::property_tree::ptree rT =
- properties.get_child(RESOURCETYPESKEY, boost::property_tree::ptree());
+ properties.get_child(OC::Key::RESOURCETYPESKEY, boost::property_tree::ptree());
for(auto itr : rT)
{
rTs.push_back(itr.second.data());
}
boost::property_tree::ptree iF =
- properties.get_child(INTERFACESKEY, boost::property_tree::ptree());
+ properties.get_child(OC::Key::INTERFACESKEY, boost::property_tree::ptree());
for(auto itr : iF)
{
ifaces.push_back(itr.second.data());
{
return OCRepresentation();
}
- boost::property_tree::ptree payload = root.get_child("oc", boost::property_tree::ptree());
+ boost::property_tree::ptree payload = root.get_child(OC::Key::OCKEY, boost::property_tree::ptree());
OCRepresentation root_resource;
std::vector<OCRepresentation> children;
bool isRoot = true;
try
{
auto resourceNode = payloadItr.second;
- std::string uri = resourceNode.get<std::string>(URIKEY, "");
+ std::string uri = resourceNode.get<std::string>(OC::Key::URIKEY, "");
if (isRoot)
{
child.setUri(uri);
}
- if( resourceNode.count(PROPERTYKEY) != 0 )
+ if( resourceNode.count(OC::Key::INTERFACESKEY) != 0 )
{
std::vector<std::string> rTs;
std::vector<std::string> ifaces;
boost::property_tree::ptree properties =
- resourceNode.get_child(PROPERTYKEY, boost::property_tree::ptree());
+ resourceNode.get_child(OC::Key::INTERFACESKEY, boost::property_tree::ptree());
boost::property_tree::ptree rT =
- properties.get_child(RESOURCETYPESKEY, boost::property_tree::ptree());
+ properties.get_child(OC::Key::RESOURCETYPESKEY, boost::property_tree::ptree());
for(auto itr : rT)
{
rTs.push_back(itr.second.data());
}
boost::property_tree::ptree iF =
- properties.get_child(INTERFACESKEY, boost::property_tree::ptree());
+ properties.get_child(OC::Key::INTERFACESKEY, boost::property_tree::ptree());
for(auto itr : iF)
{
ifaces.push_back(itr.second.data());
}
}
- if( resourceNode.count(REPKEY) != 0 )
+ if( resourceNode.count(OC::Key::INTERFACESKEY) != 0 )
{
boost::property_tree::ptree rep =
- resourceNode.get_child(REPKEY, boost::property_tree::ptree());
+ resourceNode.get_child(OC::Key::INTERFACESKEY, boost::property_tree::ptree());
AttributeMap attrs;
for( auto item : rep)
{
if(OC_REST_GET == entityHandlerRequest->method)
{
// TODO Why strings : "GET"??
- pRequest->setRequestType("GET");
+ pRequest->setRequestType(OC::PlatformCommands::GET);
}
else if(OC_REST_PUT == entityHandlerRequest->method)
{
- pRequest->setRequestType("PUT");
+ pRequest->setRequestType(OC::PlatformCommands::PUT);
pRequest->setPayload(std::string(reinterpret_cast<const char*>
(entityHandlerRequest->reqJSONPayload)));
}
else if(OC_REST_POST == entityHandlerRequest->method)
{
- pRequest->setRequestType("POST");
+ pRequest->setRequestType(OC::PlatformCommands::POST);
pRequest->setPayload(std::string(reinterpret_cast<const char*>
(entityHandlerRequest->reqJSONPayload)));
}
}
else
{
- throw OCException("Response is NULL", OC_STACK_MALFORMED_RESPONSE);
+ throw OCException(OC::Exception::STR_NULL_RESPONSE, OC_STACK_MALFORMED_RESPONSE);
}
if (payLoad.size() < entityHandlerRequest->resJSONPayloadLen)
}
else
{
- throw OCException("Payload overflow", OC_STACK_MALFORMED_RESPONSE);
+ throw OCException(OC::Exception::STR_PAYLOAD_OVERFLOW, OC_STACK_MALFORMED_RESPONSE);
}
}
}
else
{
- throw InitializeException("Cannot construct a Server when configured as a client",
+ throw InitializeException(OC::InitException::NOT_CONFIGURED_AS_SERVER,
OC_STACK_INVALID_PARAM);
}
if(OC_STACK_OK != result)
{
- throw InitializeException("Error Initializing Stack", result);
+ throw InitializeException(OC::InitException::STACK_INIT_ERROR, result);
}
m_threadRun = true;
if (result != OC_STACK_OK)
{
- throw OCException("Bind Type to resource failed", result);
+ throw OCException(OC::Exception::BIND_TYPE_FAILED, result);
}
return result;
}
if (result != OC_STACK_OK)
{
- throw OCException("Bind Interface to resource failed", result);
+ throw OCException(OC::Exception::BIND_INTERFACE_FAILED, result);
}
return result;
}
if(result != OC_STACK_OK)
{
- throw OCException("startPresence failed", result);
+ throw OCException(OC::Exception::START_PRESENCE_FAILED, result);
}
return result;
}
if(result != OC_STACK_OK)
{
- throw OCException("stopPresence failed", result);
+ throw OCException(OC::Exception::END_PRESENCE_FAILED, result);
}
return result;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "OCException.h"
+#include "StringConstants.h"
std::string OC::OCException::reason(const OCStackResult sr)
{
switch(sr)
{
case OC_STACK_OK:
- return "No Error";
+ return OC::Exception::NO_ERROR;
case OC_STACK_RESOURCE_CREATED:
- return "Resource Created";
+ return OC::Exception::RESOURCE_CREATED;
case OC_STACK_RESOURCE_DELETED:
- return "Resource Deleted";
+ return OC::Exception::RESOURCE_DELETED;
case OC_STACK_INVALID_URI:
- return "Invalid URI";
+ return OC::Exception::INVALID_URI;
case OC_STACK_INVALID_IP:
- return "Invalid IP";
+ return OC::Exception::INVALID_IP;
case OC_STACK_INVALID_PORT:
- return "Invalid Port";
+ return OC::Exception::INVALID_PORT;
case OC_STACK_INVALID_CALLBACK:
- return "Invalid Callback";
+ return OC::Exception::INVALID_CB;
case OC_STACK_INVALID_METHOD:
- return "Invalid Method";
+ return OC::Exception::INVALID_METHOD;
case OC_STACK_INVALID_QUERY:
- return "Invalid Query";
+ return OC::Exception::INVALID_QUERY;
case OC_STACK_INVALID_PARAM:
- return "Invalid Parameter";
+ return OC::Exception::INVALID_PARAM;
case OC_STACK_INVALID_OBSERVE_PARAM:
- return "Invalid Observe Parameter";
+ return OC::Exception::INVALID_OBESERVE;
case OC_STACK_NO_MEMORY:
- return "No Memory";
+ return OC::Exception::NO_MEMORY;
case OC_STACK_COMM_ERROR:
- return "Communication Error";
+ return OC::Exception::COMM_ERROR;
case OC_STACK_NOTIMPL:
- return "Not Implemented";
+ return OC::Exception::NOT_IMPL;
case OC_STACK_NO_RESOURCE:
- return "Resource Not Found";
+ return OC::Exception::NOT_FOUND;
case OC_STACK_RESOURCE_ERROR:
- return "Resource Error";
+ return OC::Exception::RESOURCE_ERROR;
case OC_STACK_SLOW_RESOURCE:
- return "Slow Resource";
+ return OC::Exception::SLOW_RESOURCE;
case OC_STACK_NO_OBSERVERS:
- return "No Observers";
- case OC_STACK_OBSERVER_NOT_FOUND:
- return "Stack observer not found";
- case OC_STACK_OBSERVER_NOT_ADDED:
- return "Stack observer not added";
- case OC_STACK_OBSERVER_NOT_REMOVED:
- return "Stack observer not removed";
+ return OC::Exception::NO_OBSERVERS;
+ case OC_STACK_OBSERVER_NOT_FOUND:
+ return OC::Exception::OBSV_NO_FOUND;
+ case OC_STACK_OBSERVER_NOT_ADDED:
+ return OC::Exception::OBSV_NOT_ADDED;
+ case OC_STACK_OBSERVER_NOT_REMOVED:
+ return OC::Exception::OBSV_NOT_REMOVED;
#ifdef WITH_PRESENCE
- case OC_STACK_PRESENCE_STOPPED:
- return "Stack presence stopped";
- case OC_STACK_PRESENCE_DO_NOT_HANDLE:
- return "Stack presence should not be handled";
+ case OC_STACK_PRESENCE_STOPPED:
+ return OC::Exception::PRESENCE_STOPPED;
+ case OC_STACK_PRESENCE_DO_NOT_HANDLE:
+ return OC::Exception::PRESENCE_NOT_HANDLED;
#endif
- case OC_STACK_INVALID_OPTION:
- return "Invalid option";
- case OC_STACK_MALFORMED_RESPONSE:
- return "Malformed response";
- case OC_STACK_ERROR:
- return "General Fault";
+ case OC_STACK_INVALID_OPTION:
+ return OC::Exception::INVALID_OPTION;
+ case OC_STACK_MALFORMED_RESPONSE:
+ return OC::Exception::MALFORMED_STACK_RESPONSE;
+ case OC_STACK_ERROR:
+ return OC::Exception::GENERAL_FAULT;
}
- return "Unknown Error";
+ return OC::Exception::UNKNOWN_ERROR;
}
if(!resourceType.empty())
{
- mapCpy["rt"]=resourceType;
+ mapCpy[OC::Key::RESOURCETYPESKEY]=resourceType;
}
if(!resourceInterface.empty())
{
- mapCpy["if"]= resourceInterface;
+ mapCpy[OC::Key::INTERFACESKEY]= resourceInterface;
}
return result_guard(get(mapCpy, attributeHandler, QoS));
if(!resourceType.empty())
{
- mapCpy["rt"]=resourceType;
+ mapCpy[OC::Key::RESOURCETYPESKEY]=resourceType;
}
if(!resourceInterface.empty())
{
- mapCpy["if"]=resourceInterface;
+ mapCpy[OC::Key::INTERFACESKEY]=resourceInterface;
}
return result_guard(put(rep, mapCpy, attributeHandler, QoS));
if(!resourceType.empty())
{
- mapCpy["rt"]=resourceType;
+ mapCpy[OC::Key::RESOURCETYPESKEY]=resourceType;
}
if(!resourceInterface.empty())
{
- mapCpy["if"]=resourceInterface;
+ mapCpy[OC::Key::INTERFACESKEY]=resourceInterface;
}
return result_guard(post(rep, mapCpy, attributeHandler, QoS));