aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-transport-rta/ccnx/api/notify/notify_Status.h
blob: 3fcdcb1d10695725d4486c993267e349d4fc1cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file notify_Status.h
 *
 * @brief
 * An API to handle notifications from the Transport.
 *
 * These notifications are specific to the RTA Transport, in that they use the Component  model and Component names.
 *
 */
#ifndef Libccnx_notifyStatus_h
#define Libccnx_notifyStatus_h

#include <parc/algol/parc_JSON.h>
#include <ccnx/common/ccnx_Name.h>

struct notify_status;
/**
 * @typedef NotifyStatus
 * @brief Notifications from Transport
 */
typedef struct notify_status NotifyStatus;

// This needs to be replaced with a more sophisticated encoding scheme that individual stack components can use.  Case 1035
/**
 * @typedef NotifyStatusCode
 * @brief Codes for Notify Status
 */
typedef enum {
    // TRANSPORT_READY                       = 1,  // returned when Transport_Create finished
    // TRANSPORT_DESTROYED                   = 2,  // when Transport_Destroy is done
    notifyStatusCode_OPEN_ERROR = 3,               // error when opening a connection stack
    notifyStatusCode_CONNECTION_OPEN = 4,          // returned when a connection is opened
    notifyStatusCode_CONNECTION_CLOSED = 5,        // returned when close is finished
    notifyStatusCode_FORWARDER_NOT_AVAILABLE = 6,  // connection problem with forwarder
    notifyStatusCode_FLOW_CONTROL_STARTED = 7,     // when flow control starts on a name
    notifyStatusCode_FLOW_CONTROL_FINISHED = 8,    // after final block is passed up
    notifyStatusCode_FLOW_CONTROL_ERROR = 9,       // some hard error on the name
    notifyStatusCode_ENCODING_ERROR = 10,          // something bad in the codec
    notifyStatusCode_SIGNING_ERROR = 11,           // error signing
    notifyStatusCode_SEND_ERROR = 12,              // some other "down" stack error
} NotifyStatusCode;

/**
 * @typedef NotifyStatusDirection
 * @brief The direction of the NotifyStatus
 */
typedef enum {
    notifyStatusDirection_UPSTACK,
    notifyStatusDirection_DOWNSTACK
} NotifyStatusDirection;

/**
 * Create an instance of `NotifyStatus`.
 *
 * @param [in] apiFd The corresponding api file descriptor.
 * @param [in] code The NotifyStatusCode for this status.
 * @param [in] name An associated CCNxName
 * @param [in] message An (optional) string message
 *
 * @return NULL An error occurred
 * @return non-NULL A pointer to a valid NotifyStatus instance that must be released via notifyStatus_Release().
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *expected = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 * }
 * @endcode
 *
 * @see {@link notifyStatus_Release}
 */
NotifyStatus *notifyStatus_Create(int apiFd, NotifyStatusCode code, CCNxName *name, const char *message);

/**
 * Increase the number of references to a `NotifyStatus`.
 *
 * Note that new `NotifyStatus` is not created,
 * only that the given `NotifyStatus` reference count is incremented.
 * Discard the reference by invoking {@link notifyStatus_Release}.
 *
 * @param [in] status A pointer to a `NotifyStatus` instance.
 * @return The input `NotifyStatus` pointer.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     NotifyStatus *x_2 = notifyStatus_Acquire(status);
 *
 *     notifyStatus_Release(&status);
 *     notifyStatus_Release(&x_2);
 * }
 * @endcode
 */
NotifyStatus *notifyStatus_Acquire(const NotifyStatus *status);

/**
 * Release a previously acquired reference to the specified instance,
 * decrementing the reference count for the instance.
 *
 * The pointer to the instance is set to NULL as a side-effect of this function.
 *
 * If the invocation causes the last reference to the instance to be released,
 * the instance is deallocated and the instance's implementation will perform
 * additional cleanup and release other privately held references.
 *
 * @param [in,out] statusPtr A pointer to a pointer to the instance to release.
 *
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     notifyStatus_Release(&status);
 * }
 * @endcode
 */
void notifyStatus_Release(NotifyStatus **statusPtr);

/**
 * Returns true if contents of two NotifyStatus objects are the same.
 *
 * @param [in] x object 1
 * @param [in] y object 2
 *
 * @return true X & Y are equal
 * @return false X & Y are not equal
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status1 = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *     NotifyStatus *status2 = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     if (notifyStatus_Equals(status1, status2)) {
 *          ...
 *     }
 * }
 * @endcode
 */
bool notifyStatus_Equals(const NotifyStatus *x, const NotifyStatus *y);

/**
 * Print a human readable representation of the given `NotifyStatus`.
 *
 * @param [in] status A pointer to the instance to display.
 * @param [in] indentation The level of indentation to use to pretty-print the output.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     notifyStatus_Display(status, 0);
 *
 *     notifyStatus_Release(&status);
 * }
 * @endcode
 */
void notifyStatus_Display(const NotifyStatus *status, int indentation);

/**
 * Get the associated file descriptor of the given `NotifyStatus` instance.
 *
 * @param [in] status A pointer to a valid instance of `NotifyStatus`.
 *
 * @return The associated file descriptor of this NotifyStatus instance.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     int fd = notifyStatus_GetFiledes(status);
 * }
 * @endcode
 */
int notifyStatus_GetFiledes(const NotifyStatus *status);

/**
 * Get the associated {@link NotifyStatusCode} of the given `NotifyStatus` instance.
 *
 * @param [in] status A pointer to a valid instance of `NotifyStatus`.
 *
 * @return The associated NotifyStatusCode of the given `NotifyStatus` instance.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     NotifyStatusCode code = notifyStatus_GetStatusCode(status);
 * }
 * @endcode
 */
NotifyStatusCode notifyStatus_GetStatusCode(const NotifyStatus *status);

/**
 * Get the associated {@link CCNxName} of the given `NotifyStatus` instance.
 *
 * @param [in] status A pointer to a valid instance of `NotifyStatus`.
 *
 * @return The `CCNxName` of this `NotifyStatus` instance.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     NotifyStatusCode code = notifyStatus_GetStatusCode(status);
 * }
 * @endcode
 */
CCNxName *notifyStatus_GetName(const NotifyStatus *status);

/**
 * Get the associated {@link CCNxName} of the given `NotifyStatus` instance.
 *
 * @param [in] status A pointer to a valid instance of `NotifyStatus`.
 *
 * @return The message of this NotifyStatus instance.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     NotifyStatusCode code = notifyStatus_GetStatusCode(status);
 * }
 * @endcode
 */
char *notifyStatus_GetMessage(const NotifyStatus *status);

/**
 * Return a {@link PARCJSON} representation of the given `NotifyStatus` instance.
 *
 * @param [in] status A pointer to a valid instance of `NotifyStatus`.
 *
 * @return NULL An error occurred
 * @return non-NULL A pointer to a valid `PARCJSON` instance
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     PARCJSON *json = notifyStatus_ToJSON(status);
 * }
 * @endcode
 */
PARCJSON *notifyStatus_ToJSON(const NotifyStatus *status);

/**
 * Create a new `NotifyStatus` instance from a {@link PARCJSON} instance.
 *
 * @param [in] json A pointer to a `PARCJSON` instance.
 *
 * @return NULL An error occurred
 * @return non-NULL A pointer to a valid `NotifyStatus` instance.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     PARCJSON *json = notifyStatus_ToJSON(status);
 *
 *     NotifyStatus *status2 = notifyStatus_ParseJSON(json)
 * }
 * @endcode
 */
NotifyStatus *notifyStatus_ParseJSON(const PARCJSON *json);

/**
 * Evaluate to `true` if the given `NotifyStatus` indicates a Connection Open.
 *
 * @param [in] status  A pointer to a `NotifyStatus` instance.
 *
 * @return `true` The given `NotifyStatus` indicates a Connection open.
 * @return `false` The given ``NotifyStatus` indicates that the Connection is not open.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     if (notifyStatus_IsConnectionOpen(status)) {
 *         printf("Connection is open\n");
 *     }
 * }
 * @endcode
 */
bool notifyStatus_IsConnectionOpen(const NotifyStatus *status);

/**
 * Return `true` if the given status indicates that the flow control has started.
 *
 * @param [in] status  A pointer to a NotifyStatus instance.
 *
 * @return `true` The given `NotifyStatu`s indicates that flow controller has started
 * @return `false` The given `NotifyStatus` indicates that the flow controller has not started.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c");
 *     NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go");
 *
 *     if (notifyStatus_IsFlowControlStarted(status)) {
 *         printf("Flow controller has started\n");
 *     }
 * }
 * @endcode
 */
bool notifyStatus_IsFlowControlStarted(const NotifyStatus *status);
#endif // Libccnx_notifyStatus_h