aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-transport-rta/ccnx/transport/transport_rta/commands/rta_CommandDestroyProtocolStack.h
blob: feecfac91d94d0d118713d5dc29df0c2ede415d2 (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
/*
 * 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 rta_CommandDestroyProtocolStack.h
 * @brief Represents a command to destroy a protocol stack
 *
 * Used to construct an RtaCommand object that is passed to rtaTransport_PassCommand() or _rtaTransport_SendCommandToFramework()
 * to send a command from the API's thread of execution to the Transport's thread of execution.
 *
 */
#ifndef Libccnx_rta_CommandDestroyProtocolStack_h
#define Libccnx_rta_CommandDestroyProtocolStack_h

struct rta_command_destroyprotocolstack;
typedef struct rta_command_destroyprotocolstack RtaCommandDestroyProtocolStack;

/**
 * Creates a DestroyProtocolStack command object
 *
 * Creates a DestroyProtocolStack command object used to signal the RTA framework to
 * destroy a protocol stack and all connections in it.
 *
 * @param [in] stackId The ID used to create the protocol stack.
 *
 * @return non-null An allocated object
 * @return null An error
 *
 * Example:
 * @code
 * void foo(RTATransport *transport)
 * {
 *     int stackId = nextStackIdNumber();
 *     CCNxStackConfig *config = ccnxStackConfig_Create();
 *
 *     RtaCommandCreateProtocolStack *createStack = rtaCommandCreateProtocolStack_Create(stackId, config);
 *     RtaCommand *command = rtaCommand_CreateCreateProtocolStack(createStack);
 *     _rtaTransport_SendCommandToFramework(transport, command);
 *     rtaCommand_Release(&command);
 *     rtaCommandCreateProtocolStack_Release(&createStack);
 *
 *     // ... do work ...
 *
 *     RtaCommandDestroyProtocolStack *destroyStack = rtaCommandDestroyProtocolStack_Create(stackId);
 *     command = rtaCommand_CreateDestroyProtocolStack(destroyStack);
 *     _rtaTransport_SendCommandToFramework(transport, command);
 *     rtaCommand_Release(&command);
 *     rtaCommandDestroyProtocolStack_Release(&destroyStack);
 *     ccnxStackConfig_Release(&config);
 * }
 * @endcode
 */
RtaCommandDestroyProtocolStack *rtaCommandDestroyProtocolStack_Create(int stackId);

/**
 * Increase the number of references to a `RtaCommandDestroyProtocolStack`.
 *
 * Note that new `RtaCommandDestroyProtocolStack` is not created,
 * only that the given `RtaCommandDestroyProtocolStack` reference count is incremented.
 * Discard the reference by invoking `rtaCommandDestroyProtocolStack_Release`.
 *
 * @param [in] destroyStack The RtaCommandDestroyProtocolStack to reference.
 *
 * @return non-null A reference to `destroyStack`.
 * @return null An error
 *
 * Example:
 * @code
 * {
 *     CCNxStackConfig *config = ccnxStackConfig_Create();
 *    RtaCommandDestroyProtocolStack *destroyStack = rtaCommandCreateProtocolStack_Create(stackId, config);
 *    RtaCommandDestroyProtocolStack *second = rtaCommandDestroyProtocolStack_Acquire(destroyStack);
 *
 *    // release order does not matter
 *    rtaCommandDestroyProtocolStack_Release(&destroyStack);
 *    rtaCommandDestroyProtocolStack_Release(&second);
 *    ccnxStackConfig_Release(&config);
 * }
 * @endcode
 */
RtaCommandDestroyProtocolStack *rtaCommandDestroyProtocolStack_Acquire(const RtaCommandDestroyProtocolStack *destroyStack);

/**
 * 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] closePtr A pointer to the object to release, will return NULL'd.
 *
 * Example:
 * @code
 * {
 *     RtaCommandDestroyProtocolStack *destroyStack = rtaCommandDestroyProtocolStack_Create(stackId);
 *     RtaCommand *command = rtaCommand_CreateDestroyProtocolStack(destroyStack);
 *     _rtaTransport_SendCommandToFramework(transport, command);
 *     rtaCommand_Release(&command);
 *     rtaCommandDestroyProtocolStack(&destroyStack);
 * }
 * @endcode
 */
void rtaCommandDestroyProtocolStack_Release(RtaCommandDestroyProtocolStack **destroyStackPtr);

/**
 * Returns the Stack ID of the destroy stack command
 *
 * Returns the Stack ID parameter.
 *
 * @param [in] destroyStack An allocated RtaCommandDestroyProtocolStack
 *
 * @return integer The value passed to rtaCommandDestroyProtocolStack_Create().
 *
 * Example:
 * @code
 * {
 *     int stackId = 7;
 *     RtaCommandDestroyProtocolStack *destroyStack = rtaCommandDestroyProtocolStack_Create(stackId);
 *     int testValue = rtaCommandDestroyProtocolStack_GetStackId(destroyStack);
 *     assertTrue(testValue == stackId, "Wrong value got %d expected %d", testValue, stackId);
 *     rtaCommandDestroyProtocolStack(&destroyStack);
 * }
 * @endcode
 */
int rtaCommandDestroyProtocolStack_GetStackId(const RtaCommandDestroyProtocolStack *destroyStack);
#endif // Libccnx_rta_CommandDestroyProtocolStack_h