Change logging method
[platform/upstream/iotivity.git] / resource / src / InProcServerWrapper.cpp
index 0659116..6bc0bae 100644 (file)
@@ -87,16 +87,17 @@ void formResourceRequest(OCEntityHandlerFlag flag,
             {
                 //Set the header options here.
                 uint16_t optionID;
-                std::string optionData;
+                char optionData[MAX_HEADER_OPTION_DATA_LENGTH + 1];
                 HeaderOptions headerOptions;
 
+                optionData[MAX_HEADER_OPTION_DATA_LENGTH] = '\0';
                 for(int i = 0;
                     i < entityHandlerRequest->numRcvdVendorSpecificHeaderOptions;
                     i++)
                 {
                     optionID = entityHandlerRequest->rcvdVendorSpecificHeaderOptions[i].optionID;
-                    optionData = reinterpret_cast<const char*>
-                             (entityHandlerRequest->rcvdVendorSpecificHeaderOptions[i].optionData);
+                    memcpy(optionData, entityHandlerRequest->rcvdVendorSpecificHeaderOptions[i].optionData,
+                        MAX_HEADER_OPTION_DATA_LENGTH);
                     HeaderOption::OCHeaderOption headerOption(optionID, optionData);
                     headerOptions.push_back(headerOption);
                 }
@@ -533,6 +534,28 @@ namespace OC
         return result;
     }
 
+    OCStackResult InProcServerWrapper::resetResourceTypes(const OCResourceHandle& resourceHandle,
+                     const std::string& newResourceType)
+    {
+        auto cLock = m_csdkLock.lock();
+        OCStackResult result;
+        if(cLock)
+        {
+            std::lock_guard<std::recursive_mutex> lock(*cLock);
+            result = OCResetResourceTypes(resourceHandle, newResourceType.c_str());
+        }
+        else
+        {
+            result = OC_STACK_ERROR;
+        }
+
+        if (result != OC_STACK_OK)
+        {
+            throw OCException(OC::Exception::BIND_TYPE_FAILED, result);
+        }
+        return result;
+    }
+
     OCStackResult InProcServerWrapper::bindInterfaceToResource(
                      const OCResourceHandle& resourceHandle,
                      const std::string& resourceInterfaceName)
@@ -557,8 +580,33 @@ namespace OC
         return result;
     }
 
+    OCStackResult InProcServerWrapper::resetResourceInterfaces(
+                     const OCResourceHandle& resourceHandle,
+                     const std::string& newResourceInterface)
+    {
+        auto cLock = m_csdkLock.lock();
+        OCStackResult result;
+        if(cLock)
+        {
+            std::lock_guard<std::recursive_mutex> lock(*cLock);
+            result = OCResetResourceInterfaces(resourceHandle,
+                        newResourceInterface.c_str());
+        }
+        else
+        {
+            result = OC_STACK_ERROR;
+        }
+
+        if (result != OC_STACK_OK)
+        {
+            throw OCException(OC::Exception::BIND_INTERFACE_FAILED, result);
+        }
+        return result;
+    }
+
     OCStackResult InProcServerWrapper::startPresence(const unsigned int seconds)
     {
+#ifdef WITH_PRESENCE
         auto cLock = m_csdkLock.lock();
         OCStackResult result = OC_STACK_ERROR;
         if(cLock)
@@ -572,10 +620,14 @@ namespace OC
             throw OCException(OC::Exception::START_PRESENCE_FAILED, result);
         }
         return result;
+#else
+        return OC_STACK_NOT_IMPLEMENTED;
+#endif
     }
 
     OCStackResult InProcServerWrapper::stopPresence()
     {
+#ifdef WITH_PRESENCE
         auto cLock = m_csdkLock.lock();
         OCStackResult result = OC_STACK_ERROR;
         if(cLock)
@@ -589,6 +641,9 @@ namespace OC
             throw OCException(OC::Exception::END_PRESENCE_FAILED, result);
         }
         return result;
+#else
+        return OC_STACK_NOT_IMPLEMENTED;
+#endif
     }
 
     OCStackResult InProcServerWrapper::sendResponse(
@@ -715,7 +770,7 @@ namespace OC
         }
         catch (InitializeException &e)
         {
-            oclog() << "Exception in stop"<< e.what() << std::flush;
+            OIC_LOG_V(INFO, TAG, "Exception in stop (%s)", e.what());
         }
     }
 }