ThingWorx C SDK
twOSPort.h
Go to the documentation of this file.
1 /***************************************
2  * Copyright (C) 2015 ThingWorx Inc. *
3  ***************************************/
4 
10 #ifndef TW_OS_PORT_H
11 #define TW_OS_PORT_H
12 
13 #include <stdint.h>
14 #include <stdlib.h>
15 
16 
17 #include "twConfig.h"
18 #include "twDefaultSettings.h"
19 #include "twDefinitions.h"
20 #include TW_OS_INCLUDE
21 #include "twLogger.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
33 enum LogLevel;
37 char * levelString(enum LogLevel level);
41 void LOGGING_FUNCTION( enum LogLevel level, const char * timestamp, const char * message );
42 
57 char twTimeGreaterThan(DATETIME t1, DATETIME t2);
58 
67 char twTimeLessThan(DATETIME t1, DATETIME t2);
68 
77 DATETIME twAddMilliseconds(DATETIME t1, int32_t msec);
78 
86 DATETIME twGetSystemTime(char utc);
87 
94 
107 void twGetSystemTimeString(char * s, const char * format, int length, char msec, char utc);
108 
122 void twGetTimeString(DATETIME time, char * s, const char * format, int length, char msec, char utc);
123 void twSleepMsec(int milliseconds);
124 
137 
146 void twMutex_Delete(TW_MUTEX m);
147 
155 void twMutex_Lock(TW_MUTEX m);
156 
164 void twMutex_Unlock(TW_MUTEX m);
165 
169 #define CLOSED (char)0
170 #define OPEN (char)1
171 
175 typedef struct twSocket {
176  TW_SOCKET_TYPE sock;
177  TW_ADDR_INFO addr;
178  TW_ADDR_INFO * addrInfo;
179  char state;
180  char * host;
181  uint16_t port;
182  char * proxyHost;
183  uint16_t proxyPort;
184  char * proxyUser;
185  char * proxyPass;
186 } twSocket;
187 
188 #ifndef MSG_NOSIGNAL
189 
192 #define MSG_NOSIGNAL 0
193 #endif
194 
207 twSocket * twSocket_Create(const char * host, int16_t port, uint32_t options);
208 
217 int twSocket_Connect(twSocket * s);
218 
228 
237 int twSocket_Close(twSocket * s);
238 
247 int twSocket_WaitFor(twSocket * s, int timeout);
248 
260 int twSocket_Read(twSocket * s, char * buf, int len, int timeout);
261 
273 int twSocket_Write(twSocket * s, char * buf, int len, int timeout);
274 
282 int twSocket_Delete(twSocket * s);
283 
290 
291 /* Enabling proxy support adds ~5KB to the code footprint, #define USE_NTLM_PROXY support adds another ~40KB */
292 #ifdef ENABLE_HTTP_PROXY_SUPPORT
293 
305 int twSocket_SetProxyInfo(twSocket * s,char * proxyHost, uint16_t proxyPort, char * proxyUser, char * proxyPass);
306 
315 int twSocket_ClearProxyInfo(twSocket * s);
316 #endif
317 
324 void twTasker_Start();
328 void twTasker_Stop();
329 
352 int twDirectory_GetFileInfo(char * filename, uint64_t * size, DATETIME * lastModified, char * isDirectory, char * isReadOnly);
353 
361 char twDirectory_FileExists(char * name);
362 
370 int twDirectory_CreateFile(char * name);
371 
380 int twDirectory_MoveFile(char * fromName, char * toName);
381 
389 int twDirectory_DeleteFile(char * name);
390 
398 int twDirectory_CreateDirectory(char * name);
399 
407 int twDirectory_DeleteDirectory(char * name);
408 
434 TW_DIR twDirectory_IterateEntries(char * dirName, TW_DIR dir, char ** name, uint64_t * size,
435  DATETIME * lastModified, char * isDirectory, char * isReadOnly);
436 
443 
444 
445 #ifdef __cplusplus
446 }
447 #endif
448 
449 #endif
450 
char state
Definition: twOSPort.h:179
void twMutex_Delete(TW_MUTEX m)
Frees all memory associated with a ::twMutex and all of its owned substructures.
Definition: twIos.c:97
void LOGGING_FUNCTION(enum LogLevel level, const char *timestamp, const char *message)
See twLogger.h.
Definition: twIos.c:26
int twSocket_Read(twSocket *s, char *buf, int len, int timeout)
Reads data from a twSocket.
Definition: twIos.c:298
char twTimeGreaterThan(DATETIME t1, DATETIME t2)
Compares two DATETIME variables to see if one is greater.
Definition: twIos.c:31
DATETIME twGetSystemTime(char utc)
Gets the current system time.
Definition: twIos.c:43
int twDirectory_GetFileInfo(char *filename, uint64_t *size, DATETIME *lastModified, char *isDirectory, char *isReadOnly)
Gets information about a file.
Definition: twIos.c:477
uint16_t port
Definition: twOSPort.h:181
void twGetTimeString(DATETIME time, char *s, const char *format, int length, char msec, char utc)
Converts a DATETIME to a string.
Definition: twIos.c:53
TW_SOCKET_TYPE sock
Definition: twOSPort.h:176
char * proxyUser
Definition: twOSPort.h:184
twSocket * twSocket_Create(const char *host, int16_t port, uint32_t options)
Creates a new twSocket.
Definition: twIos.c:215
char twTimeLessThan(DATETIME t1, DATETIME t2)
Compares two DATETIME variables to see if one is smaller.
Definition: twIos.c:35
#define TW_MUTEX
For Linux builds a TW_MUTEX is a pthread_mutex_t.
Definition: twLinux-openssl.h:81
TW_MUTEX twMutex_Create()
Creates a new ::twMutex.
Definition: twIos.c:90
twSocket base type definition.
Definition: twOSPort.h:175
int twSocket_Connect(twSocket *s)
Connects a twSocket.
Definition: twIos.c:244
void twMutex_Unlock(TW_MUTEX m)
Unlocks a ::twMutex.
Definition: twIos.c:109
int twSocket_Delete(twSocket *s)
Frees all memory associated with a twSocket.
Definition: twIos.c:351
TW_DIR twDirectory_IterateEntries(char *dirName, TW_DIR dir, char **name, uint64_t *size, DATETIME *lastModified, char *isDirectory, char *isReadOnly)
Definition: twIos.c:490
TW_ADDR_INFO addr
Definition: twOSPort.h:177
int twSocket_Close(twSocket *s)
Closes a twSocket.
Definition: twIos.c:278
int twSocket_Reconnect(twSocket *s)
Reconnects a twSocket.
Definition: twIos.c:269
LogLevel
Log message level enumeration.
Definition: twLogger.h:26
int twSocket_GetLastError()
Gets the errno of the last operation.
Definition: twIos.c:412
int twDirectory_MoveFile(char *fromName, char *toName)
Moves an existing file.
Definition: twIos.c:563
int twSocket_Write(twSocket *s, char *buf, int len, int timeout)
Writes data to a twSocket.
Definition: twIos.c:326
int twSocket_WaitFor(twSocket *s, int timeout)
Checks to see if a twSocket is ready for I/O.
Definition: twIos.c:314
void twGetSystemTimeString(char *s, const char *format, int length, char msec, char utc)
Gets the current system time as a string.
Definition: twIos.c:79
int twDirectory_DeleteDirectory(char *name)
Deletes a directory.
Definition: twIos.c:609
int twDirectory_DeleteFile(char *name)
Deletes a file.
Definition: twIos.c:571
Default settings for ThingWorx C SDK.
char twDirectory_FileExists(char *name)
Checks to see if a file exists.
Definition: twIos.c:543
General configuration overrides for ThingWorx C SDK.
Common definitions for C SDK.
int twDirectory_CreateDirectory(char *name)
Creates a directory.
Definition: twIos.c:578
char * proxyPass
Definition: twOSPort.h:185
TW_ADDR_INFO * addrInfo
Definition: twOSPort.h:178
void twMutex_Lock(TW_MUTEX m)
Locks a ::twMutex.
Definition: twIos.c:105
uint64_t twGetSystemMillisecondCount()
Gets the current system time in milliseconds.
Definition: twIos.c:49
void twTasker_Stop()
Stops the ::twTasker.
Definition: twIos.c:442
struct twSocket twSocket
twSocket base type definition.
DATETIME twAddMilliseconds(DATETIME t1, int32_t msec)
Adds milliseconds to a DATETIME.
Definition: twIos.c:39
char * proxyHost
Definition: twOSPort.h:182
char * levelString(enum LogLevel level)
See twLogger.h.
Definition: twLogger.c:18
int twDirectory_CreateFile(char *name)
Creates a new file.
Definition: twIos.c:552
Structure definitions and function prototypes for the ThingWorx logging facility. ...
int twDirectory_GetLastError()
Gets the errno of the last operation.
Definition: twIos.c:616
void twTasker_Start()
Starts the ::twTasker.
Definition: twIos.c:438
uint16_t proxyPort
Definition: twOSPort.h:183
char * host
Definition: twOSPort.h:180