Commit c6a633d6 authored by Way Vadhanasin's avatar Way Vadhanasin Committed by Dave Thaler

IOT-1994 Simplify OCStack public header file requirements

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: default avatarWay Vadhanasin <wayvad@microsoft.com>
(cherry picked from commit 140b6c46)
Reviewed-on: https://gerrit.iotivity.org/gerrit/18869Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarDan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: default avatarPhil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
Reviewed-by: default avatarMats Wichmann <mats@linux.com>
Reviewed-by: default avatarDave Thaler <dthaler@microsoft.com>
parent e65c43b7
......@@ -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>
......
......@@ -27,6 +27,7 @@
#include <chrono>
#include <condition_variable>
#include "iotivity_config.h"
#include "ipca.h"
#include "OCFDevice.h"
......
......@@ -17,6 +17,7 @@
*
******************************************************************/
#include "iotivity_config.h"
#include "oic_malloc.h"
#include "ipca.h"
#include "ipcainternal.h"
......
......@@ -23,6 +23,7 @@
#include <condition_variable>
#include "gtest/gtest.h"
#include "iotivity_config.h"
#include "ocrandom.h"
#include "octypes.h"
#include "ipca.h"
......
......@@ -30,10 +30,6 @@
#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"
......
......@@ -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;
/**
......@@ -1784,11 +1783,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;
/**
......
......@@ -17,6 +17,8 @@
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "iotivity_config.h"
#include <iostream>
#include <sstream>
#include <limits>
......
......@@ -17,6 +17,7 @@
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "iotivity_config.h"
#include <iostream>
#include "octypes.h"
#include "ocstack.h"
......
......@@ -17,6 +17,7 @@
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "iotivity_config.h"
#include "rd_server.h"
#include "rd_database.h"
......
......@@ -20,6 +20,7 @@
extern "C"
{
#include "iotivity_config.h"
#include "rd_client.h"
#include "rd_server.h"
#include "ocpayload.h"
......
......@@ -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");
......
......@@ -2494,7 +2494,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;
......@@ -2558,7 +2559,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;
......
......@@ -381,7 +381,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;
......
......@@ -18,6 +18,7 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "iotivity_config.h"
#include <stdlib.h>
#include <string.h>
#include "oic_malloc.h"
......
......@@ -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;
......
......@@ -18,6 +18,8 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "iotivity_config.h"
#include <stdlib.h>
#include <string.h>
......
......@@ -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)
......
......@@ -18,8 +18,8 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <ocstack.h>
#include "iotivity_config.h"
#include "ocstack.h"
#include <stdio.h>
#include <stdlib.h>
......
......@@ -19,7 +19,8 @@
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <ocstack.h>
#include "iotivity_config.h"
#include "ocstack.h"
#include <stdio.h>
#include <string.h>
......
......@@ -18,6 +18,7 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "iotivity_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......
......@@ -19,6 +19,7 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "iotivity_config.h"
#include <stdio.h>
#include <glib.h>
#include <stdlib.h>
......
......@@ -31,6 +31,7 @@
#include <functional>
#endif
#include "iotivity_config.h"
#include "iotivity_debug.h"
#include "octypes.h"
......
......@@ -28,6 +28,7 @@
#include "OCApi.h"
#include "OCPlatform_impl.h"
#include "oxmverifycommon.h"
#include "securevirtualresourcetypes.h"
namespace OC
{
......
......@@ -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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment