ThingWorx C SDK
twIos.h
1 /***************************************
2  * Copyright (C) 2015 ThingWorx Inc. *
3  ***************************************/
4 
10 #ifndef TW_LINUX_H
11 #define TW_LINUX_H
12 
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <netdb.h>
16 #include <dirent.h>
17 #include <stdio.h>
18 #include <CFNetwork/CFSocketStream.h>
19 
30 #define TW_TLS_INCLUDE "twAxTls.h"
31 
35 #ifndef TW_LEAN_AND_MEAN
36 
39 #define TW_LOGGER_BUF_SIZE 4096
40 #define TW_LOG(level, fmt, ...) twLog(level, fmt, ##__VA_ARGS__)
41 #define TW_LOG_HEX(msg, preamble, length) twLogHexString(msg, preamble, length)
42 #define TW_LOG_MSG(msg, preamble) twLogMessage(msg, preamble)
43 
47 #ifndef ENABLE_HTTP_PROXY_SUPPORT
48 #define ENABLE_HTTP_PROXY_SUPPORT
49 #endif
50 #ifndef USE_NTLM_PROXY
51 #define USE_NTLM_PROXY
52 #endif
53 
54 #else /* LEAN AND MEAN */
55 
61 #define TW_LOGGER_BUF_SIZE 1
62 #define TW_LOG(level, fmt, ...)
63 #define TW_LOG_HEX(msg, preamble, length)
64 #define TW_LOG_MSG(msg, preamble)
65 
66 #undef OFFLINE_MSG_STORE
67 #define OFFLINE_MSG_STORE 0
68 #undef ENABLE_HTTP_PROXY_SUPPORT
69 #undef USE_NTLM_PROXY
70 #undef ENABLE_FILE_XFER
71 #undef ENABLE_TUNNELING
72 #endif
73 
77 typedef uint64_t DATETIME;
78 
82 #define TW_MUTEX pthread_mutex_t *
83 
84 // Forward declaration
85 struct twSocket;
86 
90 typedef struct iosStream {
91  struct twSocket * parent;
92  CFReadStreamRef readStream;
93  CFWriteStreamRef writeStream;
94  CFStreamClientContext ctx;
95 } iosStream;
96 
97 #define IPV4 AF_INET
98 #define IPV6 AF_INET6
99 #define TW_SOCKET_TYPE iosStream*
100 #define TW_ADDR_INFO struct addrinfo
101 
105 #define TICKS_PER_MSEC 1
106 
110 #define TW_MALLOC(a) malloc(a)
111 #define TW_CALLOC(a, b) calloc(a,b)
112 #define TW_REALLOC(a, b) realloc(a, b)
113 #define TW_FREE(a) free(a)
114 
118 #define TW_FOPEN(a,b) fopen(a,b)
119 #define TW_FCLOSE(a) fclose(a)
120 #define TW_FREAD(a,b,c,d) fread(a,b,c,d)
121 #define TW_FWRITE(a,b,c,d) fwrite(a,b,c,d)
122 #define TW_FSEEK(a,b,c) fseeko(a,b,c)
123 #define TW_FERROR(a) ferror(a)
124 #define TW_FTELL(a) ftell(a)
125 
126 #define TW_FILE_HANDLE FILE*
127 #define TW_FILE_DELIM '/'
128 #define TW_FILE_DELIM_STR "/"
129 #define TW_FILE_CASE_SENSITVE TRUE
130 #define TW_DIR DIR *
131 #define ERROR_NO_MORE_FILES 0
132 
136 #define TW_THREAD_ID pthread_t
137 
141 #define INLINE
142 #ifndef OS_IOS
143 
144 char getch();
145 
146 #endif
147 
148 
153 char * stringCopyInUTF8FromCFString(CFStringRef string);
154 CFStringRef cFStringFromUTF8String(char *string);
155 void clearLastStreamError();
156 void setLastErrorFromReadStream(CFReadStreamRef stream);
157 void setLastErrorFromWriteStream(CFWriteStreamRef stream);
158 
159 #endif
twSocket base type definition.
Definition: twOSPort.h:175
Definition: twIos.h:90
uint64_t DATETIME
Date/time type definition.
Definition: twLinux-openssl.h:76