ThingWorx C SDK
twMessages.h
1 /*
2  * Copyright (C) 2015 ThingWorx Inc.
3  *
4  * Portable ThingWorx Binary Messaging layer
5  */
6 
7 #include "twOSPort.h"
8 #include "twDefinitions.h"
9 #include "twDefaultSettings.h"
10 #include "twErrors.h"
11 #include "twWebsocket.h"
12 #include "twBaseTypes.h"
13 #include "twInfoTable.h"
14 #include "twList.h"
15 
16 #ifndef TW_MESSAGES_H
17 #define TW_MESSAGES_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /***************************************/
24 /* Entities below this line are */
25 /* typically not directtly used */
26 /* by application developers */
27 /***************************************/
28 
32 typedef struct twMessage {
33  enum msgType type;
34  unsigned char version;
35  enum msgCodeEnum code;
36  uint32_t requestId;
37  uint32_t endpointId;
38  uint32_t sessionId;
39  char multipartMarker;
40  uint32_t length;
41  void * body;
42 } twMessage;
43 
44 twMessage * twMessage_Create(enum msgCodeEnum code, uint32_t reqId); /* Set Reqid to zero to autogenerate ID */
45 twMessage * twMessage_CreateRequestMsg(enum msgCodeEnum code);
46 twMessage * twMessage_CreateResponseMsg(enum msgCodeEnum code, uint32_t id);
47 twMessage * twMessage_CreateBindMsg(char * name, char isUnbind);
48 twMessage * twMessage_CreateAuthMsg(char * claimName, char * claimValue);
49 twMessage * twMessage_CreateFromStream(twStream * s);
50 void twMessage_Delete(void * input);
51 int twMessage_Send(struct twMessage * msg, struct twWs * ws);
52 int twMessage_SetBody(struct twMessage * msg, void * body);
53 
57 typedef struct twHeader {
58  char * name;
59  char * value;
60 } twHeader;
61 
62 typedef struct twRequestBody {
63  enum entityTypeEnum entityType;
64  char * entityName;
65  enum characteristicEnum characteristicType;
66  char * characteristicName;
67  char numHeaders;
68  twList * headers;
69  twInfoTable * params;
70  uint32_t length;
72 
73 twRequestBody * twRequestBody_Create();
74 twRequestBody * twRequestBody_CreateFromStream(twStream * s);
75 int twRequestBody_Delete(struct twRequestBody * body);
76 int twRequestBody_SetParams(struct twRequestBody * body, twInfoTable * params);
77 int twRequestBody_SetEntity(struct twRequestBody * body, enum entityTypeEnum entityType, char * entityName);
78 int twRequestBody_SetCharateristic(struct twRequestBody * body, enum characteristicEnum characteristicType, char * characteristicName);
79 int twRequestBody_AddHeader(struct twRequestBody * body, char * name, char * value);
80 int twRequestBody_ToStream(struct twRequestBody * body, twStream * s);
81 
85 typedef struct twResponseBody {
86  char reasonMarker;
87  char * reason;
88  enum BaseType contentType;
89  twInfoTable * content;
90  uint32_t length;
92 
93 twResponseBody * twResponseBody_Create();
94 twResponseBody * twResponseBody_CreateFromStream(twStream * s);
95 int twResponseBody_Delete(struct twResponseBody * body);
96 int twResponseBody_SetContent(struct twResponseBody * body, twInfoTable * t);
97 int twResponseBody_SetReason(struct twResponseBody * body, char * reason);
98 int twResponseBody_ToStream(struct twResponseBody * body, twStream * s);
99 
103 typedef struct twAuthBody {
104  /* Limit to 1 claim */
105  char * name;
106  char * value;
107  uint32_t length;
108 } twAuthBody;
109 
110 twAuthBody * twAuthBody_Create();
111 twAuthBody * twAuthBody_CreateFromStream(twStream * s);
112 int twAuthBody_Delete(struct twAuthBody * body);
113 int twAuthBody_SetClaim(struct twAuthBody * body, char * name, char * value);
114 int twAuthBody_ToStream(struct twAuthBody * body, twStream * s);
115 
116 
120 typedef struct twBindBody {
121  char * gatewayName;
122  char * gatewayType;
123  uint16_t count;
124  struct twList * names;
125  uint32_t length;
126 } twBindBody;
127 
128 twBindBody * twBindBody_Create(char * name);
129 twBindBody * twBindBody_CreateFromStream(twStream * s);
130 int twBindBody_Delete(struct twBindBody * body);
131 int twBindBody_AddName(struct twBindBody * body, char * name);
132 int twBindBody_ToStream(struct twBindBody * body, twStream * s, char * gatewayName, char * gatewayType);
133 
137 typedef struct twMultipartBody {
138  uint16_t chunkId;
139  uint16_t chunkCount;
140  uint16_t chunkSize;
141  enum entityTypeEnum entityType;
142  char * entityName;
143  char * data;
144  uint16_t length;
146 
147 twMultipartBody * twMultipartBody_CreateFromStream(twStream * s, char isRequest);
148 void twMultipartBody_Delete(void * body);
149 
151  uint64_t expirationTime;
152  uint32_t id;
153  uint16_t chunksExpected;
154  uint16_t chunksReceived;
155  twMessage ** msgs; /* Array of message pointers */
157 
158 mulitpartMessageStoreEntry * mulitpartMessageStoreEntry_Create(twMessage * msg);
159 void mulitpartMessageStoreEntry_Delete(void * entry);
160 
164 typedef struct twMultipartMessageStore {
165  twList * multipartMessageList;
166  TW_MUTEX mtx;
168 
169 twMultipartMessageStore * twMultipartMessageStore_Instance();
170 void twMultipartMessageStore_Delete(void * store);
171 twMessage * twMultipartMessageStore_AddMessage(twMessage * msg);
172 void twMultipartMessageStore_RemoveStaleMessages();
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif
msgType
Enumeration of HTTP message types.
Definition: twDefinitions.h:58
Definition: twMessages.h:85
Websocket client abstraction layer.
Definition: twMessages.h:137
ThingWorx twInfoTable and twDataShape definitions and functions.
ThingWorx C SDK error code definitions.
#define TW_MUTEX
For Linux builds a TW_MUTEX is a pthread_mutex_t.
Definition: twLinux-openssl.h:81
Dynamically allocated byte array. Automatically expands its length as needed.
Definition: twBaseTypes.h:35
Wrappers for OS-specific functionality.
Linked list structure definition.
Definition: twList.h:46
Definition: twMessages.h:57
Definition: twMessages.h:120
Definition: twMessages.h:62
entityTypeEnum
Definition: twDefinitions.h:113
msgCodeEnum
Enumeration of HTTP message codes.
Definition: twDefinitions.h:74
characteristicEnum
Definition: twDefinitions.h:146
Default settings for ThingWorx C SDK.
Common definitions for C SDK.
ThingWorx BaseType definitions and functions.
Definition: twMessages.h:32
Info table base structure.
Definition: twInfoTable.h:418
Definition: twMessages.h:103
Definition: twMessages.h:164
Websocket entity structure definition.
Definition: twWebsocket.h:65
Definition: twMessages.h:150
BaseType
Definition: twDefinitions.h:155