# Build 'resource' sub-project
SConscript(build_dir + 'resource/SConscript')
-if target_os != 'arduino':
+if target_os not in ['arduino','darwin','ios']:
SConscript(build_dir + 'examples/OICMiddle/SConscript')
# Build 'service' sub-project
env.AppendUnique(CPPDEFINES = ['NDEBUG'])
else:
env.AppendUnique(CCFLAGS = ['-g'])
+ env.AppendUnique(LINKFLAGS = ['-g'])
+
+env.ParseConfig("pkg-config glib-2.0 gthread-2.0 --cflags --libs")
if target_os == 'darwin':
sys_root = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX' + sys_version + '.sdk/'
# Build liboctbstack
SConscript('csdk/SConscript')
-if target_os != 'arduino':
+if target_os not in ['arduino','darwin']:
# Build liboc_logger
SConscript('oc_logger/SConscript')
# Build C/C++ unit tests
SConscript('unit_tests.scons')
-
+elif target_os == 'darwin':
+ # Build linux samples for now
+ SConscript('csdk/stack/samples/linux/SimpleClientServer/SConscript')
elif target_os == 'arduino':
SConscript('csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript')
if target_os == 'arduino':
liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
-else:
+elif target_os not in ['darwin','ios']:
liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
if target_os in ['darwin', 'ios']:
'ocrandom/src/ocrandom.c',
'ocmalloc/src/ocmalloc.c'
]
-if target_os == 'arduino':
+if target_os in ['arduino','darwin'] :
liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
else:
liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
env.AppendUnique(CPPDEFINES = ['WIFI_ADAPTER', 'ETHERNET_ADAPTER','NO_EDR_ADAPTER','NO_LE_ADAPTER'])
elif target_os == 'tizen':
env.AppendUnique(CPPDEFINES = ['WIFI_ADAPTER', 'NO_ETHERNET_ADAPTER','EDR_ADAPTER','LE_ADAPTER'])
+ elif target_os == 'darwin':
+ env.AppendUnique(CPPDEFINES = ['NO_WIFI_ADAPTER','ETHERNET_ADAPTER','NO_EDR_ADAPTER','NO_LE_ADAPTER'])
else:
env.AppendUnique(CPPDEFINES = ['WIFI_ADAPTER', 'ETHERNET_ADAPTER','EDR_ADAPTER','LE_ADAPTER'])
print "CA Transport is ALL"
#ifdef __TIZEN__
#define OICLog(level,tag,mes) LOG(level,tag,mes)
#define OICLogv(level,tag,fmt,args...) LOG(level,tag,fmt,##args)
-#elif defined(ANDROID) || defined(__linux__)
+#elif defined(ANDROID) || defined(__linux__) || defined(__APPLE__)
/**
* Configure logger to use a context that defines a custom logger function
*
libcoap_env = env.Clone()
target_os = env.get('TARGET_OS')
+
# As in the source code(C) includes arduino Time library head file(C++)
# It requires compile the .c with g++
if target_os == 'arduino':
if target_os not in ['arduino', 'windows', 'winrt']:
libcoap_env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
- libcoap_env.AppendUnique(CFLAGS = ['-std=gnu99', '-fPIC'])
+ libcoap_env.AppendUnique(CFLAGS = ['-std=gnu99','-fPIC'])
if target_os not in ['windows', 'winrt']:
libcoap_env.AppendUnique(CFLAGS = ['-Wall', '-ffunction-sections',
#if defined(WITH_POSIX) || defined(WITH_ARDUINO)
-time_t clock_offset;
+time_t clock_offset=0;
static inline coap_queue_t *
coap_malloc_node()
env.AppendUnique(CPPPATH = [root_dir + '/lib/libcoap-4.1.1/'])
env.AppendUnique(CPPPATH = [root_dir + '/common/inc/'])
+if ca_os not in ['arduino', 'windows', 'winrt']:
+ env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
+
+if ca_os in ['darwin']:
+ env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
#Getting common source files
env.SConscript('./../common/SConscript')
#include "cainterfacecontroller.h"
#include "caprotocolmessage.h"
#include "caretransmission.h"
+#include "caadapterutils.h"
#include "uqueue.h"
#include "logger.h"
#include "config.h" /* for coap protocol */
env.AppendUnique(CA_SRC=[src_dir+'caethernetadapter.c'])
#Source files to build in Linux platform
-if target_os == 'linux':
+if target_os in ['linux','darwin']:
env.AppendUnique(CA_SRC=[src_dir+'linux/caethernetclient.c',
src_dir+'linux/caethernetserver.c',
src_dir+'linux/caethernetnwmonitor.c',
#define ETHERNET_MONITOR_TAG "ETHERNET_MONITOR"
+#ifdef __APPLE__
+#define ETHERNET_INF_PREFIX "en"
+#else
+#define ETHERNET_INF_PREFIX "eth"
+#endif
+
/**
* @var nwConnectivityStatus
* @brief Maintains network status.
* @fn CAEthernetGetInterfaceInformation
* @brief This methods gets local interface name and IP address information.
*/
-static void CAEthernetGetInterfaceInformation(char **interfaceName, char **ipAddress,
- char **subnetMask);
+static void CAEthernetGetInterfaceInformation(const char *interfacePrefix,
+ char **interfaceName, char **ipAddress,char **subnetMask);
static void CANetworkMonitorThread(void *threadData);
}
u_mutex_lock(g_ethernetNetInfoMutex);
- CAEthernetGetInterfaceInformation(&g_ethernetInterfaceName, &g_ethernetIPAddress,
+ CAEthernetGetInterfaceInformation(ETHERNET_INF_PREFIX,&g_ethernetInterfaceName, &g_ethernetIPAddress,
&g_ethernetSubnetMask);
u_mutex_unlock(g_ethernetNetInfoMutex);
OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "OUT");
}
-void CAEthernetGetInterfaceInformation(char **interfaceName,
+void CAEthernetGetInterfaceInformation(const char *interfaceNamePrefix,char **interfaceName,
char **ipAddress, char **subnetMask)
{
if (!interfaceName || !ipAddress || !subnetMask)
continue;
}
- const char matchName[] = "eth";
- int matchNameLen = strlen(matchName);
- if (!strncasecmp(ifa->ifa_name, matchName, matchNameLen))
+ int matchNameLen = strlen(interfaceNamePrefix);
+ if (!strncasecmp(ifa->ifa_name, interfaceNamePrefix, matchNameLen))
{
// get the interface ip address
if (0 != getnameinfo(ifa->ifa_addr, len, interfaceAddress,
char *interfaceName = NULL;
char *ipAddress = NULL;
char *subnetMask = NULL;
- CAEthernetGetInterfaceInformation(&interfaceName, &ipAddress, &subnetMask);
+ CAEthernetGetInterfaceInformation(ETHERNET_INF_PREFIX,&interfaceName, &ipAddress, &subnetMask);
// check current network status
CANetworkStatus_t currNetworkStatus;
#include <time.h>
#endif
+#ifdef __APPLE__
+#include <sys/time.h>
+#endif
+
#include "logger.h"
#include "string.h"
#include "oc_logger.h"
// Convert LogLevel to platform-specific severity level. Store in PROGMEM on Arduino
#ifdef __ANDROID__
static android_LogPriority LEVEL[] = {ANDROID_LOG_DEBUG, ANDROID_LOG_INFO, ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL};
-#elif defined __linux__
+#elif defined(__linux__) || defined(__APPLE__)
static const char * LEVEL[] __attribute__ ((unused)) = {"DEBUG", "INFO", "WARNING", "ERROR", "FATAL"};
#elif defined ARDUINO
#include <stdarg.h>
}
void OCLogShutdown() {
-#ifdef __linux__
+#if defined(__linux__) || defined(__APPLE__)
if (logCtx && logCtx->destroy)
{
logCtx->destroy(logCtx);
OCLog(level, tag, buffer);
}
+#if defined(__linux__)
+static void osalGetTime(int *min,int *sec, int *ms)
+{
+ if (min && sec && ms)
+ {
+ struct timespec when = {};
+ if (!clock_gettime(CLOCK_REALTIME_COARSE, &when))
+ {
+ *min = (when.tv_sec / 60) % 60;
+ *sec = when.tv_sec % 60;
+ *ms = when.tv_nsec / 1000000;
+ }
+ }
+}
+#elif defined(__APPLE__)
+static void osalGetTime(int *min,int *sec, int *ms)
+{
+ if (min && sec && ms)
+ {
+ struct timeval now;
+ if (!gettimeofday(&now, NULL))
+ {
+ *min = (now.tv_sec / 60) % 60;
+ *sec = now.tv_sec % 60;
+ *ms = now.tv_usec * 1000;
+ }
+ }
+}
+#endif
+
/**
* Output a log string with the specified priority level.
* Only defined for Linux and Android
return;
}
- #ifdef __ANDROID__
- __android_log_write(LEVEL[level], tag, logStr);
- #elif defined __linux__
- if (logCtx && logCtx->write_level)
- {
- logCtx->write_level(logCtx, LEVEL_XTABLE[level], logStr);
+#ifdef __ANDROID__
+ __android_log_write(LEVEL[level], tag, logStr);
+#elif defined(__linux__) || defined(__APPLE__)
+ if (logCtx && logCtx->write_level)
+ {
+ logCtx->write_level(logCtx, LEVEL_XTABLE[level], logStr);
+ }
+ else
+ {
- }
- else
- {
- struct timespec when = {};
- int min = 0;
- int sec = 0;
- int ms = 0;
- if (!clock_gettime(CLOCK_REALTIME_COARSE, &when))
- {
- min = (when.tv_sec / 60) % 60;
- sec = when.tv_sec % 60;
- ms = when.tv_nsec / 1000000;
- }
- printf("%02d:%02d.%03d %s: %s: %s\n", min, sec, ms, LEVEL[level], tag, logStr);
- }
- #endif
+ int min = 0;
+ int sec = 0;
+ int ms = 0;
+ osalGetTime(&min,&sec,&ms);
+
+ printf("%02d:%02d.%03d %s: %s: %s\n", min, sec, ms, LEVEL[level], tag, logStr);
+ }
+#endif
}
/**
#endif
+
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#if defined(__ANDROID__) || defined(__linux__)
+#if defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__)
#include "fcntl.h"
#include "unistd.h"
#endif
#endif
int8_t OCSeedRandom() {
-#if defined(__ANDROID__) || defined(__linux__)
+#if defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__)
int32_t fd = open("/dev/urandom", O_RDONLY);
if (fd > 0) {
uint32_t randomSeed;
}
uint8_t OCGetRandomByte(void) {
-#if defined(__ANDROID__) || defined(__linux__)
+#if defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__)
return rand() & 0x00FF;
#elif defined ARDUINO
return random(256) & 0x00FF;
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Import('env')
-
+target_os = env.get('TARGET_OS')
samples_env = env.Clone()
######################################################################
# Build flags
samples_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
samples_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
-samples_env.AppendUnique(LIBS = ['-lpthread'])
+samples_env.AppendUnique(LIBS = ['-lpthread' ])
samples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-samples_env.PrependUnique(LIBS = ['m', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap'])
+
+if target_os in ['darwin']:
+ samples_env.PrependUnique(LIBS = ['m','octbstack', 'connectivity_abstraction','coap' ])
+else:
+ samples_env.PrependUnique(LIBS = ['m', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap'])
+
if env.get('SECURED') == '1':
samples_env.AppendUnique(LIBS = ['tinydtls'])
samples_env.ParseConfig('pkg-config --libs glib-2.0');
target_os = env.get('TARGET_OS')
-if target_os != 'arduino':
+if target_os not in ['arduino','darwin']:
# Build things manager project
SConscript('things-manager/SConscript')