IOT-2204: Fix IPCA compiler warnings on Linux
authorSoemin Tjong <stjong@microsoft.com>
Tue, 9 May 2017 02:16:19 +0000 (19:16 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Sat, 20 May 2017 01:17:50 +0000 (01:17 +0000)
https://jira.iotivity.org/browse/IOT-2204

Change-Id: I523c947aba51b3d4d7b0b6e19745e783eab3eeeb
Signed-off-by: Soemin Tjong <stjong@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19753
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
15 files changed:
resource/IPCA/samples/ElevatorClient/ElevatorClient.cpp
resource/IPCA/samples/ElevatorServer/elevatorserver.cpp
resource/IPCA/samples/ElevatorServer/elevatorserver.h
resource/IPCA/samples/ipcaapp/ipcaapp.cpp
resource/IPCA/src/app.cpp
resource/IPCA/src/callback.cpp
resource/IPCA/src/inc/ocfframework.h
resource/IPCA/src/ipcavariant.cpp
resource/IPCA/src/ocfframework.cpp
resource/IPCA/unittests/IPCAElevatorClient.cpp
resource/IPCA/unittests/ipcatestdata.h
resource/IPCA/unittests/ipcaunittests.cpp
resource/IPCA/unittests/mockOC.cpp
resource/IPCA/unittests/testelevatorclient.cpp
resource/IPCA/unittests/testelevatorserver.cpp

index 02f0c80..a8d0ee6 100644 (file)
 #include "ipca.h"
 #include "OCFDevice.h"
 
-#if defined(_MSC_VER)
-#define UNREFERENCED_PARAMETER(P)          (P)
-#else
-#define UNREFERENCED_PARAMETER(P)
-#endif
+#define UNUSED_PARAMETER(P)       (void)(P)
 
 // Forward decls.
 extern bool RediscoverElevator();
@@ -91,7 +87,7 @@ IPCAStatus RequestObserve()
 void ResourceChangeNotificationCallback(IPCAStatus result, void* context,
                         IPCAPropertyBagHandle propertyBagHandle)
 {
-    UNREFERENCED_PARAMETER(context);
+    UNUSED_PARAMETER(context);
 
     int observedCurrentFloor = -1, observedDirection = -1, observedTargetFloor = -1;
 
@@ -145,7 +141,7 @@ void GetPropertiesCallback(IPCAStatus result,
                     void* context,
                     IPCAPropertyBagHandle propertyBagHandle)
 {
-    UNREFERENCED_PARAMETER(context);
+    UNUSED_PARAMETER(context);
 
     int currentFloor = 0, direction = 0, targetFloor = 0;
 
@@ -196,8 +192,8 @@ void SetPropertiesCallback(IPCAStatus result,
                 void* context,
                 IPCAPropertyBagHandle propertyBagHandle)
 {
-    UNREFERENCED_PARAMETER(context);
-    UNREFERENCED_PARAMETER(propertyBagHandle);
+    UNUSED_PARAMETER(context);
+    UNUSED_PARAMETER(propertyBagHandle);
 
     if (result == IPCA_OK)
     {
@@ -219,7 +215,7 @@ void DiscoverDevicesCallback(void* context,
             IPCADeviceStatus deviceStatus,
             const IPCADiscoveredDeviceInfo* deviceInfo)
 {
-    UNREFERENCED_PARAMETER(context);
+    UNUSED_PARAMETER(context);
 
     std::lock_guard<std::recursive_mutex> lock(g_globalMutex);
 
@@ -507,7 +503,7 @@ bool DiscoverElevator(bool freeRun, size_t timeOutMs)
 {
     std::unique_lock<std::mutex> lock { g_deviceDiscoveredCbMutex };
 
-    char* resourceTypes[] = {
+    const char* resourceTypes[] = {
             "x.org.iotivity.sample.elevator",
             "x.org.iotivity.sample.elevator2",
             "x.org.iotivity.sample.elevator3",
@@ -567,11 +563,11 @@ IPCAStatus PwdInputCallback(
                 char* passwordBuffer,
                 size_t passwordBufferSize)
 {
-    UNREFERENCED_PARAMETER(passwordBufferSize);
-    UNREFERENCED_PARAMETER(type);
-    UNREFERENCED_PARAMETER(platformInformation);
-    UNREFERENCED_PARAMETER(deviceInformation);
-    UNREFERENCED_PARAMETER(context);
+    UNUSED_PARAMETER(passwordBufferSize);
+    UNUSED_PARAMETER(type);
+    UNUSED_PARAMETER(platformInformation);
+    UNUSED_PARAMETER(deviceInformation);
+    UNUSED_PARAMETER(context);
 
     std::cout << "Received Password Input Callback" << std::endl;
 
@@ -596,10 +592,10 @@ IPCAStatus PwdDisplayCallback(
                 IPCAOwnershipTransferType type,
                 const char* password)
 {
-    UNREFERENCED_PARAMETER(context);
-    UNREFERENCED_PARAMETER(deviceInformation);
-    UNREFERENCED_PARAMETER(platformInformation);
-    UNREFERENCED_PARAMETER(type);
+    UNUSED_PARAMETER(context);
+    UNUSED_PARAMETER(deviceInformation);
+    UNUSED_PARAMETER(platformInformation);
+    UNUSED_PARAMETER(type);
 
 
     std::cout << "==========================================" << std::endl;
@@ -613,7 +609,7 @@ IPCAStatus PwdDisplayCallback(
 
 void AuthCompletionCallback(IPCAStatus completionStatus, void* context)
 {
-    UNREFERENCED_PARAMETER(context);
+    UNUSED_PARAMETER(context);
     std::cout << "AuthCompletionCallback().  Completion status is: " << completionStatus;
     std::cout << std::endl;
 }
@@ -626,8 +622,10 @@ int main(int argc, char* argv[])
         return 0;
     }
 
-    IPCAUuid appId = {0xb6, 0x12, 0x38, 0x0c, 0x8c, 0x4c, 0x11, 0xe6,
-                      0xae, 0x22, 0x56, 0xb6, 0xb6, 0x49, 0x96, 0x11};
+    IPCAUuid appId = {
+                       {0xb6, 0x12, 0x38, 0x0c, 0x8c, 0x4c, 0x11, 0xe6,
+                        0xae, 0x22, 0x56, 0xb6, 0xb6, 0x49, 0x96, 0x11}
+                     };
 
     IPCAAppInfo ipcaAppInfo = { appId, "ElevatorClient", "1.0.0", "Microsoft" };
 
index 814fa91..23ad96f 100644 (file)
@@ -46,14 +46,14 @@ FILE* server_fopen(const char *path, const char *mode)
 // class ElevatorServer implementation.
 //
 ElevatorServer::ElevatorServer() :
-    engineThread(),
     m_elevatorResourceHandle(nullptr),
     m_elevatorResourceHandle2(nullptr),
     m_elevatorResourceHandle3(nullptr),
     m_elevatorResourceHandle4(nullptr),
     m_targetFloor(1),
     m_currentFloor(1),
-    m_direction(ElevatorDirection::Stopped)
+    m_direction(ElevatorDirection::Stopped),
+    m_engineThread()
 {
 #ifdef SECURED
     m_displayPasswordCallbackHandle = nullptr;
@@ -217,7 +217,7 @@ bool ElevatorServer::Start(const std::string& elevatorName)
 
         // Start the engine thread.
         m_isRunning = true;
-        engineThread = std::thread(&ElevatorServer::Engine, this);
+        m_engineThread = std::thread(&ElevatorServer::Engine, this);
 
         // Device Info.
         char devName[256];
@@ -225,7 +225,8 @@ bool ElevatorServer::Start(const std::string& elevatorName)
         CopyStringToBuffer(m_name, devName, 256);
         CopyStringToBuffer(defaultResourceTypeName, resTypeName, 256);
         OCStringLL types { nullptr, resTypeName };
-        OCDeviceInfo deviceInfo = { devName, &types, "0.0.1", nullptr };
+        char specVersion[] = "0.0.1";
+        OCDeviceInfo deviceInfo = { devName, &types, specVersion, nullptr };
 
         // Platform Info
         char platformId[] = "6cb6c994-8c4b-11e6-ae22-56b6b6499611";
@@ -365,11 +366,11 @@ void ElevatorServer::Stop()
         m_elevatorResourceHandle3 = nullptr;
         m_elevatorResourceHandle4 = nullptr;
 
-        // Signal the engineThread to stop and wait for it to exit.
+        // Signal the m_engineThread to stop and wait for it to exit.
         m_isRunning = false;
-        if (engineThread.joinable())
+        if (m_engineThread.joinable())
         {
-            engineThread.join();
+            m_engineThread.join();
         }
 
 #ifdef SECURED
index 09cf6dc..8d2849d 100644 (file)
-/* *****************************************************************
- *
- * Copyright 2017 Microsoft
- *
- *
- * 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 ELEVATOR_SERVER_H_
-#define ELEVATOR_SERVER_H_
-
-#include <string>
-#include <mutex>
-#include "OCPlatform.h"
-#include "OCApi.h"
-#include <OCProvisioningManager.hpp>
-
-using namespace OC;
-
-typedef enum
-{
-    Stopped = 0,
-    Up,
-    Down
-} ElevatorDirection;
-
-class ElevatorServer
-{
-public:
-    ElevatorServer();
-    ~ElevatorServer();
-
-    // Start stop the thread processing the elevator movement.  Also register/unregister the
-    // elevator from IoTivity.
-    bool Start(const std::string& elevatorName);
-    void Stop();
-
-    // Target floor is set by caller.
-    void SetTargetFloor(int floor);
-    int GetTargetFloor();
-
-    // Current floor is set by elevator.
-    int GetCurrentFloor();
-    ElevatorDirection GetElevatorDirection();
-
-private:
-    std::mutex m_elevatorMutex;
-
-    // List of observers, when client app calls resource->Observer().
-    ObservationIds m_observers;
-
-    // Send notification to observers.
-    void NotifyObservers();
-
-    // Elevator resources
-    OCResourceHandle m_elevatorResourceHandle;
-    OCResourceHandle m_elevatorResourceHandle2;
-    OCResourceHandle m_elevatorResourceHandle3;
-    OCResourceHandle m_elevatorResourceHandle4;
-
-    int m_targetFloor;    // where elevator needs to be.
-    int m_currentFloor;   // where elevator is.
-    ElevatorDirection m_direction;    // current direction of the elevator.
-
-    // Thread moving the elevator.
-    std::thread engineThread;
-    bool m_isRunning;
-    static void Engine(ElevatorServer* elevator);
-
-    // Move current floor to target floor.
-    void MoveElevator();
-
-    // Helper function to send response for a request.
-    OCStackResult SendResponse(std::shared_ptr<OCResourceRequest> request);
-
-    // OCF callback for this elevator.
-    OCEntityHandlerResult ElevatorEntityHandler(std::shared_ptr<OCResourceRequest> request);
-
-    // OCF callback for a generated pin
-    void PinDisplayCallback(char* pinData, size_t pinLength);
-
-    // Elevator device details.
-    std::string     m_name;
-
-    // Elevator platform details.
-    std::string     m_platformID;
-    std::string     m_modelNumber;
-    std::string     m_platformVersion;
-    std::string     m_serialNumber;
-    std::string     m_specVersion;
-    std::string     m_defaultLanguage;
-    std::string     m_manufacturerName;
-    std::string     m_manufacturerUrl;
-    std::string     m_dateOfManufacture;
-    std::string     m_operatingSystemVersion;
-    std::string     m_hardwareVersion;
-    std::string     m_firmwareVersion;
-    std::string     m_supportUrl;
-    std::string     m_systemTime;
-
-#ifdef SECURED
-    DisplayPinCallbackHandle m_displayPasswordCallbackHandle;
-#endif
-};
-#endif // ELEVATOR_SERVER_H_
+/* *****************************************************************\r
+ *\r
+ * Copyright 2017 Microsoft\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef ELEVATOR_SERVER_H_\r
+#define ELEVATOR_SERVER_H_\r
+\r
+#include <string>\r
+#include <mutex>\r
+#include "OCPlatform.h"\r
+#include "OCApi.h"\r
+#include <OCProvisioningManager.hpp>\r
+\r
+using namespace OC;\r
+\r
+typedef enum\r
+{\r
+    Stopped = 0,\r
+    Up,\r
+    Down\r
+} ElevatorDirection;\r
+\r
+class ElevatorServer\r
+{\r
+public:\r
+    ElevatorServer();\r
+    ~ElevatorServer();\r
+\r
+    // Start stop the thread processing the elevator movement.  Also register/unregister the\r
+    // elevator from IoTivity.\r
+    bool Start(const std::string& elevatorName);\r
+    void Stop();\r
+\r
+    // Target floor is set by caller.\r
+    void SetTargetFloor(int floor);\r
+    int GetTargetFloor();\r
+\r
+    // Current floor is set by elevator.\r
+    int GetCurrentFloor();\r
+    ElevatorDirection GetElevatorDirection();\r
+\r
+private:\r
+    std::mutex m_elevatorMutex;\r
+\r
+    // List of observers, when client app calls resource->Observer().\r
+    ObservationIds m_observers;\r
+\r
+    // Send notification to observers.\r
+    void NotifyObservers();\r
+\r
+    // Elevator resources\r
+    OCResourceHandle m_elevatorResourceHandle;\r
+    OCResourceHandle m_elevatorResourceHandle2;\r
+    OCResourceHandle m_elevatorResourceHandle3;\r
+    OCResourceHandle m_elevatorResourceHandle4;\r
+\r
+    int m_targetFloor;    // where elevator needs to be.\r
+    int m_currentFloor;   // where elevator is.\r
+    ElevatorDirection m_direction;    // current direction of the elevator.\r
+\r
+    // Thread moving the elevator.\r
+    std::thread m_engineThread;\r
+    bool m_isRunning;\r
+    static void Engine(ElevatorServer* elevator);\r
+\r
+    // Move current floor to target floor.\r
+    void MoveElevator();\r
+\r
+    // Helper function to send response for a request.\r
+    OCStackResult SendResponse(std::shared_ptr<OCResourceRequest> request);\r
+\r
+    // OCF callback for this elevator.\r
+    OCEntityHandlerResult ElevatorEntityHandler(std::shared_ptr<OCResourceRequest> request);\r
+\r
+    // OCF callback for a generated pin\r
+    void PinDisplayCallback(char* pinData, size_t pinLength);\r
+\r
+    // Elevator device details.\r
+    std::string     m_name;\r
+\r
+    // Elevator platform details.\r
+    std::string     m_platformID;\r
+    std::string     m_modelNumber;\r
+    std::string     m_platformVersion;\r
+    std::string     m_serialNumber;\r
+    std::string     m_specVersion;\r
+    std::string     m_defaultLanguage;\r
+    std::string     m_manufacturerName;\r
+    std::string     m_manufacturerUrl;\r
+    std::string     m_dateOfManufacture;\r
+    std::string     m_operatingSystemVersion;\r
+    std::string     m_hardwareVersion;\r
+    std::string     m_firmwareVersion;\r
+    std::string     m_supportUrl;\r
+    std::string     m_systemTime;\r
+\r
+#ifdef SECURED\r
+    DisplayPinCallbackHandle m_displayPasswordCallbackHandle;\r
+#endif\r
+};\r
+#endif // ELEVATOR_SERVER_H_\r
index 03448ce..f462574 100644 (file)
 
 #include "ipca.h"
 
-#if defined(_MSC_VER)
-#define UNREFERENCED_PARAMETER(P)          (P)
-#else
-#define UNREFERENCED_PARAMETER(P)
-#endif
+#define UNUSED_PARAMETER(P)       (void)(P)
 
 IPCAAppHandle g_ipcaAppHandle;
 std::recursive_mutex g_globalMutex;
@@ -90,11 +86,11 @@ private:
 };
 
 OCFDevice::OCFDevice(std::string id) :
+    m_localId(GenerateUniqueId()),
     m_deviceId (id),
     m_deviceHandle(nullptr),
     m_deviceInfo(nullptr),
-    m_platformInfo(nullptr),
-    m_localId(GenerateUniqueId())
+    m_platformInfo(nullptr)
 {
 }
 
@@ -169,8 +165,8 @@ void OCFDevice::GetPropertiesCallback(IPCAStatus result,
                     const void* context,
                     IPCAPropertyBagHandle propertyBagHandle)
 {
-    UNREFERENCED_PARAMETER(context);
-    UNREFERENCED_PARAMETER(result);
+    UNUSED_PARAMETER(context);
+    UNUSED_PARAMETER(result);
 
     std::lock_guard<std::recursive_mutex> lock(g_globalMutex);
 
@@ -516,7 +512,7 @@ void DiscoverDevicesCallback(void* context,
             IPCADeviceStatus deviceStatus,
             const IPCADiscoveredDeviceInfo* deviceInfo)
 {
-    UNREFERENCED_PARAMETER(context);
+    UNUSED_PARAMETER(context);
 
     std::lock_guard<std::recursive_mutex> lock(g_globalMutex);
 
@@ -567,12 +563,12 @@ IPCAStatus IPCA_CALL PasswordInputCallback(void* context,
                                            char* passwordBuffer,
                                            size_t passwordBufferSize)
 {
-    UNREFERENCED_PARAMETER(context);
-    UNREFERENCED_PARAMETER(deviceInformation);
-    UNREFERENCED_PARAMETER(platformInformation);
-    UNREFERENCED_PARAMETER(type);
-    UNREFERENCED_PARAMETER(passwordBuffer);
-    UNREFERENCED_PARAMETER(passwordBufferSize);
+    UNUSED_PARAMETER(context);
+    UNUSED_PARAMETER(deviceInformation);
+    UNUSED_PARAMETER(platformInformation);
+    UNUSED_PARAMETER(type);
+    UNUSED_PARAMETER(passwordBuffer);
+    UNUSED_PARAMETER(passwordBufferSize);
 
     // @todo: collect the password from the user
 
@@ -586,11 +582,11 @@ IPCAStatus IPCA_CALL PasswordDisplayCallback(void* context,
                                              IPCAOwnershipTransferType type,
                                              const char* password)
 {
-    UNREFERENCED_PARAMETER(context);
-    UNREFERENCED_PARAMETER(deviceInformation);
-    UNREFERENCED_PARAMETER(platformInformation);
-    UNREFERENCED_PARAMETER(type);
-    UNREFERENCED_PARAMETER(password);
+    UNUSED_PARAMETER(context);
+    UNUSED_PARAMETER(deviceInformation);
+    UNUSED_PARAMETER(platformInformation);
+    UNUSED_PARAMETER(type);
+    UNUSED_PARAMETER(password);
 
     // @todo: display the password and ask for confirmation from the user
 
@@ -612,8 +608,10 @@ int main()
     IPCAStatus status;
 
     // Initialize IPCA.
-    IPCAUuid appId = {0x37, 0x9d, 0xf2, 0xf2, 0x7e, 0xf7, 0x11, 0xe6,
-                      0xae, 0x22, 0x56, 0xb6, 0xb6, 0x49, 0x96, 0x11};
+    IPCAUuid appId = {
+                        {0x37, 0x9d, 0xf2, 0xf2, 0x7e, 0xf7, 0x11, 0xe6,
+                         0xae, 0x22, 0x56, 0xb6, 0xb6, 0x49, 0x96, 0x11}
+                     };
     IPCAAppInfo ipcaAppInfo = { appId, "IPCAAPP", "1.0.0", "Microsoft" };
 
     status = IPCAOpen(&ipcaAppInfo, IPCA_VERSION_1, &g_ipcaAppHandle);
@@ -627,7 +625,7 @@ int main()
         PasswordInputCallback, PasswordDisplayCallback, nullptr);
 
     // Start discovering devices.
-    char* resourceTypes[] = {
+    const char* resourceTypes[] = {
         "" /* any resource type */
     };
 
index 03e723a..bfc6adf 100644 (file)
@@ -29,10 +29,10 @@ OCFFramework ocfFramework;
 
 App::App(const IPCAAppInfo* ipcaAppInfo, IPCAVersion ipcaVersion) :
     m_isStopped(false),
-    m_passwordInputCallbackHandle(nullptr),
-    m_passwordDisplayCallbackHandle(nullptr),
     m_ipcaVersion(ipcaVersion),
+    m_passwordInputCallbackHandle(nullptr),
     m_passwordInputCallbackInfo(nullptr),
+    m_passwordDisplayCallbackHandle(nullptr),
     m_passwordDisplayCallbackInfo(nullptr)
 {
     m_ipcaAppInfo.appId = ipcaAppInfo->appId;
index 06a5ebb..dffce6b 100644 (file)
@@ -98,7 +98,8 @@ void Callback::Stop()
         OIC_LOG_V(
             ERROR,
             TAG,
-            "Stop() timed out: m_callbackInfoList count = [%d] m_expiredCallbacksInProgress = [%d]",
+            "Stop() timed out: m_callbackInfoList count = [%" PRIuPTR
+            "] m_expiredCallbacksInProgress = [%" PRIuPTR "]",
             m_callbackInfoList.size(),
             m_expiredCallbacksInProgress);
         throw timeoutException;
@@ -411,7 +412,7 @@ bool Callback::ClearCallbackInProgress(size_t mapKey)
         return true;
     }
 
-    OIC_LOG_V(WARNING, TAG, "ClearCallbackInProgress() mapKey [%d] is not found", mapKey);
+    OIC_LOG_V(WARNING, TAG, "ClearCallbackInProgress() mapKey [%" PRIuPTR "] is not found", mapKey);
     assert(false); // In progress callback is not expected to be removed from the list.
     return false;
 }
@@ -616,7 +617,8 @@ void Callback::DeviceDiscoveryCallback(
                     const std::vector<std::string>& deviceResourceTypeList)
 {
     // Create IPCADiscoveredDeviceInfo object for callback.
-    IPCADiscoveredDeviceInfo  deviceInfoUsedForCallback = {0};
+    IPCADiscoveredDeviceInfo  deviceInfoUsedForCallback;
+    memset(&deviceInfoUsedForCallback, 0, sizeof(IPCADiscoveredDeviceInfo));
 
     if (deviceInfo.deviceUris.size() != 0)
     {
@@ -890,6 +892,8 @@ void Callback::PasswordDisplayCallback(
                     const char* passwordBuffer,
                     CallbackInfo::Ptr cbInfo)
 {
+    OC_UNUSED(deviceId);
+
     if ((cbInfo->app != m_app) || (SetCallbackInProgress(cbInfo->mapKey) == false))
     {
         return;
index c910cda..e2b41f8 100644 (file)
@@ -39,7 +39,7 @@ typedef struct DeviceDetails
     bool deviceNotRespondingIndicated;
 
     // How many IPCAOpenDevice() on this device.
-    size_t deviceOpenCount;
+    int deviceOpenCount;
 
     // Timestamp of final close.
     uint64_t lastCloseDeviceTime;
index f61281a..8540277 100644 (file)
@@ -59,7 +59,7 @@ IPCAStatus IPCAPropertySetValue(IPCAPropertyBagHandle propertyBagHandle, const c
     catch (std::exception &e)
     {
         OC_UNUSED(e);
-        OIC_LOG_V(WARNING, TAG, e.what());
+        OIC_LOG_V(WARNING, TAG, "%s", e.what());
         return IPCA_FAIL;
     }
 }
@@ -112,7 +112,7 @@ IPCAStatus IPCAPropertyBagSetValuePropertyBag(IPCAPropertyBagHandle propertyBagH
     catch (std::exception &e)
     {
         OC_UNUSED(e);
-        OIC_LOG_V(WARNING, TAG, e.what());
+        OIC_LOG_V(WARNING, TAG, "%s", e.what());
         return IPCA_FAIL;
     }
 }
@@ -144,7 +144,7 @@ IPCAStatus IPCAPropertyBagSetValueArray(IPCAPropertyBagHandle propertyBagHandle,
     catch (std::exception &e)
     {
         OC_UNUSED(e);
-        OCLog(WARNING, TAG, e.what());
+        OIC_LOG_V(WARNING, TAG, "%s", e.what());
         return IPCA_FAIL;
     }
 }
@@ -200,7 +200,7 @@ IPCAStatus IPCAPropertyBagSetValueStringArray(IPCAPropertyBagHandle propertyBagH
     catch (std::exception &e)
     {
         OC_UNUSED(e);
-        OIC_LOG_V(WARNING, TAG, e.what());
+        OIC_LOG_V(WARNING, TAG, "%s", e.what());
         return IPCA_FAIL;
     }
 }
@@ -232,7 +232,7 @@ IPCAStatus IPCAPropertyBagSetValuePropertyBagArray(IPCAPropertyBagHandle propert
     catch (std::exception &e)
     {
         OC_UNUSED(e);
-        OIC_LOG_V(WARNING, TAG, e.what());
+        OIC_LOG_V(WARNING, TAG, "%s", e.what());
         return IPCA_FAIL;
     }
 }
index 63fc954..a28853b 100644 (file)
@@ -347,7 +347,7 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
         }
 
 
-        if (OC_STACK_OK != SetDeviceInfo(&deviceInfo))
+        if (IPCA_OK != SetDeviceInfo(&deviceInfo))
         {
             return IPCA_FAIL;
         }
@@ -612,7 +612,7 @@ void OCFFramework::OnResourceFound(std::shared_ptr<OCResource> resource)
             m_OCFDevices[resource->sid()] = deviceDetails;
 
             OIC_LOG_V(INFO, TAG, "Added device ID: [%s]", resource->sid().c_str());
-            OIC_LOG_V(INFO, TAG, "m_OCFDevices count = [%d]", m_OCFDevices.size());
+            OIC_LOG_V(INFO, TAG, "m_OCFDevices count = [%" PRIuPTR "]", m_OCFDevices.size());
         }
 
         // Populate the details about the device.
@@ -888,7 +888,7 @@ void OCFFramework::OnPlatformInfoCallback(const OCRepresentation& rep)
 
 IPCAStatus OCFFramework::GetCommonResources(DeviceDetails::Ptr deviceDetails)
 {
-    const int MAX_REQUEST_COUNT = 3;
+    const size_t MAX_REQUEST_COUNT = 3;
 
     OCStackResult result;
 
@@ -1028,7 +1028,7 @@ void OCFFramework::OnGet(const HeaderOptions& headerOptions,
                         const int eCode,
                         CallbackInfo::Ptr callbackInfo)
 {
-    headerOptions;
+    OC_UNUSED(headerOptions);
 
     IPCAStatus status = IPCA_OK;
 
@@ -1054,6 +1054,7 @@ void OCFFramework::OnObserve(
                         const int &sequenceNumber,
                         CallbackInfo::Ptr callbackInfo)
 {
+    OC_UNUSED(headerOptions);
     OC_UNUSED(sequenceNumber);
 
     IPCAStatus status = IPCA_OK;
@@ -1167,6 +1168,12 @@ IPCAStatus OCFFramework::SendCommandToDevice(std::string& deviceId,
                                             _1, _2, _3, _4, callbackInfo));
             break;
         }
+
+        default:
+        {
+            assert(false);
+            result = OC_STACK_ERROR;
+        }
     }
 
     if (result == OC_STACK_OK)
index ebdf0dd..681daa8 100644 (file)
@@ -423,7 +423,7 @@ IPCAStatus IPCAElevatorClient::ConfirmDeviceAndPlatformInfo()
         EXPECT_STREQ(g_elevator1Name.c_str(), deviceInfo->deviceName);
 
         // See: ipcatestdata.h ELEVATOR_DATA_MODEL_VERSION_1 to 3.
-        EXPECT_EQ(3, deviceInfo->dataModelVersionCount);
+        EXPECT_EQ(static_cast<size_t>(3), deviceInfo->dataModelVersionCount);
 
         bool modelFound = false;
         std::string Model1(ELEVATOR_DATA_MODEL_VERSION_1);
@@ -546,7 +546,7 @@ IPCAStatus IPCAElevatorClient::ConfirmResourceInterfaces()
                             nullptr,
                             &resourcePathList,
                             &resourcePathCount));
-    EXPECT_EQ(1, resourcePathCount);
+    EXPECT_EQ(static_cast<size_t>(1), resourcePathCount);
     EXPECT_STREQ(ELEVATOR_CO_RESOURCE_PATH, resourcePathList[0]);
     IPCAFreeStringArray(resourcePathList, resourcePathCount);
 
@@ -1069,15 +1069,15 @@ IPCAStatus IPCAElevatorClient::TestMultipleCallsToCloseSameHandle()
 
     // First IPCACloseHandle() should be succesful.
     EXPECT_EQ(IPCA_OK, IPCACloseHandle(getHandle, &C_CloseHandleComplete, static_cast<void*>(&count)));
-    EXPECT_EQ(1, C_WaitNumber(&count, 1));
+    EXPECT_EQ(static_cast<size_t>(1), C_WaitNumber(&count, 1));
 
     // Subsequent IPCACloseHandle() on the same handle is expected to fail.
     // And the C_CloseHandleMultiple() is not called, i.e. count should not increase.
     EXPECT_EQ(IPCA_FAIL, IPCACloseHandle(getHandle, &C_CloseHandleComplete, static_cast<void*>(&count)));
-    EXPECT_EQ(1, C_WaitNumber(&count, 2));
+    EXPECT_EQ(static_cast<size_t>(1), C_WaitNumber(&count, 2));
 
     EXPECT_EQ(IPCA_FAIL, IPCACloseHandle(getHandle, &C_CloseHandleComplete, static_cast<void*>(&count)));
-    EXPECT_EQ(1, C_WaitNumber(&count, 3));
+    EXPECT_EQ(static_cast<size_t>(1), C_WaitNumber(&count, 3));
 
     return IPCA_OK;
 }
index d7b2b19..67a66b7 100644 (file)
@@ -1,52 +1,52 @@
-/* *****************************************************************
- *
- * Copyright 2017 Microsoft
- *
- *
- * 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 IPCATESTDATA_H_
-#define IPCATESTDATA_H_
-
-static char* ELEVATOR_PLATFORM_ID = "2386034c-8099-11e6-ae22-56b6b6499611";
-static char* ELEVATOR_PLATFORM_INDEPENDENT_ID = "be182fc4-f336-11e6-bc64-92361f002671";
-static char* ELEVATOR_DATA_MODEL_VERSION_1 = "x.org.iotivity.test.1.0.0";
-static char* ELEVATOR_DATA_MODEL_VERSION_2 = "x.org.iotivity.test.2.0.0";
-static char* ELEVATOR_DATA_MODEL_VERSION_3 = "x.org.iotivity.test.3.0.0";
-
-static char* ELEVATOR_RESOURCE_PATH = "/ipca/test/elevator";
-static char* ELEVATOR_RESOURCE_TYPE = "x.org.iotivity.test.elevator";
-static char* ELEVATOR_PROPERTY_CURRENT_FLOOR = "x.org.iotivity.CurrentFloor";
-static char* ELEVATOR_PROPERTY_TARGET_FLOOR = "x.org.iotivity.TargetFloor";
-static char* ELEVATOR_PROPERTY_DIRECTION = "x.org.iotivity.Direction";
-
-static char* ELEVATOR_RESOURCE_MADE_UP_INTERFACE = "non.existence.if";
-
-static char* ELEVATOR_CO_RESOURCE_PATH = "/ipca/test/carbonmonoxide";
-static char* ELEVATOR_CO_RESOURCE_TYPE = "oic.r.sensor.carbonmonoxide";
-static char* ELEVATOR_CO_PRIVATE_INTERFACE = "my.private.if";
-
-static char* ELEVATOR_RESOURCE_CREATE_RELATIVE_PATH = "/ipca/new/resource/relative";
-static char* ELEVATOR_RESOURCE_CREATE_RELATIVE_PATH_TYPE = "x.ipca.test.elevator.create.resource.relative";
-static char* ELEVATOR_RESOURCE_NEW_RESOURCE_PATH = "/ipca/new/resource/relative/1";
-
-static char* ELEVATOR_RESOURCE_CREATE_EXPLICIT_PATH = "/ipca/new/resource/explicit";
-static char* ELEVATOR_RESOURCE_CREATE_EXPLICIT_PATH_TYPE = "x.ipca.test.elevator.create.resource.explicit";
-
-static char* ELEVATOR_RESOURCE_DELETE_PATH = "/ipca/resource/delete";
-static char* ELEVATOR_RESOURCE_DELETE_TYPE = "x.ipca.test.elevator.delete";
-
-static char* ELEVATOR_KEYWORD = "elevator";
-#endif // IPCATESTDATA_H_
+/* *****************************************************************\r
+ *\r
+ * Copyright 2017 Microsoft\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License")\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef IPCATESTDATA_H_\r
+#define IPCATESTDATA_H_\r
+\r
+#define ELEVATOR_PLATFORM_ID                "2386034c-8099-11e6-ae22-56b6b6499611"\r
+#define ELEVATOR_PLATFORM_INDEPENDENT_ID    "be182fc4-f336-11e6-bc64-92361f002671"\r
+#define ELEVATOR_DATA_MODEL_VERSION_1       "x.org.iotivity.test.1.0.0"\r
+#define ELEVATOR_DATA_MODEL_VERSION_2       "x.org.iotivity.test.2.0.0"\r
+#define ELEVATOR_DATA_MODEL_VERSION_3       "x.org.iotivity.test.3.0.0"\r
+\r
+#define ELEVATOR_RESOURCE_PATH              "/ipca/test/elevator"\r
+#define ELEVATOR_RESOURCE_TYPE              "x.org.iotivity.test.elevator"\r
+#define ELEVATOR_PROPERTY_CURRENT_FLOOR     "x.org.iotivity.CurrentFloor"\r
+#define ELEVATOR_PROPERTY_TARGET_FLOOR      "x.org.iotivity.TargetFloor"\r
+#define ELEVATOR_PROPERTY_DIRECTION         "x.org.iotivity.Direction"\r
+\r
+#define ELEVATOR_RESOURCE_MADE_UP_INTERFACE "non.existence.if"\r
+\r
+#define ELEVATOR_CO_RESOURCE_PATH       "/ipca/test/carbonmonoxide"\r
+#define ELEVATOR_CO_RESOURCE_TYPE       "oic.r.sensor.carbonmonoxide"\r
+#define ELEVATOR_CO_PRIVATE_INTERFACE   "my.private.if"\r
+\r
+#define ELEVATOR_RESOURCE_CREATE_RELATIVE_PATH       "/ipca/new/resource/relative"\r
+#define ELEVATOR_RESOURCE_CREATE_RELATIVE_PATH_TYPE  "x.ipca.test.elevator.create.resource.relative"\r
+#define ELEVATOR_RESOURCE_NEW_RESOURCE_PATH          "/ipca/new/resource/relative/1"\r
+\r
+#define ELEVATOR_RESOURCE_CREATE_EXPLICIT_PATH       "/ipca/new/resource/explicit"\r
+#define ELEVATOR_RESOURCE_CREATE_EXPLICIT_PATH_TYPE  "x.ipca.test.elevator.create.resource.explicit"\r
+\r
+#define ELEVATOR_RESOURCE_DELETE_PATH   "/ipca/resource/delete"\r
+#define ELEVATOR_RESOURCE_DELETE_TYPE   "x.ipca.test.elevator.delete"\r
+\r
+#define ELEVATOR_KEYWORD    "elevator"\r
+#endif // IPCATESTDATA_H_\r
index 4bedbf5..7c0ad0f 100644 (file)
@@ -39,8 +39,10 @@ using namespace std::placeholders;
 void IPCASetUnitTestMode();
 
 // IPCA test app info.
-IPCAUuid IPCATestAppUuid = {0x84, 0x71, 0x88, 0x78, 0xe6, 0x91, 0x4b, 0xf4,
-                            0xa9, 0x57, 0x04, 0xe0, 0x1b, 0x9b, 0x59, 0xd1};
+IPCAUuid IPCATestAppUuid = {
+                              {0x84, 0x71, 0x88, 0x78, 0xe6, 0x91, 0x4b, 0xf4,
+                               0xa9, 0x57, 0x04, 0xe0, 0x1b, 0x9b, 0x59, 0xd1}
+                           };
 char IPCATestAppName[] = "IPCA Unittests";
 
 // IoTivity supports 1 server per instance.
@@ -282,7 +284,7 @@ TEST_F(IPCAPropertyBagTest, PropertyBagIntArrayType)
     size_t readBackIntArraySize;
     EXPECT_EQ(IPCA_OK, IPCAPropertyBagGetValueIntArray(m_propertyBagHandle,
                             "IntArray", &readBackIntArray, &readBackIntArraySize));
-    EXPECT_EQ(10, readBackIntArraySize);
+    EXPECT_EQ(static_cast<size_t>(10), readBackIntArraySize);
     EXPECT_EQ(0, memcmp(intArray, readBackIntArray, readBackIntArraySize));
 
     IPCAPropertyBagFreeIntArray(readBackIntArray);
@@ -299,7 +301,7 @@ TEST_F(IPCAPropertyBagTest, PropertyBagDoubleArrayType)
     size_t readBackDoubleArraySize;
     EXPECT_EQ(IPCA_OK, IPCAPropertyBagGetValueDoubleArray(m_propertyBagHandle,
                             "DoubleArray", &readBackDoubleArray, &readBackDoubleArraySize));
-    EXPECT_EQ(10, readBackDoubleArraySize);
+    EXPECT_EQ(static_cast<size_t>(10), readBackDoubleArraySize);
     EXPECT_EQ(0, memcmp(doubleArray, readBackDoubleArray, readBackDoubleArraySize));
 
     IPCAPropertyBagFreeDoubleArray(readBackDoubleArray);
@@ -316,7 +318,7 @@ TEST_F(IPCAPropertyBagTest, PropertyBagBoolArrayType)
     size_t readBackBoolArraySize;
     EXPECT_EQ(IPCA_OK, IPCAPropertyBagGetValueBoolArray(m_propertyBagHandle,
                             "boolArray", &readBackBoolArray, &readBackBoolArraySize));
-    EXPECT_EQ(10, readBackBoolArraySize);
+    EXPECT_EQ(static_cast<size_t>(10), readBackBoolArraySize);
     EXPECT_EQ(0, memcmp(boolArray, readBackBoolArray, readBackBoolArraySize));
 
     IPCAPropertyBagFreeBoolArray(readBackBoolArray);
@@ -325,7 +327,7 @@ TEST_F(IPCAPropertyBagTest, PropertyBagBoolArrayType)
 TEST_F(IPCAPropertyBagTest, PropertyBagStringArrayType)
 {
     // array of string
-    char* stringArray[] = {"hello world 1", "hello world 2", "hello world 3"};
+    const char* stringArray[] = {"hello world 1", "hello world 2", "hello world 3"};
     EXPECT_EQ(IPCA_OK, IPCAPropertyBagSetValueStringArray(m_propertyBagHandle,
                             "stringArray", (const char**)stringArray, 3));
 
@@ -333,7 +335,7 @@ TEST_F(IPCAPropertyBagTest, PropertyBagStringArrayType)
     size_t readbackStringSize;
     EXPECT_EQ(IPCA_OK, IPCAPropertyBagGetValueStringArray(m_propertyBagHandle,
                             "stringArray", &readBackString, &readbackStringSize));
-    ASSERT_EQ(3, readbackStringSize);
+    ASSERT_EQ(static_cast<size_t>(3), readbackStringSize);
     EXPECT_STREQ(stringArray[0], readBackString[0]);
     EXPECT_STREQ(stringArray[1], readBackString[1]);
     EXPECT_STREQ(stringArray[2], readBackString[2]);
@@ -384,7 +386,7 @@ TEST_F(IPCAPropertyBagTest, PropertyBagPropertyBagArrayType)
     size_t arrayCount;
     EXPECT_EQ(IPCA_OK, IPCAPropertyBagGetValuePropertyBagArray(m_propertyBagHandle,
                                 "PropertyBagArray", &propertyBagReadBackArray, &arrayCount));
-    ASSERT_EQ(3, arrayCount);
+    ASSERT_EQ(static_cast<size_t>(3), arrayCount);
 
     IPCAPropertyBagHandle propertyBag1 = propertyBagReadBackArray[0], propertyBag1A;
     EXPECT_EQ(IPCA_OK, IPCAPropertyBagGetValuePropertyBag(propertyBag1, "values", &propertyBag1A));
index 2dbb124..b629db7 100644 (file)
@@ -110,7 +110,9 @@ uint16_t g_mockHostPort = 10000;
 std::string g_mockCompleteAddress = "coap://[fe80::1%25eth0]:10000";\r
 void SetMockOCDevAddr(OCDevAddr& addr)\r
 {\r
-    addr = {OC_DEFAULT_ADAPTER, OC_IP_USE_V6};\r
+    memset (&addr, 0, sizeof(addr));\r
+    addr.adapter = OC_DEFAULT_ADAPTER;\r
+    addr.flags= OC_IP_USE_V6;\r
     addr.port = g_mockHostPort;\r
     strcpy(addr.addr, g_mockHostAddress.c_str());\r
 }\r
@@ -500,6 +502,12 @@ OCStackResult OCPlatform::sendResponse(const std::shared_ptr<OCResourceResponse>
             deleteCallbackThread.detach();\r
             break;\r
         }\r
+\r
+        default:\r
+        {\r
+            assert(false);\r
+            return OC_STACK_ERROR;\r
+        }\r
     }\r
 \r
     // One time request is responded, remove the pending request.\r
@@ -680,7 +688,7 @@ std::string OCResource::setHost(const std::string& host)
     OC_UNUSED(host);\r
 \r
     g_mockCompleteAddress.copy(m_devAddr.addr, sizeof(m_devAddr.addr));\r
-    m_devAddr.addr[g_mockCompleteAddress.length()] = NULL;\r
+    m_devAddr.addr[g_mockCompleteAddress.length()] = '\0';\r
     return host;\r
 }\r
 \r
@@ -892,7 +900,9 @@ OCEntityHandlerResult MockEntityHandler(OCEntityHandlerFlag flag,
 \r
     OCPayload* payload = reinterpret_cast<OCPayload*>(ocInfo.getPayload());\r
 \r
-    OCEntityHandlerRequest  entityHandlerRequest = {0};\r
+    OCEntityHandlerRequest  entityHandlerRequest;\r
+    memset(&entityHandlerRequest, 0, sizeof(OCEntityHandlerRequest));\r
+\r
     entityHandlerRequest.requestHandle = reinterpret_cast<void*>(pendingRequest->requestNumber);\r
     entityHandlerRequest.resource = nullptr;\r
     entityHandlerRequest.messageID = 0;\r
index bf960a2..98ecbc7 100644 (file)
-/* *****************************************************************
- *
- * Copyright 2017 Microsoft
- *
- *
- * 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 "testelevatorclient.h"
-#include "ipcatestdata.h"
-
-#define VERBOSE_INFO  0   // set to 1 for extra output.
-
-using namespace OC;
-using namespace std::placeholders;
-
-ElevatorClient::ElevatorClient()
-{
-    m_elevatorResource = nullptr;
-}
-
-ElevatorClient::~ElevatorClient()
-{
-}
-
-void ElevatorClient::OnObserveCallback(
-                        const HeaderOptions headerOptions,
-                        const OCRepresentation &rep,
-                        const int &eCode,
-                        const int &sequenceNumber)
-{
-    OC_UNUSED(sequenceNumber);
-    OC_UNUSED(eCode);
-
-    int newCurrentFloor, newTargetFloor, newDirection;
-
-    if (rep.getValue(ELEVATOR_PROPERTY_CURRENT_FLOOR, newCurrentFloor) == true)
-    {
-        m_notifiedCurrentFloor = newCurrentFloor;
-    }
-
-    if (rep.getValue(ELEVATOR_PROPERTY_TARGET_FLOOR, newTargetFloor) == true)
-    {
-        m_notifiedTargetFloor = newTargetFloor;
-    }
-
-    if (rep.getValue(ELEVATOR_PROPERTY_DIRECTION, newDirection) == true)
-    {
-        m_notifiedDirection = newDirection;
-    }
-}
-
-int ElevatorClient::GetObservedCurrentFloor()
-{
-    return m_notifiedCurrentFloor;
-}
-
-bool ElevatorClient::StartObservation()
-{
-    OCStackResult result = m_elevatorResource->observe(
-                                    ObserveType::Observe,
-                                    QueryParamsMap(),
-                                    std::bind(&ElevatorClient::OnObserveCallback,
-                                            this, _1, _2, _3, _4));
-    return result == OC_STACK_OK ? true : false;
-}
-
-bool ElevatorClient::StopObservation()
-{
-    OCStackResult result = m_elevatorResource->cancelObserve();
-    return result == OC_STACK_OK ? true : false;
-}
-
-const int DEFAULT_WAITTIME = 2000;
-bool ElevatorClient::WaitForCallback(int waitingTime = DEFAULT_WAITTIME)
-{
-    std::unique_lock<std::mutex> lock { syncMutex };
-
-    if (syncCV.wait_for(lock, std::chrono::milliseconds{ waitingTime }) != std::cv_status::timeout)
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
-}
-
-void ElevatorClient::SignalCompletion()
-{
-    syncCV.notify_all();
-}
-
-// Callback handler on GET request
-void ElevatorClient::OnGet(const HeaderOptions& headerOptions,
-                           const OCRepresentation& rep,
-                           const int eCode)
-{
-    OC_UNUSED(headerOptions);
-    OC_UNUSED(eCode);
-
-    if (eCode == OC_STACK_OK)
-    {
-        ReadRepresentation(rep);
-    }
-    else
-    {
-        printf("OnGet:: received error [0x%x]\r\n", eCode);
-    }
-
-    SignalCompletion();
-}
-
-// Callback handler on PUT request
-void ElevatorClient::OnPut(const HeaderOptions& headerOptions,
-                           const OCRepresentation& rep,
-                           const int eCode)
-{
-    OC_UNUSED(headerOptions);
-
-    if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
-    {
-        ReadRepresentation(rep);
-    }
-    else
-    {
-        printf ("PUT request failed, error: 0x%x\r\n", eCode);
-    }
-
-    SignalCompletion();
-}
-
-void ElevatorClient::ReadRepresentation(const OCRepresentation& rep)
-{
-    m_targetFloor = rep.getValue<int>(ELEVATOR_PROPERTY_TARGET_FLOOR);
-    m_currentFloor = rep.getValue<int>(ELEVATOR_PROPERTY_CURRENT_FLOOR);
-    m_direction = rep.getValue<int>(ELEVATOR_PROPERTY_DIRECTION);
-}
-
-std::recursive_mutex theMutex;
-
-void ElevatorClient::PrintResource(std::shared_ptr<OCResource> resource)
-{
-#if (VERBOSE_INFO == 1)
-    std::lock_guard<std::recursive_mutex> lock(theMutex);
-    std::string resourcePath;
-    std::string hostAddress;
-    std::cout << "ElevatorClient::PrintResource:" << std::endl;
-    std::cout << "Resource URI: " << resource->uri() << std::endl;
-    std::cout << "Device URI: " << resource->host() << std::endl;
-    std::cout << "Resource Types: " << std::endl;
-    for(auto &rt : resource->getResourceTypes())
-        std::cout << "   " << rt << std::endl;
-    std::cout << "List of resource interfaces: " << std::endl;
-    for(auto &ri : resource->getResourceInterfaces())
-        std::cout << "   " << ri << std::endl;
-    std::cout << std::endl;
-#else
-    OC_UNUSED(resource);
-#endif
-}
-
-// Temporarily store the found resource pointers until their device name is found.
-// Key is device URI (e.g., "coap://[fe80::5828:93a8:d53e:4222%7]:62744")
-std::map<std::string, std::shared_ptr<OCResource>> OCFDevices;
-
-void ElevatorClient::OnDeviceInfoCallback(const OCRepresentation& rep)
-{
-    std::lock_guard<std::recursive_mutex> lock(theMutex);
-    std::string deviceName;
-    rep.getValue("n", deviceName);
-
-    if (m_elevatorResource == nullptr && deviceName.compare(m_targetElevatorName) == 0)
-    {
-        m_elevatorResource = OCFDevices[rep.getHost()];
-        OCFDevices.clear(); // free rest of the resources.
-        PrintResource(m_elevatorResource);
-    }
-}
-
-void ElevatorClient::PrintOCRep(const OCRepresentation& rep)
-{
-#if (VERBOSE_INFO == 1)
-    std::lock_guard<std::recursive_mutex> lock(theMutex);
-    std::cout << "++++++++++ PrintOCRep() ++++++++++++" << std::endl;
-    std::cout << "For device URI: " << rep.getHost() << std::endl;
-    std::cout << "Resoure URI: " << rep.getUri() << std::endl;
-    OCRepresentation::const_iterator itr= rep.begin();
-    OCRepresentation::const_iterator endItr = rep.end();
-    for(;itr!=endItr;++itr)
-    {
-        std::string value = (*itr).getValue<std::string>();
-        std::cout << "   = ElevatorClient:: Attribute name:  " << itr->attrname() << std::endl;
-        std::cout << "     ElevatorClient:: Attribute type:  " << itr->type() << std::endl;
-        std::cout << "     ElevatorClient:: Attribute value: ";
-        switch(itr->type())
-        {
-            case AttributeType::Null:
-            {
-                std::cout << "nullptr" << std::endl;
-                break;
-            }
-
-            case AttributeType::String:
-            {
-                std::cout << ((*itr).getValue<std::string>()).c_str() << std::endl;
-                break;
-            }
-
-            case AttributeType::Integer:
-            {
-                std::cout << (*itr).getValue<int>() << std::endl;
-                break;
-            }
-
-            default:
-            {
-                std::cout << "unrecognized type" << std::endl;
-                break;
-            }
-        }
-
-    }
-    std::cout << "---------- PrintOCRep() ------------" << std::endl << std::endl;
-#else
-    OC_UNUSED(rep);
-#endif
-}
-
-void ElevatorClient::OnPlatformInfoCallback(const OCRepresentation& rep)
-{
-    OC_UNUSED(rep);
-    std::lock_guard<std::recursive_mutex> lock(theMutex);
-    PrintOCRep(rep);
-}
-
-// Callback to found resources
-void ElevatorClient::OnResourceFound(std::shared_ptr<OCResource> resource)
-{
-    std::lock_guard<std::recursive_mutex> lock(theMutex);
-
-    // Target elevator already found.
-    if (m_elevatorResource != nullptr)
-    {
-        return;
-    }
-
-    std::vector<std::string> resourceTypes = resource->getResourceTypes();
-
-    if (resourceTypes.size() != 1)
-    {
-        return;
-    }
-
-    bool matchTargetResourceType = false;
-
-    for (auto const& rt : resourceTypes)
-    {
-        if (rt.compare(ELEVATOR_RESOURCE_TYPE) == 0)
-        {
-            matchTargetResourceType = true;
-            break;
-        }
-    }
-
-    if (matchTargetResourceType == false)
-    {
-        return;
-    }
-
-    if (OCFDevices.find(resource->host()) != OCFDevices.end())
-    {
-        return;  // have seen this resource from this host.
-    }
-
-    OCFDevices[resource->host()] = resource;
-
-    // Get the device name for match with m_targetElevatorName.
-    OCPlatform::getDeviceInfo(
-                    resource->host(),
-                    OC_RSRVD_DEVICE_URI,
-                    CT_DEFAULT,
-                    std::bind(&ElevatorClient::OnDeviceInfoCallback, this, _1));
-
-
-    OCPlatform::getPlatformInfo(
-                    resource->host(),
-                    OC_RSRVD_PLATFORM_URI,
-                    CT_DEFAULT,
-                    std::bind(&ElevatorClient::OnPlatformInfoCallback, this, _1));
-}
-
-// each elevator in unit test has unique device name to differentiate it from the others.
-bool ElevatorClient::FindElevator(std::string elevatorName)
-{
-    std::string defaultElevatorResourceType = ELEVATOR_RESOURCE_TYPE;
-    std::ostringstream deviceUri;
-    m_targetElevatorName = elevatorName;
-
-    deviceUri << OC_RSRVD_WELL_KNOWN_URI << "?rt=" << defaultElevatorResourceType.c_str();
-
-    OCConnectivityType connectivityType = CT_ADAPTER_IP;
-
-    OCStackResult result = OCPlatform::findResource(
-                                "",
-                                deviceUri.str(),
-                                connectivityType,
-                                std::bind(&ElevatorClient::OnResourceFound, this, _1));
-
-    if (result == OC_STACK_OK)
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
-}
-
-bool ElevatorClient::IsElevatorFound()
-{
-    return m_elevatorResource != nullptr;
-}
-
-void ElevatorClient::SetTargetFloor(int targetFloor)
-{
-    if(m_elevatorResource)
-    {
-        OCRepresentation rep;
-        rep[ELEVATOR_PROPERTY_TARGET_FLOOR] = targetFloor;
-
-        m_elevatorResource->post(
-            rep,
-            QueryParamsMap(),
-            std::bind(&ElevatorClient::OnPut, this, _1, _2, _3));
-
-        WaitForCallback();  // wait for completion.
-    }
-}
-
-bool ElevatorClient::GetTargetFloor(int* targetFlr)
-{
-    m_elevatorResource->get(QueryParamsMap(), std::bind(&ElevatorClient::OnGet, this, _1, _2, _3));
-    if (WaitForCallback())
-    {
-        *targetFlr = m_targetFloor;
-        return true;
-    }
-    else
-    {
-        *targetFlr = -1;
-        return false;
-    }
-}
-
-bool ElevatorClient::GetCurrentFloor(int* currFloor)
-{
-    m_elevatorResource->get(QueryParamsMap(), std::bind(&ElevatorClient::OnGet, this, _1, _2, _3));
-    if (WaitForCallback())
-    {
-        *currFloor = m_currentFloor;
-        return true;
-    }
-    else
-    {
-        *currFloor = -1;
-        return false;
-    }
-}
-
-bool ElevatorClient::GetDirection(int* dir)
-{
-    m_elevatorResource->get(QueryParamsMap(), std::bind(&ElevatorClient::OnGet, this, _1, _2, _3));
-    if (WaitForCallback())
-    {
-        *dir = m_direction;
-        return true;
-    }
-    else
-    {
-        *dir = -1;
-        return false;
-    }
-}
+/* *****************************************************************\r
+ *\r
+ * Copyright 2017 Microsoft\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "testelevatorclient.h"\r
+#include "ipcatestdata.h"\r
+\r
+#define VERBOSE_INFO  0   // set to 1 for extra output.\r
+\r
+using namespace OC;\r
+using namespace std::placeholders;\r
+\r
+ElevatorClient::ElevatorClient()\r
+{\r
+    m_elevatorResource = nullptr;\r
+}\r
+\r
+ElevatorClient::~ElevatorClient()\r
+{\r
+}\r
+\r
+void ElevatorClient::OnObserveCallback(\r
+                        const HeaderOptions headerOptions,\r
+                        const OCRepresentation &rep,\r
+                        const int &eCode,\r
+                        const int &sequenceNumber)\r
+{\r
+    OC_UNUSED(headerOptions);\r
+    OC_UNUSED(sequenceNumber);\r
+    OC_UNUSED(eCode);\r
+\r
+    int newCurrentFloor, newTargetFloor, newDirection;\r
+\r
+    if (rep.getValue(ELEVATOR_PROPERTY_CURRENT_FLOOR, newCurrentFloor) == true)\r
+    {\r
+        m_notifiedCurrentFloor = newCurrentFloor;\r
+    }\r
+\r
+    if (rep.getValue(ELEVATOR_PROPERTY_TARGET_FLOOR, newTargetFloor) == true)\r
+    {\r
+        m_notifiedTargetFloor = newTargetFloor;\r
+    }\r
+\r
+    if (rep.getValue(ELEVATOR_PROPERTY_DIRECTION, newDirection) == true)\r
+    {\r
+        m_notifiedDirection = newDirection;\r
+    }\r
+}\r
+\r
+int ElevatorClient::GetObservedCurrentFloor()\r
+{\r
+    return m_notifiedCurrentFloor;\r
+}\r
+\r
+bool ElevatorClient::StartObservation()\r
+{\r
+    OCStackResult result = m_elevatorResource->observe(\r
+                                    ObserveType::Observe,\r
+                                    QueryParamsMap(),\r
+                                    std::bind(&ElevatorClient::OnObserveCallback,\r
+                                            this, _1, _2, _3, _4));\r
+    return result == OC_STACK_OK ? true : false;\r
+}\r
+\r
+bool ElevatorClient::StopObservation()\r
+{\r
+    OCStackResult result = m_elevatorResource->cancelObserve();\r
+    return result == OC_STACK_OK ? true : false;\r
+}\r
+\r
+const int DEFAULT_WAITTIME = 2000;\r
+bool ElevatorClient::WaitForCallback(int waitingTime = DEFAULT_WAITTIME)\r
+{\r
+    std::unique_lock<std::mutex> lock { syncMutex };\r
+\r
+    if (syncCV.wait_for(lock, std::chrono::milliseconds{ waitingTime }) != std::cv_status::timeout)\r
+    {\r
+        return true;\r
+    }\r
+    else\r
+    {\r
+        return false;\r
+    }\r
+}\r
+\r
+void ElevatorClient::SignalCompletion()\r
+{\r
+    syncCV.notify_all();\r
+}\r
+\r
+// Callback handler on GET request\r
+void ElevatorClient::OnGet(const HeaderOptions& headerOptions,\r
+                           const OCRepresentation& rep,\r
+                           const int eCode)\r
+{\r
+    OC_UNUSED(headerOptions);\r
+    OC_UNUSED(eCode);\r
+\r
+    if (eCode == OC_STACK_OK)\r
+    {\r
+        ReadRepresentation(rep);\r
+    }\r
+    else\r
+    {\r
+        printf("OnGet:: received error [0x%x]\r\n", eCode);\r
+    }\r
+\r
+    SignalCompletion();\r
+}\r
+\r
+// Callback handler on PUT request\r
+void ElevatorClient::OnPut(const HeaderOptions& headerOptions,\r
+                           const OCRepresentation& rep,\r
+                           const int eCode)\r
+{\r
+    OC_UNUSED(headerOptions);\r
+\r
+    if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)\r
+    {\r
+        ReadRepresentation(rep);\r
+    }\r
+    else\r
+    {\r
+        printf ("PUT request failed, error: 0x%x\r\n", eCode);\r
+    }\r
+\r
+    SignalCompletion();\r
+}\r
+\r
+void ElevatorClient::ReadRepresentation(const OCRepresentation& rep)\r
+{\r
+    m_targetFloor = rep.getValue<int>(ELEVATOR_PROPERTY_TARGET_FLOOR);\r
+    m_currentFloor = rep.getValue<int>(ELEVATOR_PROPERTY_CURRENT_FLOOR);\r
+    m_direction = rep.getValue<int>(ELEVATOR_PROPERTY_DIRECTION);\r
+}\r
+\r
+std::recursive_mutex theMutex;\r
+\r
+void ElevatorClient::PrintResource(std::shared_ptr<OCResource> resource)\r
+{\r
+#if (VERBOSE_INFO == 1)\r
+    std::lock_guard<std::recursive_mutex> lock(theMutex);\r
+    std::string resourcePath;\r
+    std::string hostAddress;\r
+    std::cout << "ElevatorClient::PrintResource:" << std::endl;\r
+    std::cout << "Resource URI: " << resource->uri() << std::endl;\r
+    std::cout << "Device URI: " << resource->host() << std::endl;\r
+    std::cout << "Resource Types: " << std::endl;\r
+    for(auto &rt : resource->getResourceTypes())\r
+        std::cout << "   " << rt << std::endl;\r
+    std::cout << "List of resource interfaces: " << std::endl;\r
+    for(auto &ri : resource->getResourceInterfaces())\r
+        std::cout << "   " << ri << std::endl;\r
+    std::cout << std::endl;\r
+#else\r
+    OC_UNUSED(resource);\r
+#endif\r
+}\r
+\r
+// Temporarily store the found resource pointers until their device name is found.\r
+// Key is device URI (e.g., "coap://[fe80::5828:93a8:d53e:4222%7]:62744")\r
+std::map<std::string, std::shared_ptr<OCResource>> OCFDevices;\r
+\r
+void ElevatorClient::OnDeviceInfoCallback(const OCRepresentation& rep)\r
+{\r
+    std::lock_guard<std::recursive_mutex> lock(theMutex);\r
+    std::string deviceName;\r
+    rep.getValue("n", deviceName);\r
+\r
+    if (m_elevatorResource == nullptr && deviceName.compare(m_targetElevatorName) == 0)\r
+    {\r
+        m_elevatorResource = OCFDevices[rep.getHost()];\r
+        OCFDevices.clear(); // free rest of the resources.\r
+        PrintResource(m_elevatorResource);\r
+    }\r
+}\r
+\r
+void ElevatorClient::PrintOCRep(const OCRepresentation& rep)\r
+{\r
+#if (VERBOSE_INFO == 1)\r
+    std::lock_guard<std::recursive_mutex> lock(theMutex);\r
+    std::cout << "++++++++++ PrintOCRep() ++++++++++++" << std::endl;\r
+    std::cout << "For device URI: " << rep.getHost() << std::endl;\r
+    std::cout << "Resoure URI: " << rep.getUri() << std::endl;\r
+    OCRepresentation::const_iterator itr= rep.begin();\r
+    OCRepresentation::const_iterator endItr = rep.end();\r
+    for(;itr!=endItr;++itr)\r
+    {\r
+        std::string value = (*itr).getValue<std::string>();\r
+        std::cout << "   = ElevatorClient:: Attribute name:  " << itr->attrname() << std::endl;\r
+        std::cout << "     ElevatorClient:: Attribute type:  " << itr->type() << std::endl;\r
+        std::cout << "     ElevatorClient:: Attribute value: ";\r
+        switch(itr->type())\r
+        {\r
+            case AttributeType::Null:\r
+            {\r
+                std::cout << "nullptr" << std::endl;\r
+                break;\r
+            }\r
+\r
+            case AttributeType::String:\r
+            {\r
+                std::cout << ((*itr).getValue<std::string>()).c_str() << std::endl;\r
+                break;\r
+            }\r
+\r
+            case AttributeType::Integer:\r
+            {\r
+                std::cout << (*itr).getValue<int>() << std::endl;\r
+                break;\r
+            }\r
+\r
+            default:\r
+            {\r
+                std::cout << "unrecognized type" << std::endl;\r
+                break;\r
+            }\r
+        }\r
+\r
+    }\r
+    std::cout << "---------- PrintOCRep() ------------" << std::endl << std::endl;\r
+#else\r
+    OC_UNUSED(rep);\r
+#endif\r
+}\r
+\r
+void ElevatorClient::OnPlatformInfoCallback(const OCRepresentation& rep)\r
+{\r
+    OC_UNUSED(rep);\r
+    std::lock_guard<std::recursive_mutex> lock(theMutex);\r
+    PrintOCRep(rep);\r
+}\r
+\r
+// Callback to found resources\r
+void ElevatorClient::OnResourceFound(std::shared_ptr<OCResource> resource)\r
+{\r
+    std::lock_guard<std::recursive_mutex> lock(theMutex);\r
+\r
+    // Target elevator already found.\r
+    if (m_elevatorResource != nullptr)\r
+    {\r
+        return;\r
+    }\r
+\r
+    std::vector<std::string> resourceTypes = resource->getResourceTypes();\r
+\r
+    if (resourceTypes.size() != 1)\r
+    {\r
+        return;\r
+    }\r
+\r
+    bool matchTargetResourceType = false;\r
+\r
+    for (auto const& rt : resourceTypes)\r
+    {\r
+        if (rt.compare(ELEVATOR_RESOURCE_TYPE) == 0)\r
+        {\r
+            matchTargetResourceType = true;\r
+            break;\r
+        }\r
+    }\r
+\r
+    if (matchTargetResourceType == false)\r
+    {\r
+        return;\r
+    }\r
+\r
+    if (OCFDevices.find(resource->host()) != OCFDevices.end())\r
+    {\r
+        return;  // have seen this resource from this host.\r
+    }\r
+\r
+    OCFDevices[resource->host()] = resource;\r
+\r
+    // Get the device name for match with m_targetElevatorName.\r
+    OCPlatform::getDeviceInfo(\r
+                    resource->host(),\r
+                    OC_RSRVD_DEVICE_URI,\r
+                    CT_DEFAULT,\r
+                    std::bind(&ElevatorClient::OnDeviceInfoCallback, this, _1));\r
+\r
+\r
+    OCPlatform::getPlatformInfo(\r
+                    resource->host(),\r
+                    OC_RSRVD_PLATFORM_URI,\r
+                    CT_DEFAULT,\r
+                    std::bind(&ElevatorClient::OnPlatformInfoCallback, this, _1));\r
+}\r
+\r
+// each elevator in unit test has unique device name to differentiate it from the others.\r
+bool ElevatorClient::FindElevator(std::string elevatorName)\r
+{\r
+    std::string defaultElevatorResourceType = ELEVATOR_RESOURCE_TYPE;\r
+    std::ostringstream deviceUri;\r
+    m_targetElevatorName = elevatorName;\r
+\r
+    deviceUri << OC_RSRVD_WELL_KNOWN_URI << "?rt=" << defaultElevatorResourceType.c_str();\r
+\r
+    OCConnectivityType connectivityType = CT_ADAPTER_IP;\r
+\r
+    OCStackResult result = OCPlatform::findResource(\r
+                                "",\r
+                                deviceUri.str(),\r
+                                connectivityType,\r
+                                std::bind(&ElevatorClient::OnResourceFound, this, _1));\r
+\r
+    if (result == OC_STACK_OK)\r
+    {\r
+        return true;\r
+    }\r
+    else\r
+    {\r
+        return false;\r
+    }\r
+}\r
+\r
+bool ElevatorClient::IsElevatorFound()\r
+{\r
+    return m_elevatorResource != nullptr;\r
+}\r
+\r
+void ElevatorClient::SetTargetFloor(int targetFloor)\r
+{\r
+    if(m_elevatorResource)\r
+    {\r
+        OCRepresentation rep;\r
+        rep[ELEVATOR_PROPERTY_TARGET_FLOOR] = targetFloor;\r
+\r
+        m_elevatorResource->post(\r
+            rep,\r
+            QueryParamsMap(),\r
+            std::bind(&ElevatorClient::OnPut, this, _1, _2, _3));\r
+\r
+        WaitForCallback();  // wait for completion.\r
+    }\r
+}\r
+\r
+bool ElevatorClient::GetTargetFloor(int* targetFlr)\r
+{\r
+    m_elevatorResource->get(QueryParamsMap(), std::bind(&ElevatorClient::OnGet, this, _1, _2, _3));\r
+    if (WaitForCallback())\r
+    {\r
+        *targetFlr = m_targetFloor;\r
+        return true;\r
+    }\r
+    else\r
+    {\r
+        *targetFlr = -1;\r
+        return false;\r
+    }\r
+}\r
+\r
+bool ElevatorClient::GetCurrentFloor(int* currFloor)\r
+{\r
+    m_elevatorResource->get(QueryParamsMap(), std::bind(&ElevatorClient::OnGet, this, _1, _2, _3));\r
+    if (WaitForCallback())\r
+    {\r
+        *currFloor = m_currentFloor;\r
+        return true;\r
+    }\r
+    else\r
+    {\r
+        *currFloor = -1;\r
+        return false;\r
+    }\r
+}\r
+\r
+bool ElevatorClient::GetDirection(int* dir)\r
+{\r
+    m_elevatorResource->get(QueryParamsMap(), std::bind(&ElevatorClient::OnGet, this, _1, _2, _3));\r
+    if (WaitForCallback())\r
+    {\r
+        *dir = m_direction;\r
+        return true;\r
+    }\r
+    else\r
+    {\r
+        *dir = -1;\r
+        return false;\r
+    }\r
+}\r
index 645984c..1b1e8ad 100644 (file)
@@ -42,18 +42,18 @@ FILE* elevatorServer_fopen(const char *path, const char *mode)
 
 OCPersistentStorage elevatorServerPS = {elevatorServer_fopen, fread, fwrite, fclose, unlink};
 
-static char* ELEVATOR_MAINTENANCE_PATH = "/oic/mnt";
+#define ELEVATOR_MAINTENANCE_PATH   "/oic/mnt"
 
 //
 // Class ElevatorServer implementation.
 //
 ElevatorServer::ElevatorServer() :
-    m_engineThread(),
     m_elevatorResourceHandle(nullptr),
     m_elevatorCOResourceHandle(nullptr),
     m_elevatorMaintenanceHandle(nullptr),
     m_elevatorCreateRelativeResource(nullptr),
-    m_elevatorDeleteResource(nullptr)
+    m_elevatorDeleteResource(nullptr),
+    m_engineThread()
 {
     m_isRunning = false;
     m_targetFloor = m_currentFloor = 1;
@@ -325,16 +325,16 @@ bool ElevatorServer::Start(std::string& elevatorName)
         CopyStringToBuffer(m_name, devName, 256);
         CopyStringToBuffer(resourceTypeName, resTypeName, 256);
         OCStringLL types { nullptr, resTypeName };
-        OCDeviceInfo deviceInfo = { devName, &types, "0.0.1", nullptr };
+        char specVersion[] = "0.0.1";
+        OCDeviceInfo deviceInfo = { devName, &types, specVersion, nullptr };
 
         std::vector<std::string> dataModelVersions = {
                                     ELEVATOR_DATA_MODEL_VERSION_1,
                                     ELEVATOR_DATA_MODEL_VERSION_2,
                                     ELEVATOR_DATA_MODEL_VERSION_3};
 
-
         // Platform Info
-        char* platformId = ELEVATOR_PLATFORM_ID;
+        char platformId[] = ELEVATOR_PLATFORM_ID;
         char manufacturerName[] = "Elevator Manufacturer";
         char manufacturerUrl[] = "http://www.example.com/elevator";
         char modelNumber[] = "Elevator Model Number";