IOT-1994 Simplify OCStack public header file requirements
authorWay Vadhanasin <wayvad@microsoft.com>
Wed, 12 Apr 2017 05:44:54 +0000 (22:44 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Thu, 13 Apr 2017 02:32:26 +0000 (02:32 +0000)
Applications that need to include ocstack.h for access to OC* APIs currently need to bring in
multiple unrelated (and platform-specific) headers. This is because octypes.h, a public type
definition header used by ocstack.h, is including more headers than it needs to. It is more
desirable for applications to bring in only requird headers.

This change reduces the number of required headers from the public surface, specifically ocstack.h,
by taking advantange of IoTivity's requirement that all supported compilers are at least
C++11-compliant. See https://wiki.iotivity.org/compiler_support?s[]=compiler for details.

Before this change, users of ocstack.h must also bring in (this example is from Windows):

    Ocstack.h
    Octypes.h
    Iotivity_config.h
    Ocpresence.h
    Ocstackconfig.h
    Platform_features.h
    Windows\include\memmem.h
    Windows\include\pthread_create.h
    Windows\include\vs12_snprintf.h
    Windows\include\win_sleep.h

After this change, the list becomes:

    Ocstack.h
    Octypes.h
    Ocpresence.h
    Ocstackconfig.h

Arguably ocpresence.h and ocstackconfig.h could be combined into octypes.h since they are just
simple type definitions, just like octypes.h. That work is lower priority as both ocpresence.h
and ocstackconfig.h are already platform independent.

Change-Id: I9943589603453730446b2d616b497fbb235774a5
Signed-off-by: Way Vadhanasin <wayvad@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18487
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
22 files changed:
plugins/samples/linux/IotivityandZigbeeClient.c
resource/IPCA/samples/ElevatorClient/ElevatorClient.cpp
resource/IPCA/src/ipca.cpp
resource/IPCA/unittests/IPCAElevatorClient.cpp
resource/c_common/platform_features.h
resource/csdk/include/octypes.h
resource/csdk/resource-directory/samples/rd_publishingClient.cpp
resource/csdk/resource-directory/samples/rd_queryClient.cpp
resource/csdk/resource-directory/unittests/rdtests.cpp
resource/csdk/security/provisioning/src/multipleownershiptransfermanager.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/provisioning/src/secureresourceprovider.c
resource/csdk/security/src/amaclresource.c
resource/csdk/security/src/directpairing.c
resource/csdk/security/src/pstatresource.c
resource/csdk/security/unittest/srmtestcommon.cpp
resource/csdk/stack/samples/linux/OCSample/occlient.c
resource/csdk/stack/samples/linux/OCSample/ocserver.c
resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp
resource/include/OCApi.h
resource/include/OCProvisioningManager.hpp
resource/src/OCRepresentation.cpp

index 2c39b90..04e061d 100644 (file)
@@ -25,6 +25,7 @@
 // except for resource-specific IoTivity APIs (ie. OCCreateResource(),
 // OCDeleteResource(), EntityHandler()..etc.)
 
+#include "iotivity_config.h"
 #include "IotivityandZigbeeClient.h"
 #include <stdio.h>
 #include <stdlib.h>
index 19771e2..8d91f83 100644 (file)
@@ -27,6 +27,7 @@
 #include <chrono>
 #include <condition_variable>
 
+#include "iotivity_config.h"
 #include "ipca.h"
 #include "OCFDevice.h"
 
index 33840ab..c462092 100644 (file)
@@ -17,6 +17,7 @@
  *
  ******************************************************************/
 
+#include "iotivity_config.h"
 #include "oic_malloc.h"
 #include "ipca.h"
 #include "ipcainternal.h"
index 6aa6986..d77131f 100644 (file)
@@ -23,6 +23,7 @@
 #include <condition_variable>
 
 #include "gtest/gtest.h"
+#include "iotivity_config.h"
 #include "ocrandom.h"
 #include "octypes.h"
 #include "ipca.h"
index fbd2dd8..221a2e8 100644 (file)
 #define PLATFORM_FEATURES_H_
 
 
-#if (__cplusplus >=201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__)
-#  define SUPPORTS_DEFAULT_CTOR
-#endif
-
 #if (__STDC_VERSION__ >= 201112L)
 #  include <assert.h>
 #  define OC_STATIC_ASSERT(condition, msg) static_assert(condition, msg)
@@ -74,9 +70,6 @@
 #  define ssize_t SSIZE_T
 #  define SHUT_RDWR           SD_BOTH
 #  define sleep(SECS)         Sleep(1000*(SECS))
-#  ifdef __cplusplus
-#    define SUPPORTS_DEFAULT_CTOR
-#  endif
 #  include "windows/include/memmem.h"
 #  include "windows/include/win_sleep.h"
 #  include "windows/include/pthread_create.h"
index 524dad6..138dedb 100644 (file)
@@ -28,7 +28,6 @@
 #ifndef OCTYPES_H_
 #define OCTYPES_H_
 
-#include "iotivity_config.h"
 #include "ocstackconfig.h"
 #include <stdbool.h>
 #include <stdint.h>
@@ -1250,7 +1249,7 @@ typedef struct OCHeaderOption
     /** pointer to its data.*/
     uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
 
-#ifdef SUPPORTS_DEFAULT_CTOR
+#ifdef __cplusplus
     OCHeaderOption() = default;
     OCHeaderOption(OCTransportProtocolID pid,
                    uint16_t optId,
@@ -1267,7 +1266,7 @@ typedef struct OCHeaderOption
         memcpy(optionData, optData, optionLength);
         optionData[optionLength - 1] = '\0';
     }
-#endif
+#endif // __cplusplus
 } OCHeaderOption;
 
 /**
@@ -1776,11 +1775,11 @@ typedef struct OCCallbackData
     /** A pointer to a function to delete the context when this callback is removed.*/
     OCClientContextDeleter cd;
 
-#ifdef SUPPORTS_DEFAULT_CTOR
+#ifdef __cplusplus
     OCCallbackData() = default;
     OCCallbackData(void* ctx, OCClientResponseHandler callback, OCClientContextDeleter deleter)
         :context(ctx), cb(callback), cd(deleter){}
-#endif
+#endif // __cplusplus
 } OCCallbackData;
 
 /**
index 851bcd5..6a5be55 100644 (file)
@@ -17,6 +17,8 @@
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "iotivity_config.h"
 #include <iostream>
 #include <sstream>
 #include <limits>
index bec0415..2785c5b 100644 (file)
@@ -17,6 +17,7 @@
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include "iotivity_config.h"
 #include <iostream>
 #include "octypes.h"
 #include "ocstack.h"
index 35c5f54..1ed5e3b 100644 (file)
@@ -20,6 +20,7 @@
 
 extern "C"
 {
+    #include "iotivity_config.h"
     #include "rd_client.h"
     #include "rd_server.h"
     #include "ocpayload.h"
index 569e0bd..149bf4e 100644 (file)
@@ -174,7 +174,8 @@ static OCStackResult MOTSendPostDoxm(void *ctx,
     VERIFY_NOT_NULL(TAG, motCtx->ctxResultArray, ERROR);
 
     //Send POST request
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData;
+    memset(&cbData, 0, sizeof(cbData));
     cbData.cb = &MOTUpdateSecurityResourceCB;
     cbData.context = (void *)motCtx;
     OIC_LOG(DEBUG, TAG, "Sending POST 'doxm' request to resource server");
@@ -448,7 +449,8 @@ OCStackResult MOTProvisionPreconfigPIN(void *ctx, const OCProvisionDev_t *target
     VERIFY_NOT_NULL(TAG, motCtx->ctxResultArray, ERROR);
 
     //Send POST request
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData;
+    memset(&cbData, 0, sizeof(cbData));
     cbData.cb = &MOTUpdateSecurityResourceCB;
     cbData.context = (void *)motCtx;
     OIC_LOG(DEBUG, TAG, "Sending POST Preconfiged PIN credenatial request to resource server");
index 808b639..5d5faae 100644 (file)
@@ -2462,7 +2462,8 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData;
+    memset(&cbData, 0, sizeof(cbData));
     cbData.cb = &ProvisioningStatusHandler;
     cbData.context = (void*)otmCtx;
     cbData.cd = NULL;
@@ -2522,7 +2523,8 @@ OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx)
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData;
+    memset(&cbData, 0, sizeof(cbData));
     cbData.cb = &ReadyForNomalStatusHandler;
     cbData.context = (void*)otmCtx;
     cbData.cd = NULL;
index d2db735..b36bc79 100644 (file)
@@ -390,7 +390,8 @@ static OCStackResult provisionCredentials(OicSecCred_t *cred,
         }
         OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-        OCCallbackData cbData = { .context = NULL, .cb = NULL, .cd = NULL };
+        OCCallbackData cbData;
+        memset(&cbData, 0, sizeof(cbData));
         cbData.cb = responseHandler;
         cbData.context = (void *)credData;
         cbData.cd = NULL;
index 8d2238f..eb5fee1 100644 (file)
@@ -18,6 +18,7 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include "iotivity_config.h"
 #include <stdlib.h>
 #include <string.h>
 #include "oic_malloc.h"
index 4c1ad97..f36c3d4 100644 (file)
@@ -496,7 +496,8 @@ OCStackResult FinalizeDirectPairing(void *ctx, OCDirectPairingDev_t* peer,
     dpairData->resultCallback = resultCallback;
     dpairData->userCtx = ctx;
 
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData;
+    memset(&cbData, 0, sizeof(cbData));
     cbData.cb = DirectPairingFinalizeHandler;
     cbData.context = (void*)dpairData;
     cbData.cd = NULL;
@@ -754,7 +755,8 @@ OCStackResult DPDirectPairing(void *ctx, OCDirectPairingDev_t* peer, OicSecPrm_t
     dpairData->resultCallback = resultCallback;
     dpairData->userCtx = ctx;
 
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData;
+    memset(&cbData, 0, sizeof(cbData));
     cbData.cb = DirectPairingHandler;
     cbData.context = (void*)dpairData;
     cbData.cd = NULL;
index e127112..20662dd 100644 (file)
@@ -18,6 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include "iotivity_config.h"
+
 #include <stdlib.h>
 #include <string.h>
 
index ab592d0..7a554ea 100644 (file)
@@ -23,6 +23,7 @@
 #include "ocstack.h"
 #include <stdlib.h>
 #include "cbor.h"
+#include "platform_features.h"
 
 #define STRINGIZE2(x) #x
 #define STRINGIZE(x) STRINGIZE2(x)
index 7bb976a..d97e170 100644 (file)
@@ -18,8 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-
-#include <ocstack.h>
+#include "iotivity_config.h"
+#include "ocstack.h"
 
 #include <stdio.h>
 #include <stdlib.h>
index ad07637..a087b6b 100644 (file)
@@ -19,7 +19,8 @@
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 
-#include <ocstack.h>
+#include "iotivity_config.h"
+#include "ocstack.h"
 
 #include <stdio.h>
 #include <string.h>
index ef6d77f..46ef9f0 100644 (file)
@@ -19,6 +19,7 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include "iotivity_config.h"
 #include <stdio.h>
 #include <glib.h>
 #include <stdlib.h>
index c8250e5..4e14f29 100644 (file)
@@ -31,6 +31,7 @@
 #include <functional>
 #endif
 
+#include "iotivity_config.h"
 #include "iotivity_debug.h"
 
 #include "octypes.h"
index f7f6bb3..9165310 100644 (file)
@@ -28,6 +28,7 @@
 #include "OCApi.h"
 #include "OCPlatform_impl.h"
 #include "oxmverifycommon.h"
+#include "securevirtualresourcetypes.h"
 
 namespace OC
 {
index a1c887f..76002c4 100644 (file)
@@ -31,6 +31,7 @@
 #include <boost/lexical_cast.hpp>
 #include <algorithm>
 #include <iomanip>
+#include "iotivity_config.h"
 #include "ocpayload.h"
 #include "ocrandom.h"
 #include "oic_malloc.h"