aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-transport-rta/ccnx/api/control/cpi_ControlFacade.h
blob: 26d84f229d085715f60a87615e99fe4f3afaa9d1 (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
/*
 * 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 cpi_ControlFacade.h
 * @ingroup Utility
 * @brief <#Brief Description#>
 *
 * A ControlFacade has several flavors.  A Notification is a spontaneous message
 * sent as an indication of some state or condition.  A CPI (ControlPlaneInterface)
 * message is a Request/Reponse protocol used to manage the Transport.
 *
 * The ccnxControlFacade takes ownership of the JSON object
 * and will destroy it when it's Destroy is called.
 *
 * If put inside a CCNxMetaMessage and sent to the Transport, the Transport
 * takes ownership of the CCNxMetaMessage and will thus be responsible for
 * destroying the object.
 *
 */
#ifndef libccnx_ccnx_ControlFacade_h
#define libccnx_ccnx_ControlFacade_h

#include <ccnx/common/ccnx_Name.h>
#include <ccnx/api/control/cpi_ControlMessage.h>

#include <ccnx/common/internal/ccnx_TlvDictionary.h>

typedef enum {
    CCNxControlMessage_Unknown = 0,
    CCNxControlMessage_CPI = 1,
    CCNxControlMessage_Notify = 2
} CCNxControlFacadeType;

// =====================

/**
 * Creates a Nofification control message from the supplied JSON object.
 *
 * The newly created instance must eventually be released by calling
 * {@link ccnxControl_Release}.
 *
 * @param ccnxJson the JSON object to include in the message.
 * @return A `CCNxControl` message.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CCNxControl *ccnxControlFacade_CreateNotification(PARCJSON *ccnxJson);

/**
 * Creates a CPI message from the supplied JSON object.
 *
 * The newly created instance must eventually be released by calling
 * {@link ccnxControl_Release}.
 *
 * @param ccnxJson the JSON to include with the message.
 * @return A `CCNxControl` message.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CCNxControl *ccnxControlFacade_CreateCPI(PARCJSON *ccnxJson);

// =====================
// Getters

/**
 * Return a pointer to the JSON object contained in the control message.
 *
 *   <#Discussion#>
 *
 * @param controlDictionary the control message to retrieve the JSON from.
 * @return the PARCJSON object from the control message.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCJSON *ccnxControlFacade_GetJson(const CCNxTlvDictionary *controlDictionary);

/**
 * Test whether a control message is a Notification.
 *
 *   <#Discussion#>
 *
 * @param controlDictionary the control message to test.
 * @return true if the control message is a Notification.
 * @return false if the control message is not a Notification.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool ccnxControlFacade_IsNotification(const CCNxTlvDictionary *controlDictionary);

/**
 * Test whether a control message is a CPI (Control Plane Interface) message.
 *
 *   <#Discussion#>
 *
 * @param controlDictionary the control message to test.
 * @return true if the control message is a CPI message.
 * @return false if the control message is not a CPI message.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
bool ccnxControlFacade_IsCPI(const CCNxTlvDictionary *controlDictionary);


// =====================
// Miscellaneous

/**
 * Print a human readable representation of the given `CCNxTlvDictionary` representing
 * a control message.
 *
 * @param [in] name A pointer to the `CCNxTlvDictionary` instance representing a CCNxControl.
 * @param [in] indentation The level of indentation to use to pretty-print the output.
 *
 * Example:
 * @code
 * {
 *     CCNxTlvDictionary *controlMessage = ccnxControlFacade_CreateCPI(...);
 *     ccnxControlFacade_Display(controlMessage);
 *     ...
 * }
 * @endcode
 */
void ccnxControlFacade_Display(const CCNxTlvDictionary *controlDictionary, int indentation);

/**
 * Produce a null-terminated string representation of the specified CCNxTlvDictionary instance
 * representing a control message.
 *
 * The non-null result must be freed by the caller via {@link parcMemory_Deallocate}.
 *
 * @param [in] name A pointer to the `CCNxTlvDictionary` instance representing a CCNxControl.
 *
 * @return NULL Cannot allocate memory.
 * @return non-NULL A pointer to an allocated,
 *         null-terminated C string that must be deallocated via `parcMemory_Deallocate()`.
 *
 * Example:
 * @code
 * {
 *      char *desc = ccnxControlFacade_ToString(controlDictionary);
 *      printf("%s\n", desc);
 *      parcMemory_Deallocate((void **) &desc);
 *
 *      ccnxTlvDictionary_Release(&control);
 * }
 * @endcode
 *
 * @see {@link ccnxControlFacade_Display}
 * @see {@link parcMemory_Deallocate}
 */
char *ccnxControlFacade_ToString(const CCNxTlvDictionary *controlDictionary);

/**
 * Assert that an instance of `CCNxTlvDictionary` is a valid control message.
 *
 * If the instance is not valid, terminate via {@link trapIllegalValue}
 *
 * Valid means the internal state of the type is consistent with its
 * required current or future behaviour.
 * This may include the validation of internal instances of types.
 *
 * @param [in] name A pointer to a `CCNxName` instance.
 *
 * Example:
 * @code
 * {
 *     CCNxControl *controlMessage = ccnxControlFacade_CreateCPI(...);
 *     ccnxControlFacade_AssertValid(controlMessage);
 *     ...
 * }
 * @endcode
 */
void ccnxControlFacade_AssertValid(const CCNxTlvDictionary *controlDictionary);
#endif // libccnx_ccnx_ControlFacade_h