# Set common flags
if env['CC'] == 'cl':
- # C4244 conversion from one type to another type results in a possible loss of data.
- # C4267 conversion from size_t to a smaller type.
- # C4355 'this' used in base member initializer list.
- # C4800 forcing value to bool 'true' or 'false'.
- # C4996 deprecated declaration.
- # C4820 added padding to the end of a struct.
- # C4514 unreferenced inline function has been removed
- # C4365 signed/unsigned mismatch
- # C4503 decorated name length exceeded, name was truncated
- env.AppendUnique(CXXFLAGS=['/wd4244', '/wd4267', '/wd4355', '/wd4800', '/wd4996', '/wd4820', '/wd4514', '/wd4365', '/wd4503'])
- env.AppendUnique(CCFLAGS=['/EHsc'])
- vs_version = env['MSVC_VERSION']
+ # TODO: re-enable warnings, especially: 4244, 4267, 4365
+ env.AppendUnique(CXXFLAGS=[
+ '/wd4244', # C4244 conversion from one type to another type results in a possible loss of data.
+ '/wd4267', # C4267 conversion from size_t to a smaller type.
+ '/wd4355', # C4355 'this' used in base member initializer list.
+ '/wd4800', # C4800 forcing value to bool 'true' or 'false'.
+ '/wd4996', # C4996 deprecated declaration.
+ '/wd4820', # C4820 added padding to the end of a struct.
+ '/wd4514', # C4514 unreferenced inline function has been removed
+ '/wd4365', # C4365 signed/unsigned mismatch
+ '/wd4503']) # C4503 decorated name length exceeded, name was truncated
- # Enable special exports for unit test purposes
- if env.get('TEST') == '1':
- env.AppendUnique(CPPDEFINES = ['ENABLE_TEST_EXPORTS'])
- # Set release/debug flags
- if env.get('RELEASE'):
- env.AppendUnique(CCFLAGS = ['/MD', '/O2', '/GF'])
- env.AppendUnique(CPPDEFINES = ['NDEBUG'])
- elif env.get('TARGET_ARCH') in ['x86', 'x86_64'] or "14.0" in vs_version:
- env.AppendUnique(CCFLAGS = ['/MDd', '/Od', '/ZI', '/RTC1', '/Gm'])
- env.AppendUnique(LINKFLAGS = ['/debug'])
- else:
- env.AppendUnique(CCFLAGS = ['/MDd', '/Od', '/Zi', '/RTC1', '/Gm'])
- env.AppendUnique(LINKFLAGS = ['/debug'])
- env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
- env.AppendUnique(PATH = os.environ['PATH'])
+ env.AppendUnique(CCFLAGS=['/EHsc'])
+
+ vs_version = env['MSVC_VERSION']
+
+ # Enable special exports for unit test purposes
+ if env.get('TEST') == '1':
+ env.AppendUnique(CPPDEFINES = ['ENABLE_TEST_EXPORTS'])
+ # Set release/debug flags
+ if env.get('RELEASE'):
+ env.AppendUnique(CCFLAGS = ['/MD', '/O2', '/GF'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+ elif env.get('TARGET_ARCH') in ['x86', 'x86_64'] or "14.0" in vs_version:
+ env.AppendUnique(CCFLAGS = ['/MDd', '/Od', '/ZI', '/RTC1', '/Gm'])
+ env.AppendUnique(LINKFLAGS = ['/debug'])
+ else:
+ env.AppendUnique(CCFLAGS = ['/MDd', '/Od', '/Zi', '/RTC1', '/Gm'])
+ env.AppendUnique(LINKFLAGS = ['/debug'])
+ env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+ env.AppendUnique(PATH = os.environ['PATH'])
elif env['CC'] == 'gcc':
- print "\nError: gcc not supported on Windows. Use Visual Studio!\n"
- Exit(1);
+ print "\nError: gcc not supported on Windows. Use Visual Studio!\n"
+ Exit(1);
int initThread()
{
- int res;
-
- res = pthread_create(&thread_id, NULL, loop, NULL);
+ int res = pthread_create(&thread_id, NULL, loop, NULL);
if (res)
{
currentTime = (TIME_IN_MS == precision) ? millis() : micros();
#elif defined(_WIN32)
FILETIME fileTime;
- ULARGE_INTEGER time;
GetSystemTimePreciseAsFileTime(&fileTime);
// fileTime should now be a QWORD hundred-nanoseconds time since 1601
// MSDN recommends using ULARGE_INTEGER as an intermediate representation for math.
- time.LowPart = fileTime.dwLowDateTime;
- time.HighPart = fileTime.dwHighDateTime;
+ ULARGE_INTEGER time = { .LowPart = fileTime.dwLowDateTime,
+ .HighPart = fileTime.dwHighDateTime };
currentTime =
(TIME_IN_MS == precision)
#if (__cplusplus >=201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__)
- #define SUPPORTS_DEFAULT_CTOR
+# define SUPPORTS_DEFAULT_CTOR
#endif
#if (__STDC_VERSION__ >= 201112L)
- #include <assert.h>
- #define OC_STATIC_ASSERT(condition, msg) static_assert(condition, msg)
+# include <assert.h>
+# define OC_STATIC_ASSERT(condition, msg) static_assert(condition, msg)
#elif defined(_WIN32)
- #if defined(__msys_nt__) && !defined(__cplusplus)
- #define static_assert _Static_assert
- #endif
- #define OC_STATIC_ASSERT(condition, msg) static_assert(condition, msg)
+# if defined(__msys_nt__) && !defined(__cplusplus)
+# define static_assert _Static_assert
+# endif
+# define OC_STATIC_ASSERT(condition, msg) static_assert(condition, msg)
#else
- #define OC_STATIC_ASSERT(condition, msg) ((void)sizeof(char[2*!!(condition) - 1]))
+# define OC_STATIC_ASSERT(condition, msg) ((void)sizeof(char[2*!!(condition) - 1]))
#endif
#ifndef INLINE_API
/** @todo: Add Microsoft license information */
-#ifndef __GETOPT_H__
-#define __GETOPT_H__
+#ifndef GETOPT_H__
+#define GETOPT_H__
#ifdef __cplusplus
extern "C" {
/** @todo: Add Microsoft license information */
-#ifndef __PTHREAD_CREATE_H__
-#define __PTHREAD_CREATE_H__
+#ifndef PTHREAD_CREATE_H__
+#define PTHREAD_CREATE_H__
#ifndef WIN_PTHREADS_H
#ifdef __cplusplus
*
******************************************************************/
-#ifndef __VS12_SNPRINTF_H__
-#define __VS12_SNPRINTF_H__
+#ifndef VS12_SNPRINTF_H__
+#define VS12_SNPRINTF_H__
+
+#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
-#include <stdlib.h>
-
int vs12_snprintf(char *buffer, size_t count, const char *format, ...);
#if defined(_MSC_VER) && (_MSC_VER < 1900)
*
******************************************************************/
-#ifndef __WIN_SLEEP_H__
-#define __WIN_SLEEP_H__
+#ifndef WIN_SLEEP_H__
+#define WIN_SLEEP_H__
#include <time.h>
#include "getopt.h"
#include <windows.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
char* optarg = NULL;
int optind = 1;
int opt = argv[optind][1];
const char *p = strchr(optstring, opt);
- if (p == NULL) {
+ if (p == NULL)
+ {
return '?';
}
- if (p[1] == ':') {
+ if (p[1] == ':')
+ {
optind++;
- if (optind >= argc) {
+ if (optind >= argc)
+ {
return '?';
}
optarg = argv[optind];
return opt;
}
-#ifdef __cplusplus
-}
-#endif
-
int vs12_snprintf(char *buffer, size_t count, const char *format, ...)
{
- int length;
va_list args;
va_start(args, format);
- length = _vsnprintf(buffer, count, format, args);
+ int length = _vsnprintf(buffer, count, format, args);
va_end(args);
#include <assert.h>
#include <windows.h>
+#include <errno.h>
#include "win_sleep.h"
+#include "logger.h"
+#define TAG "WIN_SLEEP"
+
#define NS_PER_MS (1000000)
#define US_PER_MS (1000)
+#define ASSERT_AND_FAIL(EXPRESSION) { \
+ assert((EXPRESSION)); \
+ if (!(EXPRESSION)) \
+ { \
+ errno = EINVAL; \
+ return -1; \
+ } \
+}
+
int usleep(unsigned int usec)
{
assert((usec % US_PER_MS) == 0); // granularity check
- Sleep(usec / US_PER_MS);
+ Sleep((usec + US_PER_MS - 1) / US_PER_MS);
return 0;
}
int nanosleep(const struct timespec *req, struct timespec *rem)
{
- assert(req != NULL);
- assert(rem == NULL);
- assert(req->tv_sec == 0);
+ if (req == NULL)
+ {
+ OIC_LOG(DEBUG, TAG, "nanosleep: req param should not be null");
+ }
+ ASSERT_AND_FAIL(req != NULL);
+ ASSERT_AND_FAIL(rem == NULL);
+ ASSERT_AND_FAIL(req->tv_sec == 0);
assert((req->tv_nsec % NS_PER_MS) == 0); // granularity check
- Sleep(req->tv_nsec / NS_PER_MS);
+ Sleep((req->tv_nsec + NS_PER_MS - 1) / NS_PER_MS);
return 0;
}
*/
typedef char *CAToken_t;
-/**
+/*
* Socket types and error definitions
*/
#ifdef HAVE_WINSOCK2_H
typedef int CASocketFd_t;
#endif
-/** The following flags are the same as the equivalent OIC values in
+/*
+ * The following flags are the same as the equivalent OIC values in
* octypes.h, allowing direct copying with slight fixup.
* The CA layer should used the OC types when build allows that.
*/
#ifdef RA_ADAPTER
#define MAX_ADDR_STR_SIZE_CA (256)
#else
-/** Max Address could be "coap+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
+/*
+ * Max Address could be "coap+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
* Which is 64, +1 for null terminator => 65
* OCDevAddr (defined in OCTypes.h) must be the same
* as CAEndpoint_t (defined here)
#define TAG "IP_MONITOR"
-/** @todo Implement network interface monitoring in case the IP changes.
+/**
+ * @todo Implement network interface monitoring in case the IP changes.
* Not critical for win32 bring-up.
*/
CAResult_t CAIPStartNetworkMonitor()
return CA_STATUS_OK;
}
-/** @todo Implement network interface monitoring in case the IP changes.
+/**
+ * @todo Implement network interface monitoring in case the IP changes.
* Not critical for win32 bring-up.
*/
CAResult_t CAIPStopNetworkMonitor()
return CA_STATUS_OK;
}
-/** @todo Implement network interface monitoring.
- * Not used in win32, but caipserver currently requires this function
- * be defined. not critical.
+/**
+ * @todo Implement network interface monitoring.
+ * Not used in win32, but caipserver currently requires this function
+ * be defined. not critical.
*/
int CAGetPollingInterval(int interval)
{
return interval;
}
-/** @todo Implement network interface monitoring.
- * Not used in win32, but caipserver currently requires this function
- * be defined. not critical.
+/**
+ * @todo Implement network interface monitoring.
+ * Not used in win32, but caipserver currently requires this function
+ * be defined. not critical.
*/
CAInterface_t *CAFindInterfaceChange()
{
return foundNewInterface;
}
-/** @todo Implement network interface monitoring.
+/**
+ * @todo Implement network interface monitoring.
* Not critical for win32 bring-up.
*/
void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback)
OIC_LOG_V(DEBUG, RM_TAG, "createoption dlen %u slen [%u]", dLen, sLen);
unsigned int totalLength = 0;
-#if defined(_MSC_VER)
- char *tempData = NULL;
-#else
- void *tempData = NULL;
-#endif
+ uint8_t *tempData = NULL;
+
if (0 == dLen && 0 == sLen)
{
OIC_LOG(DEBUG, RM_TAG, "Source and destination is not present");
#ifndef IOTVT_SRM_RSRC_STRINGS_H
#define IOTVT_SRM_RSRC_STRINGS_H
+#include "securevirtualresourcetypes.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-#include "securevirtualresourcetypes.h"
-
extern const char * SVR_DB_FILE_NAME;
extern const char * SVR_DB_DAT_FILE_NAME;
extern const char * OIC_MI_DEF;
OCStackResult PMTimeout(unsigned short waittime, bool waitForStackResponse)
{
OCStackResult res = OC_STACK_OK;
- uint64_t startTime;
- uint64_t currTime;
- startTime = OICGetCurrentTime(TIME_IN_MS);
+ uint64_t startTime = OICGetCurrentTime(TIME_IN_MS);
while (OC_STACK_OK == res)
{
- currTime = OICGetCurrentTime(TIME_IN_MS);
+ uint64_t currTime = OICGetCurrentTime(TIME_IN_MS);
long elapsed = (long)((currTime - startTime) / MS_PER_SEC);
if (elapsed > waittime)
\r
int clock_res = -1;\r
#if defined(_MSC_VER)\r
- time_t startTime;\r
+ time_t startTime = NULL;\r
clock_res = (time(&startTime) == -1);\r
#else\r
struct timespec startTime = {.tv_sec=0, .tv_nsec=0};\r
while (1)\r
{\r
#if defined(_MSC_VER)\r
- time_t currTime;\r
+ time_t currTime = NULL;\r
clock_res = (time(&currTime) == -1);\r
#else\r
struct timespec currTime = {.tv_sec=0, .tv_nsec=0};\r
static const char BYDAY[] = "BYDAY";
static const char DAILY[] = "DAILY";
-/**
- * Parses periodStr and populate struct IotvtICalPeriod_t
- *
- * @param periodStr string to be parsed.
- * @param period IotvtICalPeriod_t struct to be populated.
- *
- * @return IOTVTICAL_INVALID_PARAMETER -- if parameter are invalid
- * IOTVTICAL_INVALID_PERIOD -- if period string has invalid format
- * IOTVTICAL_INVALID_SUCCESS -- if no error while parsing
- */
IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period)
{
if ((NULL == periodStr) || (NULL == period))
char * strptime(const char *buf, const char *fmt, struct tm *tm)
{
- char c;
int temp = 0;
+ char c = '\0';
+
+ //check params
+ if ((fmt == NULL) || (tm == NULL))
+ {
+ return NULL;
+ }
//initialize the tm struct values
memset(tm, 0, sizeof(struct tm));
#elif defined(HAVE_WINDOWS_H)
- #include <Windows.h>
+ #include <windows.h>
CRITICAL_SECTION lock;
#define MUTEX_LOCK(ARG_NAME) { EnterCriticalSection(ARG_NAME); }
#define MUTEX_UNLOCK(ARG_NAME) { LeaveCriticalSection(ARG_NAME); }
/// (properties and methods) and host this resource on the server.
///
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <functional>
#include <pthread.h>
#include "OCApi.h"
#ifdef HAVE_WINDOWS_H
-#include <Windows.h>
+#include <windows.h>
#endif
#include "platform_features.h"
#include "OCPlatform.h"
#include "OCApi.h"
-#if defined(__msys_nt__)
-#include <Windows.h>
-#define sleep(x) Sleep(1000*x)
+#if defined(HAVE_WINDOWS_H)
+#include <windows.h>
#endif
+#include "platform_features.h"
using namespace OC;
}
#if defined(_WIN32)
- DWORD threadId;
- HANDLE threadHandle;
+ DWORD threadId = 0;
+ HANDLE threadHandle = INVALID_HANDLE_VALUE;
#else
pthread_t threadId;
#endif
#include "OCApi.h"
#ifdef HAVE_WINDOWS_H
-#include <Windows.h>
+#include <windows.h>
#endif
#include "platform_features.h"
#include "OCApi.h"
#ifdef HAVE_WINDOWS_H
-#include <Windows.h>
+#include <windows.h>
#endif
#include "platform_features.h"
#include <iterator>
#if defined(_MSC_VER)
#include <functional>
-//Squelch "decorated name length exceeded, name was truncated"
-// This compensates for templates full of templates
-#pragma warning(disable : 4503)
#endif
#include "octypes.h"
#ifndef OC_REPRESENTATION_H_
#define OC_REPRESENTATION_H_
-#define GCC_VERSION (__GNUC__ * 10000 \
- + __GNUC_MINOR__ * 100 \
- + __GNUC_PATCHLEVEL__)
-
#include <string>
#include <sstream>
#include <vector>
// Enable-if required to prevent conversions to alternate types. This prevents
// ambigious conversions in the case where conversions can include a number of
// types, such as the string constructor.
-#if (defined(_MSC_VER) ) || (defined(__GNUC__) && (GCC_VERSION <= 50000))
+#if (defined(_MSC_VER) ) || (defined(__GNUC__) && (__GNUC__ <= 5))
template<typename T, typename std::enable_if<
std::is_same<T, int>::value ||
std::is_same<T, double>::value ||
ClientCallbackContext::ListenContext* context =
new ClientCallbackContext::ListenContext(callback, shared_from_this());
OCCallbackData cbdata;
- cbdata.context = (void*)context;
+ cbdata.context = static_cast<void*>(context),
cbdata.cb = listenCallback;
cbdata.cd = [](void* c){delete (ClientCallbackContext::ListenContext*)c;};
new ClientCallbackContext::DeviceListenContext(callback, shared_from_this());
OCCallbackData cbdata;
- cbdata.context = (void*)context;
+ cbdata.context = static_cast<void*>(context),
cbdata.cb = listenDeviceCallback;
cbdata.cd = [](void* c){delete (ClientCallbackContext::DeviceListenContext*)c;};
ClientCallbackContext::GetContext* ctx =
new ClientCallbackContext::GetContext(callback);
OCCallbackData cbdata;
- cbdata.context = (void*)ctx;
+ cbdata.context = static_cast<void*>(ctx),
cbdata.cb = getResourceCallback;
cbdata.cd = [](void* c){delete (ClientCallbackContext::GetContext*)c;};
{
if (!uri.empty())
{
- if(uri.back() == '/')
+ if (uri.back() == '/')
{
- uri.resize(uri.size()-1);
+ uri.resize(uri.size() - 1);
}
}
paramsList << '?';
}
- for(auto& param : queryParams)
+ for (auto& param : queryParams)
{
paramsList << param.first <<'='<<param.second<<';';
}
std::string queryString = paramsList.str();
- if(queryString.empty())
+ if (queryString.empty())
{
return uri;
}
OCStackResult result;
ClientCallbackContext::SetContext* ctx = new ClientCallbackContext::SetContext(callback);
OCCallbackData cbdata;
- cbdata.context = (void*)ctx;
+ cbdata.context = static_cast<void*>(ctx),
cbdata.cb = setResourceCallback;
cbdata.cd = [](void* c){delete (ClientCallbackContext::SetContext*)c;};
OCStackResult result;
ClientCallbackContext::SetContext* ctx = new ClientCallbackContext::SetContext(callback);
OCCallbackData cbdata;
- cbdata.context = (void*)ctx;
+ cbdata.context = static_cast<void*>(ctx),
cbdata.cb = setResourceCallback;
cbdata.cd = [](void* c){delete (ClientCallbackContext::SetContext*)c;};
ClientCallbackContext::DeleteContext* ctx =
new ClientCallbackContext::DeleteContext(callback);
OCCallbackData cbdata;
- cbdata.context = (void*)ctx;
+ cbdata.context = static_cast<void*>(ctx),
cbdata.cb = deleteResourceCallback;
cbdata.cd = [](void* c){delete (ClientCallbackContext::DeleteContext*)c;};
ClientCallbackContext::ObserveContext* ctx =
new ClientCallbackContext::ObserveContext(callback);
OCCallbackData cbdata;
- cbdata.context = (void*)ctx;
+ cbdata.context = static_cast<void*>(ctx),
cbdata.cb = observeResourceCallback;
cbdata.cd = [](void* c){delete (ClientCallbackContext::ObserveContext*)c;};
ClientCallbackContext::SubscribePresenceContext* ctx =
new ClientCallbackContext::SubscribePresenceContext(presenceHandler);
OCCallbackData cbdata;
- cbdata.context = (void*)ctx;
+ cbdata.context = static_cast<void*>(ctx),
cbdata.cb = subscribePresenceCallback;
cbdata.cd = [](void* c){delete (ClientCallbackContext::SubscribePresenceContext*)c;};
break;
case AttributeType::String:
OCRepPayloadSetPropString(root, val.attrname().c_str(),
- (static_cast<std::string>(val)).c_str());
+ static_cast<std::string>(val).c_str());
break;
case AttributeType::OCRepresentation:
OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
- (static_cast<OCRepresentation>(val)).getPayload());
+ static_cast<OCRepresentation>(val).getPayload());
break;
case AttributeType::Vector:
getPayloadArray(root, val);
* This internal method is the entity handler for RD resources and
* will handle REST request (GET/PUT/POST/DEL) for them.
*/
-#ifdef _MSC_VER
static OCEntityHandlerResult rdEntityHandler(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest *ehRequest, void *callbackParameter)
-#else
-static OCEntityHandlerResult rdEntityHandler(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest *ehRequest, __attribute__((unused)) void *callbackParameter)
-#endif
+ OCEntityHandlerRequest *ehRequest, OC_ANNOTATE_UNUSED void *callbackParameter)
{
OCEntityHandlerResult ehRet = OC_EH_ERROR;