# if defined(__cplusplus)
# define INLINE_API inline
# else
-# ifdef _WIN32
+# ifdef _MSC_VER
# define INLINE_API static __inline
# else
# define INLINE_API static inline
extern "C" {
#endif
+#include <stdlib.h>
+
int vs12_snprintf(char *buffer, size_t count, const char *format, ...);
#if defined(_MSC_VER) && (_MSC_VER < 1900)
extern "C" {
#endif
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+struct timespec
+{
+ time_t tv_sec; // Seconds - >= 0
+ long tv_nsec; // Nanoseconds - [0, 999999999]
+};
+#endif
+
int nanosleep(const struct timespec *req, struct timespec *rem);
int usleep(unsigned int usec);
#include <errno.h>
#include <assert.h>
#include <oic_malloc.h>
+#include "platform_features.h"
#include "camutex.h"
#include "logger.h"
}addr;
}coap_address_t;
-static inline int
+INLINE_API int
_coap_address_equals_impl(const coap_address_t *a,
const coap_address_t *b)
{
return 0;
}
-static inline int
+INLINE_API int
_coap_is_mcast_impl(const coap_address_t *a)
{
if (!a)
uint8_t addr[DEV_ADDR_SIZE_MAX]; /**< device address. */
} coap_address_t;
-static inline int
+INLINE_API int
_coap_address_equals_impl(const coap_address_t *a,
const coap_address_t *b)
{
return 1;
}
-static inline int
+INLINE_API int
_coap_is_mcast_impl(const coap_address_t *a)
{
if (!a)
*
* @param addr The coap_address_t object to initialize.
*/
-static inline void coap_address_init(coap_address_t *addr)
+INLINE_API void coap_address_init(coap_address_t *addr)
{
assert(addr);
memset(addr, 0, sizeof(coap_address_t));
* @c 1 if addresses are equal, @c 0 otherwise. The parameters @p a
* and @p b must not be @c NULL;
*/
-static inline int coap_address_equals(const coap_address_t *a, const coap_address_t *b)
+INLINE_API int coap_address_equals(const coap_address_t *a, const coap_address_t *b)
{
assert(a);
assert(b);
* Checks if given address @p a denotes a multicast address. This
* function returns @c 1 if @p a is multicast, @c 0 otherwise.
*/
-static inline int coap_is_mcast(const coap_address_t *a)
+INLINE_API int coap_is_mcast(const coap_address_t *a)
{
return a && _coap_is_mcast_impl(a);
}
*
* @param s The state object to update.
*/
-static inline void coap_touch_async(coap_async_state_t *s)
+INLINE_API void coap_touch_async(coap_async_state_t *s)
{
coap_ticks(&s->created);
}
*
* @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
*/
-inline static int bits_setb(uint8_t *vec, size_t size, uint8_t bit)
+INLINE_API int bits_setb(uint8_t *vec, size_t size, uint8_t bit)
{
if (size <= (size_t)(bit >> 3))
return -1;
*
* @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
*/
-inline static int bits_clrb(uint8_t *vec, size_t size, uint8_t bit)
+INLINE_API int bits_clrb(uint8_t *vec, size_t size, uint8_t bit)
{
if (size <= (size_t)(bit >> 3))
return -1;
*
* @return @c 1 if the bit is set, @c 0 otherwise.
*/
-inline static int bits_getb(const uint8_t *vec, size_t size, uint8_t bit)
+INLINE_API int bits_getb(const uint8_t *vec, size_t size, uint8_t bit)
{
if (size <= (size_t)(bit >> 3))
return -1;
* Checks if more than @p num blocks are required to deliver @p data_len
* bytes of data for a block size of 1 << (@p szx + 4).
*/
-static inline int coap_more_blocks(size_t data_len, unsigned int num, unsigned short szx)
+INLINE_API int coap_more_blocks(size_t data_len, unsigned int num, unsigned short szx)
{
return ((num + 1) << (szx + 4)) < data_len;
}
/** Sets the More-bit in @p block_opt */
-static inline void coap_opt_block_set_m(coap_opt_t *block_opt, int m)
+INLINE_API void coap_opt_block_set_m(coap_opt_t *block_opt, int m)
{
if (m)
*(COAP_OPT_VALUE(block_opt) + (COAP_OPT_LENGTH(block_opt) - 1)) |= 0x08;
typedef uint32_t coap_tick_t;
- static inline void coap_ticks_impl(coap_tick_t *t)
+ INLINE_API void coap_ticks_impl(coap_tick_t *t)
{
*t = sys_now();
}
- static inline void coap_clock_init_impl(void)
+ INLINE_API void coap_clock_init_impl(void)
{
}
/** Set at startup to initialize the internal clock (time in seconds). */
extern clock_time_t clock_offset;
- static inline void
+ INLINE_API void
contiki_clock_init_impl(void)
{
clock_init();
#define coap_clock_init contiki_clock_init_impl
- static inline void
+ INLINE_API void
contiki_ticks_impl(coap_tick_t *t)
{
*t = clock_time();
#endif /* WITH_ARDUINO */
#ifndef coap_clock_init
- static inline void coap_clock_init_impl(void)
+ INLINE_API void coap_clock_init_impl(void)
{
#ifdef HAVE_TIME_H
clock_offset = time(NULL);
#endif /* coap_clock_init */
#ifndef coap_ticks
- static inline void coap_ticks_impl(coap_tick_t *t)
+ INLINE_API void coap_ticks_impl(coap_tick_t *t)
{
#ifdef HAVE_SYS_TIME_H
struct timeval tv;
* Returns @c 1 if and only if @p a is less than @p b where less is
* defined on a signed data type.
*/
- static inline
+ INLINE_API
int coap_time_lt(coap_tick_t a, coap_tick_t b)
{
return ((coap_tick_diff_t)(a - b)) < 0;
* Returns @c 1 if and only if @p a is less than or equal @p b where
* less is defined on a signed data type.
*/
- static inline
+ INLINE_API
int coap_time_le(coap_tick_t a, coap_tick_t b)
{
return a == b || coap_time_lt(a, b);
# endif
#endif
+#ifndef INLINE_API
+# if defined(__cplusplus)
+# define INLINE_API inline
+# else
+# ifdef _MSC_VER
+# define INLINE_API static __inline
+# else
+# define INLINE_API static inline
+# endif
+# endif
+#endif
+
/* Define to rpl_malloc if the replacement function should be used. */
/* #undef malloc */
#ifdef HAVE_TIME_H
-static inline size_t print_timestamp(char *s, size_t len, coap_tick_t t)
+INLINE_API size_t print_timestamp(char *s, size_t len, coap_tick_t t)
{
struct tm *tmp;
time_t now = clock_offset + (t / COAP_TICKS_PER_SECOND);
#else /* alternative implementation: just print the timestamp */
-static inline size_t
+INLINE_API size_t
print_timestamp(char *s, size_t len, coap_tick_t t)
{
#ifdef HAVE_SNPRINTF
*
* @return The length of @p s.
*/
-static inline size_t
+INLINE_API size_t
strnlen(const char *s, size_t maxlen)
{
size_t n = 0;
time_t clock_offset=0;
-static inline coap_queue_t *
+INLINE_API coap_queue_t *
coap_malloc_node()
{
return (coap_queue_t *)coap_malloc(sizeof(coap_queue_t));
}
-static inline void
+INLINE_API void
coap_free_node(coap_queue_t *node)
{
coap_free(node);
static void coap_retransmittimer_execute(void *arg);
static void coap_retransmittimer_restart(coap_context_t *ctx);
-static inline coap_queue_t *
+INLINE_API coap_queue_t *
coap_malloc_node()
{
return (coap_queue_t *)memp_malloc(MEMP_COAP_NODE);
}
-static inline void
+INLINE_API void
coap_free_node(coap_queue_t *node)
{
memp_free(MEMP_COAP_NODE, node);
PROCESS(coap_retransmit_process, "message retransmit process");
-static inline coap_queue_t *
+INLINE_API coap_queue_t *
coap_malloc_node()
{
return (coap_queue_t *)memb_alloc(&node_storage);
}
-static inline void
+INLINE_API void
coap_free_node(coap_queue_t *node)
{
memb_free(&node_storage, node);
* This function returns @c 1 on success, or @c 0 if the option @p opt
* would exceed @p maxpos.
*/
-static inline int check_opt_size(coap_opt_t *opt, unsigned char *maxpos)
+INLINE_API int check_opt_size(coap_opt_t *opt, unsigned char *maxpos)
{
if (opt && opt < maxpos)
{
}
-static inline int token_match(const unsigned char *a, size_t alen, const unsigned char *b,
+INLINE_API int token_match(const unsigned char *a, size_t alen, const unsigned char *b,
size_t blen)
{
return alen == blen && (alen == 0 || memcmp(a, b, alen) == 0);
* Quick hack to determine the size of the resource description for
* .well-known/core.
*/
-static inline size_t get_wkc_len(coap_context_t *context, coap_opt_t *query_filter)
+INLINE_API size_t get_wkc_len(coap_context_t *context, coap_opt_t *query_filter)
{
unsigned char buf[1];
size_t len = 0;
}
}
-static inline void handle_response(coap_context_t *context, coap_queue_t *sent, coap_queue_t *rcvd)
+INLINE_API void handle_response(coap_context_t *context, coap_queue_t *sent, coap_queue_t *rcvd)
{
/* Call application-specific reponse handler when available. If
}
}
-static inline int
+INLINE_API int
#ifdef __GNUC__
handle_locally(coap_context_t *context __attribute__ ((unused)),
coap_queue_t *node __attribute__ ((unused)))
* @param context The context to register the handler for.
* @param handler The response handler to register.
*/
- static inline void coap_register_response_handler(coap_context_t *context,
+ INLINE_API void coap_register_response_handler(coap_context_t *context,
coap_response_handler_t handler)
{
context->response_handler = handler;
* @param ctx The context to use.
* @param type The option type to register.
*/
- inline static void coap_register_option(coap_context_t *ctx, unsigned char type)
+ INLINE_API void coap_register_option(coap_context_t *ctx, unsigned char type)
{
coap_option_setb(ctx->known_options, type);
}
* @param context the current coap_context_t object
* @return incremented message id in network byte order
*/
-static inline unsigned short coap_new_message_id(coap_context_t *context)
+INLINE_API unsigned short coap_new_message_id(coap_context_t *context)
{
++(context->message_id);
#if defined(WITH_ARDUINO)
* @return The transaction id if RST was sent or @c COAP_INVALID_TID
* on error.
*/
- static inline coap_tid_t coap_send_rst(coap_context_t *context, const coap_address_t *dst,
+ INLINE_API coap_tid_t coap_send_rst(coap_context_t *context, const coap_address_t *dst,
coap_pdu_t *request)
{
return coap_send_message_type(context, dst, request, COAP_MESSAGE_RST);
*
* @return @c 1 if node was found, removed and destroyed, @c 0 otherwise.
*/
- inline static int coap_remove_transaction(coap_queue_t **queue, coap_tid_t id)
+ INLINE_API int coap_remove_transaction(coap_queue_t **queue, coap_tid_t id)
{
coap_queue_t *node;
if (!coap_remove_from_queue(queue, id, &node))
return oi;
}
-static inline int opt_finished(coap_opt_iterator_t *oi)
+INLINE_API int opt_finished(coap_opt_iterator_t *oi)
{
assert(oi);
*
* @param f The filter to clear.
*/
-static inline void coap_option_filter_clear(coap_opt_filter_t f)
+INLINE_API void coap_option_filter_clear(coap_opt_filter_t f)
{
memset(f, 0, sizeof(coap_opt_filter_t));
}
*
* @return @c 1 if bit was set, @c -1 otherwise.
*/
-inline static int coap_option_setb(coap_opt_filter_t filter, unsigned short type)
+INLINE_API int coap_option_setb(coap_opt_filter_t filter, unsigned short type)
{
return bits_setb((uint8_t *) filter, sizeof(coap_opt_filter_t), type);
}
*
* @return @c 1 if bit was set, @c -1 otherwise.
*/
-inline static int coap_option_clrb(coap_opt_filter_t filter, unsigned short type)
+INLINE_API int coap_option_clrb(coap_opt_filter_t filter, unsigned short type)
{
return bits_clrb((uint8_t *) filter, sizeof(coap_opt_filter_t), type);
}
*
* @return @c 1 if bit was set, @c 0 if not, @c -1 on error.
*/
-inline static int coap_option_getb(const coap_opt_filter_t filter, unsigned short type)
+INLINE_API int coap_option_getb(const coap_opt_filter_t filter, unsigned short type)
{
return bits_getb((uint8_t *) filter, sizeof(coap_opt_filter_t), type);
}
* implementation for prng(). You might want to change prng() to use
* a better PRNG on your specific platform.
*/
-static inline int coap_prng_impl(unsigned char *buf, size_t len)
+INLINE_API int coap_prng_impl(unsigned char *buf, size_t len)
{
while (len--)
*buf++ = rand() & 0xFF;
* implementation for prng(). You might want to change prng() to use
* a better PRNG on your specific platform.
*/
-static inline int
+INLINE_API int
contiki_prng_impl(unsigned char *buf, size_t len)
{
unsigned short v = random_rand();
* @param method The CoAP request method to handle.
* @param handler The handler to register with @p resource.
*/
-static inline void coap_register_handler(coap_resource_t *resource, unsigned char method,
+INLINE_API void coap_register_handler(coap_resource_t *resource, unsigned char method,
coap_method_handler_t handler)
{
assert(resource);
(struct_ptr)->LIST_CONCAT(name,_list) = NULL; \
}
-static inline void *
+INLINE_API void *
list_head(list_t the_list)
{
return *the_list;
}
-static inline void list_remove(list_t the_list, void *item)
+INLINE_API void list_remove(list_t the_list, void *item)
{
if (list_head(the_list))
LL_DELETE(*(struct list **)the_list, (struct list *)item);
}
-static inline void list_add(list_t the_list, void *item)
+INLINE_API void list_add(list_t the_list, void *item)
{
list_remove(the_list, item);
LL_APPEND(*(struct list **)the_list, (struct list *)item);
}
-static inline void list_push(list_t the_list, void *item)
+INLINE_API void list_push(list_t the_list, void *item)
{
LL_PREPEND(*(struct list **)the_list, (struct list *)item);
}
-static inline void *
+INLINE_API void *
list_pop(list_t the_list)
{
struct list *l;
return l;
}
-static inline void list_insert(list_t the_list, void *previtem, void *newitem)
+INLINE_API void list_insert(list_t the_list, void *previtem, void *newitem)
{
if (previtem == NULL)
{
}
}
-static inline void *
+INLINE_API void *
list_item_next(void *item)
{
return item == NULL ? NULL : ((struct list *) item)->next;
* @return A pointer to the first occurence of @p c, or @c NULL
* if not found.
*/
-static inline unsigned char *
+INLINE_API unsigned char *
strnchr(unsigned char *s, size_t len, unsigned char c)
{
while (len && *s++ != c)
/* The function signature of coap_hash() is different from
* segment_handler_t hence we use this wrapper as safe typecast. */
-static inline void hash_segment(unsigned char *s, size_t len, void *data)
+INLINE_API void hash_segment(unsigned char *s, size_t len, void *data)
{
coap_hash(s, len, (unsigned char *) data);
}
}\r
\r
OCStackResult ret;\r
- struct timespec startTime = {.tv_sec=0, .tv_nsec=0};\r
- struct timespec currTime = {.tv_sec=0, .tv_nsec=0};\r
- struct timespec timeout;\r
\r
const char DP_DISCOVERY_QUERY[] = "/oic/sec/pconf";\r
\r
}\r
\r
// wait..\r
- timeout.tv_sec = 0;\r
- timeout.tv_nsec = 100000000L;\r
\r
int clock_res = -1;\r
+#if defined(_MSC_VER)\r
+ time_t startTime;\r
+ clock_res = (time(&startTime) == -1);\r
+#else\r
+ struct timespec startTime = {.tv_sec=0, .tv_nsec=0};\r
#if defined(__ANDROID__) || _POSIX_TIMERS > 0\r
clock_res = clock_gettime(CLOCK_MONOTONIC, &startTime);\r
#endif\r
+#endif\r
if (0 != clock_res)\r
{\r
OIC_LOG(ERROR, TAG, "clock error");\r
\r
while (1)\r
{\r
+#if defined(_MSC_VER)\r
+ time_t currTime;\r
+ clock_res = (time(&currTime) == -1);\r
+#else\r
+ struct timespec currTime = {.tv_sec=0, .tv_nsec=0};\r
#if defined(__ANDROID__) || _POSIX_TIMERS > 0\r
clock_res = clock_gettime(CLOCK_MONOTONIC, &currTime);\r
#endif\r
+#endif\r
if (0 != clock_res)\r
{\r
OIC_LOG(ERROR, TAG, "clock error");\r
ret = OC_STACK_ERROR;\r
break;\r
}\r
+#if defined(_MSC_VER)\r
+ long elapsed = currTime - startTime;\r
+#else\r
long elapsed = (currTime.tv_sec - startTime.tv_sec);\r
+#endif\r
if (elapsed > waittime)\r
{\r
break;\r
}\r
else\r
{\r
-#if defined(_WIN32)\r
- Sleep(100);\r
-#else\r
+ struct timespec timeout = {.tv_sec=0, .tv_nsec=100000000L};\r
nanosleep(&timeout, NULL);\r
-#endif // defined (_WIN32)\r
}\r
}\r
\r
- //Waiting for each response.\r
+ // Waiting for each response.\r
ret = OCCancel(handle, OC_LOW_QOS, NULL, 0);\r
if (OC_STACK_OK != ret)\r
{\r
}
break;
case WM_CREATE:
- hIcon1 = LoadIcon (NULL, IDI_WARNING);
- SendMessage(icon_button,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcon1);
- GetClientRect(hwnd, &rect);
- g_BkgndBrush = GetSysColorBrush(COLOR_MENU);
-
- app = new WinUIClient::WinUIClientApp({client_open, fread, fwrite, fclose, unlink });
- app->Initialize();
- app->Run();
-
+ {
+ hIcon1 = LoadIcon (NULL, IDI_WARNING);
+ SendMessage(icon_button,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcon1);
+ GetClientRect(hwnd, &rect);
+ g_BkgndBrush = GetSysColorBrush(COLOR_MENU);
+
+ OCPersistentStorage ps = {client_open, fread, fwrite, fclose, unlink };
+ app = new WinUIClient::WinUIClientApp(ps);
+ app->Initialize();
+ app->Run();
+ }
break;
case WM_DESTROY:
const std::vector<std::string>& interfaces)
: m_clientWrapper(clientWrapper), m_uri(uri),
m_resourceId(serverId, m_uri),
- m_devAddr{ OC_DEFAULT_ADAPTER, OC_DEFAULT_FLAGS, 0, {0}, 0
-#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
- , {0}
-#endif
- },
m_isObservable(observable), m_isCollection(false),
m_resourceTypes(resourceTypes), m_interfaces(interfaces),
m_observeHandle(nullptr)
{
+ m_devAddr = OCDevAddr{OC_DEFAULT_ADAPTER, OC_DEFAULT_FLAGS, 0, {0}, 0,
+#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
+ {0}
+#endif
+ };
m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE)
!= m_interfaces.end();
OCStackResult result = checked_guard(m_clientWrapper.lock(),
&IClientWrapper::CancelObserveResource,
- m_observeHandle, "", m_uri, m_headerOptions, QoS);
+ m_observeHandle, (const char*)"", m_uri, m_headerOptions, QoS);
if(result == OC_STACK_OK)
{