ThingWorx C SDK
|
Wrappers for OS-specific functionality. More...
#include <stdint.h>
#include <stdlib.h>
#include "twConfig.h"
#include "twDefaultSettings.h"
#include "twDefinitions.h"
#include "twLogger.h"
Go to the source code of this file.
Classes | |
struct | twSocket |
twSocket base type definition. More... | |
Functions | |
Logging functions | |
char * | levelString (enum LogLevel level) |
See twLogger.h. | |
void | LOGGING_FUNCTION (enum LogLevel level, const char *timestamp, const char *message) |
See twLogger.h. | |
Time Functions | |
Time is represented as a 64 bit value representing milliseconds since the epoch. | |
char | twTimeGreaterThan (DATETIME t1, DATETIME t2) |
Compares two DATETIME variables to see if one is greater. More... | |
char | twTimeLessThan (DATETIME t1, DATETIME t2) |
Compares two DATETIME variables to see if one is smaller. More... | |
DATETIME | twAddMilliseconds (DATETIME t1, int32_t msec) |
Adds milliseconds to a DATETIME. More... | |
DATETIME | twGetSystemTime (char utc) |
Gets the current system time. More... | |
uint64_t | twGetSystemMillisecondCount () |
Gets the current system time in milliseconds. More... | |
void | twGetSystemTimeString (char *s, const char *format, int length, char msec, char utc) |
Gets the current system time as a string. More... | |
void | twGetTimeString (DATETIME time, char *s, const char *format, int length, char msec, char utc) |
Converts a DATETIME to a string. More... | |
void | twSleepMsec (int milliseconds) |
Mutex Functions | |
TW_MUTEX | twMutex_Create () |
Creates a new ::twMutex. More... | |
void | twMutex_Delete (TW_MUTEX m) |
Frees all memory associated with a ::twMutex and all of its owned substructures. More... | |
void | twMutex_Lock (TW_MUTEX m) |
Locks a ::twMutex. More... | |
void | twMutex_Unlock (TW_MUTEX m) |
Unlocks a ::twMutex. More... | |
Thread/Task Functions | |
void | twTasker_Start () |
Starts the ::twTasker. | |
void | twTasker_Stop () |
Stops the ::twTasker. | |
File Transfer Functions | |
int | twDirectory_GetFileInfo (char *filename, uint64_t *size, DATETIME *lastModified, char *isDirectory, char *isReadOnly) |
Gets information about a file. More... | |
char | twDirectory_FileExists (char *name) |
Checks to see if a file exists. More... | |
int | twDirectory_CreateFile (char *name) |
Creates a new file. More... | |
int | twDirectory_MoveFile (char *fromName, char *toName) |
Moves an existing file. More... | |
int | twDirectory_DeleteFile (char *name) |
Deletes a file. More... | |
int | twDirectory_CreateDirectory (char *name) |
Creates a directory. More... | |
int | twDirectory_DeleteDirectory (char *name) |
Deletes a directory. More... | |
TW_DIR | twDirectory_IterateEntries (char *dirName, TW_DIR dir, char **name, uint64_t *size, DATETIME *lastModified, char *isDirectory, char *isReadOnly) |
int | twDirectory_GetLastError () |
Gets the errno of the last operation. More... | |
Sockets | |
#define | CLOSED (char)0 |
#define | OPEN (char)1 |
#define | MSG_NOSIGNAL 0 |
MSG_NOSIGNAL is not defined on some implementations. | |
typedef struct twSocket | twSocket |
twSocket base type definition. | |
twSocket * | twSocket_Create (const char *host, int16_t port, uint32_t options) |
Creates a new twSocket. More... | |
int | twSocket_Connect (twSocket *s) |
Connects a twSocket. More... | |
int | twSocket_Reconnect (twSocket *s) |
Reconnects a twSocket. More... | |
int | twSocket_Close (twSocket *s) |
Closes a twSocket. More... | |
int | twSocket_WaitFor (twSocket *s, int timeout) |
Checks to see if a twSocket is ready for I/O. More... | |
int | twSocket_Read (twSocket *s, char *buf, int len, int timeout) |
Reads data from a twSocket. More... | |
int | twSocket_Write (twSocket *s, char *buf, int len, int timeout) |
Writes data to a twSocket. More... | |
int | twSocket_Delete (twSocket *s) |
Frees all memory associated with a twSocket. More... | |
int | twSocket_GetLastError () |
Gets the errno of the last operation. More... | |
Wrappers for OS-specific functionality.
int twDirectory_CreateDirectory | ( | char * | name | ) |
Creates a directory.
[in] | name | The full path of the directory to create. |
int twDirectory_CreateFile | ( | char * | name | ) |
Creates a new file.
[in] | name | The full path of the file to create. |
int twDirectory_DeleteDirectory | ( | char * | name | ) |
Deletes a directory.
[in] | name | The full path of the directory to delete. |
int twDirectory_DeleteFile | ( | char * | name | ) |
Deletes a file.
[in] | name | The full path of the file to delete. |
char twDirectory_FileExists | ( | char * | name | ) |
Checks to see if a file exists.
[in] | name | The full path of the file to check. |
int twDirectory_GetFileInfo | ( | char * | filename, |
uint64_t * | size, | ||
DATETIME * | lastModified, | ||
char * | isDirectory, | ||
char * | isReadOnly | ||
) |
Gets information about a file.
[in] | filename | The full path of the file or directory to get the information of. |
[out] | size | A pointer to an integer to store the size of the file in. |
[out] | lastModified | A pointer to a DATETIME to store the date/time of the last modification to the file in. |
[out] | isDirectory | A pointer to a char to store #TRUE if the file is a directory or #FALSE if it isn't. |
[out] | isReadOnly | A pointer to a char to store #TRUE if the file is read-only or #FALSE if it isn't. |
int twDirectory_GetLastError | ( | ) |
Gets the errno of the last operation.
TW_DIR twDirectory_IterateEntries | ( | char * | dirName, |
TW_DIR | dir, | ||
char ** | name, | ||
uint64_t * | size, | ||
DATETIME * | lastModified, | ||
char * | isDirectory, | ||
char * | isReadOnly | ||
) |
[in] | dirName | The full path of the directory to iterate through. |
[out] | dir | A handle for the directory. |
[out] | name | A pointer to a string to store the name of the current entry in. |
[out] | size | A pointer to an integer to store the size of the current entry in. |
[out] | lastModified | A pointer to a DATETIME to store the date/time of the last modification to the current entry in. |
[out] | isDirectory | A pointer to a char to store #TRUE if the current entry is a directory or #FALSE if it isn't. |
[out] | isReadOnly | A pointer to a char to store #TRUE if the current entry is read-only or #FALSE if it isn't. |
dirName
for the first time, the function will open the directory and return a handle to the opened directory. If there are no more entries in the directory the directory will be closed and the function will return 0. int twDirectory_MoveFile | ( | char * | fromName, |
char * | toName | ||
) |
Moves an existing file.
[in] | fromName | The full path of the file to move. |
[in] | toName | The full path to move the file to. |
uint64_t twGetSystemMillisecondCount | ( | ) |
Gets the current system time in milliseconds.
DATETIME twGetSystemTime | ( | char | utc | ) |
Gets the current system time.
[in] | utc | Currently unused. |
void twGetSystemTimeString | ( | char * | s, |
const char * | format, | ||
int | length, | ||
char | msec, | ||
char | utc | ||
) |
Gets the current system time as a string.
[in,out] | s | A pointer to the string to write the time to. |
[in] | format | A string describing how to format the time (via sprintf()). |
[in] | length | The length of the string. |
[in] | msec | If #TRUE, get time in milliseconds. |
[in] | utc | If #TRUE, get coordinated universal time. |
void twGetTimeString | ( | DATETIME | time, |
char * | s, | ||
const char * | format, | ||
int | length, | ||
char | msec, | ||
char | utc | ||
) |
Converts a DATETIME to a string.
[in] | time | The DATETIME to convert. |
[in,out] | s | A pointer to the string to write the time to. |
[in] | format | A string describing how to format the time (via sprintf()). |
[in] | length | The length of the string. |
[in] | msec | If #TRUE, get time in milliseconds. |
[in] | utc | If #TRUE, get coordinated universal time. |
TW_MUTEX twMutex_Create | ( | ) |
Creates a new ::twMutex.
void twMutex_Delete | ( | TW_MUTEX | m | ) |
Frees all memory associated with a ::twMutex and all of its owned substructures.
[in] | m | A pointer to the ::twMutex to delete. |
void twMutex_Lock | ( | TW_MUTEX | m | ) |
Locks a ::twMutex.
[in] | m | A pointer to the ::twMutex to lock. |
void twMutex_Unlock | ( | TW_MUTEX | m | ) |
Unlocks a ::twMutex.
[in] | m | A pointer to the ::twMutex to unlock. |
int twSocket_Close | ( | twSocket * | s | ) |
int twSocket_Connect | ( | twSocket * | s | ) |
twSocket* twSocket_Create | ( | const char * | host, |
int16_t | port, | ||
uint32_t | options | ||
) |
Creates a new twSocket.
[in] | host | The host name of the server. |
[in] | port | The port the server is listening on. |
[in] | options | Currently unused. |
int twSocket_Delete | ( | twSocket * | s | ) |
int twSocket_GetLastError | ( | ) |
Gets the errno of the last operation.
int twSocket_Read | ( | twSocket * | s, |
char * | buf, | ||
int | len, | ||
int | timeout | ||
) |
int twSocket_Reconnect | ( | twSocket * | s | ) |
int twSocket_WaitFor | ( | twSocket * | s, |
int | timeout | ||
) |
int twSocket_Write | ( | twSocket * | s, |
char * | buf, | ||
int | len, | ||
int | timeout | ||
) |