examples: liboc.a
cd examples && $(MAKE) apps "BUILD=$(BUILD)"
-liboc.a: OCPlatform_impl.o OCPlatform.o OCResource.o OCException.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o OCRepresentation.o
- ar -cvq $(OBJ_DIR)/liboc.a $(OBJ_DIR)/OCPlatform_impl.o $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCException.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o $(OBJ_DIR)/OCRepresentation.o
+liboc.a: OCPlatform_impl.o OCPlatform.o OCResource.o OCException.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o OCRepresentation.o OCResourceRequest.o
+ ar -cvq $(OBJ_DIR)/liboc.a $(OBJ_DIR)/OCPlatform_impl.o $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCException.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o $(OBJ_DIR)/OCRepresentation.o $(OBJ_DIR)/OCResourceRequest.o
OCPlatform_impl.o: src/OCPlatform_impl.cpp
$(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/OCPlatform_impl.cpp $(CXX_INC)
InProcClientWrapper.o: src/InProcClientWrapper.cpp
$(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/InProcClientWrapper.cpp $(CXX_INC)
+OCResourceRequest.o: src/OCResourceRequest.cpp
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/OCResourceRequest.cpp $(CXX_INC)
+
clean: clean_legacy
-rm -rf release
-rm -rf debug
}
MessageContainer oc;
- oc.setJSONRepresentation(clientResponse->resJSONPayload);
+ try
+ {
+ oc.setJSONRepresentation(clientResponse->resJSONPayload);
+ }
+ catch (cereal::RapidJSONException& ex)
+ {
+ oclog() <<"RapidJSON Exception in parseGetSetCallback: "<<ex.what() <<std::endl<<
+ "Data was:"<< clientResponse->resJSONPayload<< ":" << std::flush;
+ throw OCException(OC::Exception::INVALID_REPRESENTATION, OC_STACK_INVALID_JSON);
+ }
+ catch (cereal::Exception& ex)
+ {
+ oclog() <<"Cereal Exception in parseGetSetCallback: "<<ex.what() <<std::endl<<
+ "Data was:"<< clientResponse->resJSONPayload<< ":" << std::flush;
+ throw OCException(OC::Exception::INVALID_REPRESENTATION, OC_STACK_INVALID_JSON);
+ }
std::vector<OCRepresentation>::const_iterator it = oc.representations().begin();
if(it == oc.representations().end())
ClientCallbackContext::DeviceListenContext* context =
static_cast<ClientCallbackContext::DeviceListenContext*>(ctx);
- OCRepresentation rep = parseGetSetCallback(clientResponse);
- std::thread exec(context->callback, rep);
- exec.detach();
+ try
+ {
+ OCRepresentation rep = parseGetSetCallback(clientResponse);
+ std::thread exec(context->callback, rep);
+ exec.detach();
+ }
+ catch(OC::OCException& e)
+ {
+ oclog() <<"Exception in listenDeviceCallback, ignoring response: "
+ <<e.what() <<std::flush;
+ }
return OC_STACK_KEEP_TRANSACTION;
}
OCRepresentation rep;
HeaderOptions serverHeaderOptions;
- if(clientResponse->result == OC_STACK_OK)
+ OCStackResult result = clientResponse->result;
+ if(result == OC_STACK_OK)
{
parseServerHeaderOptions(clientResponse, serverHeaderOptions);
- rep = parseGetSetCallback(clientResponse);
+ try
+ {
+ rep = parseGetSetCallback(clientResponse);
+ }
+ catch(OC::OCException& e)
+ {
+ result = e.code();
+ }
}
- std::thread exec(context->callback, serverHeaderOptions, rep, clientResponse->result);
+ std::thread exec(context->callback, serverHeaderOptions, rep, result);
exec.detach();
return OC_STACK_DELETE_TRANSACTION;
}
OCRepresentation attrs;
HeaderOptions serverHeaderOptions;
- if (OC_STACK_OK == clientResponse->result ||
- OC_STACK_RESOURCE_CREATED == clientResponse->result ||
- OC_STACK_RESOURCE_DELETED == clientResponse->result)
+ OCStackResult result = clientResponse->result;
+ if (OC_STACK_OK == result ||
+ OC_STACK_RESOURCE_CREATED == result ||
+ OC_STACK_RESOURCE_DELETED == result)
{
parseServerHeaderOptions(clientResponse, serverHeaderOptions);
- attrs = parseGetSetCallback(clientResponse);
+ try
+ {
+ attrs = parseGetSetCallback(clientResponse);
+ }
+ catch(OC::OCException& e)
+ {
+ result = e.code();
+ }
}
- std::thread exec(context->callback, serverHeaderOptions, attrs, clientResponse->result);
+ std::thread exec(context->callback, serverHeaderOptions, attrs, result);
exec.detach();
return OC_STACK_DELETE_TRANSACTION;
}
OCRepresentation attrs;
HeaderOptions serverHeaderOptions;
uint32_t sequenceNumber = clientResponse->sequenceNumber;
+ OCStackResult result = clientResponse->result;
if(clientResponse->result == OC_STACK_OK)
{
parseServerHeaderOptions(clientResponse, serverHeaderOptions);
- attrs = parseGetSetCallback(clientResponse);
+ try
+ {
+ attrs = parseGetSetCallback(clientResponse);
+ }
+ catch(OC::OCException& e)
+ {
+ result = e.code();
+ }
}
std::thread exec(context->callback, serverHeaderOptions, attrs,
- clientResponse->result, sequenceNumber);
+ result, sequenceNumber);
exec.detach();
if(sequenceNumber == OC_OBSERVE_DEREGISTER)
{
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <OCResourceRequest.h>
+
+#include <vector>
+#include <map>
+#include <cereal/cereal.hpp>
+#include <OicJsonSerializer.hpp>
+
+using namespace OC;
+using namespace std;
+
+void OCResourceRequest::setPayload(const std::string& requestPayload)
+{
+ MessageContainer info;
+
+ if(requestPayload.empty())
+ {
+ return;
+ }
+
+ try
+ {
+ info.setJSONRepresentation(requestPayload);
+ }
+ catch(cereal::RapidJSONException& ex)
+ {
+ oclog() << "RapidJSON Exception in setPayload: "<<ex.what()<<std::endl<<
+ "Data was:"<<requestPayload<<std::flush;
+ return;
+ }
+ catch(cereal::Exception& ex)
+ {
+ oclog() << "Cereal Exception in setPayload: "<<ex.what()<<std::endl<<
+ "Data was:"<<requestPayload<<std::flush;
+ return;
+ }
+
+ const std::vector<OCRepresentation>& reps = info.representations();
+ if(reps.size() >0)
+ {
+ std::vector<OCRepresentation>::const_iterator itr = reps.begin();
+ std::vector<OCRepresentation>::const_iterator back = reps.end();
+ m_representation = *itr;
+ ++itr;
+
+ for(;itr != back; ++itr)
+ {
+ m_representation.addChild(*itr);
+ }
+ }
+ else
+ {
+ oclog() << "setPayload Error: "<<OC::Exception::INVALID_REPRESENTATION<< std::flush;
+ }
+}