Friendly LWM2M client
WppPlatform.cpp
Go to the documentation of this file.
1
#include "
WppPlatform.h
"
2
3
#include <cstring>
4
#include "liblwm2m.h"
5
6
/*
7
* With this file we have problem related to linker optimization.
8
* Unlike dynamic libraries, which are fully linked when they are created,
9
* static libraries are essentially archives of object files (.o files).
10
* When we link an executable against a static library, the linker only
11
* pulls in the object files that contain symbols that are actually used
12
* by the executable. This is to reduce the final size of the executable.
13
* If an object file inside the static library does not contain any symbols
14
* that are referenced by the executable, that object file will not be
15
* included in the final link.
16
*
17
* This is exactly the problem with this file, since its functionality is
18
* not directly used by either the user code or the Wpp library, so the
19
* linker tries to optimize it, and the WakaamaCore library, due to the
20
* optimization of this file, does not get the implementation of the
21
* necessary functions. The solution can be the linker flag --whole-archive,
22
* which should be added to the user CMake file, it includes all object
23
* files from the Wpp library, while it does not extend to the WakaamaCore
24
* library, and when optimization is enabled, it does not add overhead to
25
* the .text section. Another approach for solving the problem is combining
26
* the source code of wakaama core and wpp library into a single library.
27
*
28
* For now, uses the second approach.
29
*/
30
extern
"C"
{
31
/*---------- Platform bindings ----------*/
32
void
*
lwm2m_malloc
(
size_t
s) {
33
return
new
uint8_t[s];
34
}
35
36
void
lwm2m_free
(
void
* p) {
37
delete
[] (uint8_t *)p;
38
}
39
40
char
*
lwm2m_strdup
(
const
char
* str) {
41
if
(!str)
return
NULL;
42
43
const
int
len = strlen(str) + 1;
44
char
*
const
buf = (
char
*)
lwm2m_malloc
(len);
45
if
(buf) {
46
memset(buf, 0, len);
47
memcpy(buf, str, len - 1);
48
}
49
50
return
buf;
51
}
52
53
int
lwm2m_strncmp
(
const
char
* s1,
const
char
* s2,
size_t
n) {
54
return
strncmp(s1, s2, n);
55
}
56
57
int
lwm2m_strcasecmp
(
const
char
* str1,
const
char
* str2) {
58
return
strcasecmp(str1, str2);
59
}
60
61
time_t
lwm2m_gettime
(
void
) {
62
return
wpp::WppPlatform::getTime
();
63
}
64
65
void
lwm2m_printf
(
const
char
* format, ...) {
66
va_list ap;
67
va_start(ap, format);
68
wpp::WppPlatform::print
(format, ap);
69
va_end(ap);
70
}
71
}
lwm2m_strdup
char * lwm2m_strdup(const char *str)
Definition:
WppPlatform.cpp:40
lwm2m_printf
void lwm2m_printf(const char *format,...)
Definition:
WppPlatform.cpp:65
lwm2m_strncmp
int lwm2m_strncmp(const char *s1, const char *s2, size_t n)
Definition:
WppPlatform.cpp:53
lwm2m_free
void lwm2m_free(void *p)
Definition:
WppPlatform.cpp:36
lwm2m_gettime
time_t lwm2m_gettime(void)
Definition:
WppPlatform.cpp:61
lwm2m_strcasecmp
int lwm2m_strcasecmp(const char *str1, const char *str2)
Definition:
WppPlatform.cpp:57
lwm2m_malloc
void * lwm2m_malloc(size_t s)
Definition:
WppPlatform.cpp:32
WppPlatform.h
wpp::WppPlatform::getTime
static time_t getTime(void)
Returns the number of seconds elapsed since a specific origin.
wpp::WppPlatform::print
static void print(const char *msg, va_list arg)
Prints a formatted message.
wpp
platform
WppPlatform.cpp
Generated by
1.9.1