aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-portal/ccnx/api/ccnx_Portal/ccnx_PortalStack.h
blob: b119213a86042ccaad3dcaf0b81b2a981ed6b9d9 (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
/*
 * 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 ccnx_PortalStack.h
 * @brief A polymorphic interface to different Portal Stack implementations.
 *
 */
#ifndef CCNx_Portal_API_ccnx_PortalImplementation_h
#define CCNx_Portal_API_ccnx_PortalImplementation_h

struct CCNxPortalStack;
/**
 * @typedef CCNxPortalStack
 * @brief A set of functions and state for the Portal instance.
 */
typedef struct CCNxPortalStack CCNxPortalStack;

#include <parc/algol/parc_Properties.h>
#include <ccnx/api/ccnx_Portal/ccnx_PortalFactory.h>

/**
 * Create function for a `CCNxPortalStack`
 *
 * @param [in] factory An instance of a {@link CCNxPortalFactory}.
 * @param [in] start A pointer to a function that takes `*privateData` as a parameter.
 * @param [in] stop A pointer to a function that takes `*privateData` as a parameter.
 * @param [in] receiveFunction A pointer to a function that takes `*privateData` as a parameter and returns a pointer to a {@link CCNxMetaMessage}.
 * @param [in] send A pointer to a function that takes `*privateData` and `*portalMessage` as parameters.
 * @param [in] listen A pointer to a function that takes `*privateData` and a {@link CCNxName} as parameters.
 * @param [in] ignore A pointer to a function that takes `*privateData` and a {@link CCNxName} as parameters.
 * @param [in] getFileId A pointer to a function that takes `*privateData` as a parameter and returns an `int`.
 * @param [in] setAttributes A pointer to a function that takes `*privateData` and a {@link CCNxPortalAttributes} as parameters.
 * @param [in] getAttributes A pointer to a function that takes `*privateData` as a parameter and returns an instance of `CCNxPortalAttributes`.
 * @param [in] privateData A pointer to some data.
 * @param [in] releasePrivateData A pointer to a function that takes `**privateData` as a parameter.
 *
 * @return  A pointer to a new `CCNxPortalStack`.
 *
 */
CCNxPortalStack *
ccnxPortalStack_Create(const CCNxPortalFactory *factory,
                       const CCNxPortalAttributes *attributes,
                       void (*start)(void *privateData),
                       void (*stop)(void *privateData),
                       CCNxMetaMessage *(*receive)(void *privateData, const CCNxStackTimeout *microSeconds),
                       bool (*send)(void *privateData, const CCNxMetaMessage *message, const CCNxStackTimeout *microSeconds),
                       bool (*listen)(void *privateData, const CCNxName *name, const CCNxStackTimeout *microSeconds),
                       bool (*ignore)(void *privateData, const CCNxName *name, const CCNxStackTimeout *microSeconds),
                       int (*getFileId)(void *privateData),
                       bool (*setAttributes)(void *privateData, const CCNxPortalAttributes *attributes),
                       CCNxPortalAttributes * (*getAttributes)(void *privateData),
                       void *privateData,
                       void (*releasePrivateData)(void **privateData));

/**
 * Increase the number of references to a `PARCBuffer`.
 *
 * Note that new `PARCBuffer` is not created,
 * only that the given `PARCBuffer` reference count is incremented.
 * Discard the reference by invoking `parcBuffer_Release`.
 *
 * @param [in] portal A pointer to a valid CCNxPortalStack instance.
 *
 * @return The input `CCNxPortalStack` pointer.
 *
 * Example:
 * @code
 * {
 *     PARCBuffer *x = parcBuffer_Allocate(10);
 *
 *     PARCBuffer *x_2 = parcBuffer_Acquire(x);
 *
 *     parcBuffer_Release(&x);
 *     parcBuffer_Release(&x_2);
 * }
 * @endcode
 */
CCNxPortalStack *ccnxPortalStack_Acquire(const CCNxPortalStack *portal);

/**
 * Release a previously acquired reference to the specified `CCNxPortalStack` 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] portalPtr A pointer to a pointer to a `CCNxPortalStack` instance to be released.
 *
 * Example:
 * @code
 * {
 *     CCNxPortalStack *stack = ccnxPortalStack_Create(...);
 *
 *     ccnxPortalStack_Release(&stack);
 * }
 * @endcode
 *
 * @see {@link ccnxPortalStack_Create}
 * @see {@link ccnxPortalStack_Acquire}
 */
void ccnxPortalStack_Release(CCNxPortalStack **portalPtr);

/**
 * Release a `CCNxPortalStack` reference.
 *
 * Only the last invocation where the reference count is decremented to zero,
 * will actually destroy the `CCNxPortalStack`.
 *
 * @param [in,out] instancePtr is a pointer to the `CCNxPortalStack` reference to be released.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void ccnxPortalStack_Release(CCNxPortalStack **instancePtr);

/**
 * Start a `CCNxPortalStack`
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`
 *
 * @return `true` if stack started successfully, else `false`.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool ccnxPortalStack_Start(const CCNxPortalStack *implementation);

/**
 * Stop a `CCNxPortalStack`
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`
 *
 * @return `true` if stack started successfully, else `false`.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool ccnxPortalStack_Stop(const CCNxPortalStack *implementation);

/**
 * Receive a message from a `CCNxPortalStack`
 *
 * @param [in] portalStack A pointer to an instance of `CCNxPortalStack`
 * @param [in] microSeconds A pointer to a `struct timeval` or NULL indicating no timeout.
 *
 * @return An instance of {@link CCNxMetaMessage}.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CCNxMetaMessage *ccnxPortalStack_Receive(const CCNxPortalStack *portalStack, const CCNxStackTimeout *microSeconds);

/**
 * Send a message through a `CCNxPortalStack`
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`.
 * @param [in] portalMessage A pointer to an instance of `CCNxMetaMessage` to send.
 *
 * @return `true` if message sent successfully, else `false`.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool ccnxPortalStack_Send(const CCNxPortalStack *implementation, const CCNxMetaMessage *portalMessage, const CCNxStackTimeout *microSeconds);

/**
 * Set the attributes on a `CCNxPortalStack`.
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`.
 * @param [in] attributes A pointer to an instance of `CCNxPortalAttributes`.
 * @return `true` if attributes set successfully, else `false`.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */

bool ccnxPortalStack_SetAttributes(const CCNxPortalStack *implementation, const CCNxPortalAttributes *attributes);

/**
 * Get the attributes from a `CCNxPortalStack`.
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`.
 * @return A pointer to an instance of `CCNxPortalAttributes` associated with the @p implementation.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
const CCNxPortalAttributes *ccnxPortalStack_GetAttributes(const CCNxPortalStack *implementation);

/**
 * Listen for @p name on the @p implementation.
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`.
 * @param [in] name A pointer to an instance of {@link CCNxName} to listen for.
 *
 * @return `true` if listen started successfully, else `false`.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool ccnxPortalStack_Listen(const CCNxPortalStack *implementation, const CCNxName *name, const CCNxStackTimeout *microSeconds);
/**
 * Ignore (stop listening for) @p name on the @p implementation.
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`.
 * @param [in] name A pointer to an instance of {@link CCNxName} to listen for.
 *
 * @return `true` if ignore was successful, else `false`.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */

bool ccnxPortalStack_Ignore(const CCNxPortalStack *implementation, const CCNxName *name, const CCNxStackTimeout *microSeconds);
/**
 * Get the file ID for @p implementation.
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`.
 *
 * @return `int` The file ID.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
int ccnxPortalStack_GetFileId(const CCNxPortalStack *implementation);

/**
 * Get the {@link PARCKeyId} associated with the @p implementation.
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`.
 *
 * @return A pointer to the `PARCKeyId`.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
const PARCKeyId *ccnxPortalStack_GetKeyId(const CCNxPortalStack *implementation);

/**
 * Get the error code for the most recent operation.
 *
 * @param [in] implementation A pointer to an instance of `CCNxPortalStack`.
 *
 * @return A value corresponding to the UNIX `errno`  see `sys/errno.h`
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 */
int ccnxPortalStack_GetErrorCode(const CCNxPortalStack *implementation);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [<#in#> | <#out#> | <#in,out#>] <#name#> <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 */
PARCProperties *ccnxPortalStack_GetProperties(const CCNxPortalStack *portalStack);

/**
 * <#One Line Description#>
 *
 * <#Paragraphs Of Explanation#>
 *
 * @param [in] portalStack <#description#>
 * @param [in] name <#description#>
 * @param [in] defaultValue <#description#>
 *
 * @return <#value#> <#explanation#>
 *
 * Example:
 * @code
 * {
 *     <#example#>
 * }
 * @endcode
 */
const char *ccnxPortalStack_GetProperty(const CCNxPortalStack *portalStack, const char *restrict name, const char *restrict defaultValue);
#endif