aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-transport-rta/ccnx/transport/transport_rta/rta_Transport.h
blob: 44ac7cb06ec5d11a439416613c3c5d229f5b074d (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
/*
 * 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.
 */


#include <stdint.h>
#include <ccnx/transport/common/transport.h>

/**
 * rtaTransport executes in the API's thread.  It glues the bottom half of
 * the Transport API to the RTA transport.  It owns and manages a worker thread
 * in which the event schduler executes.
 *
 * rtaTransport is thread safe.  You may have multiple threads using the same
 * transport context.
 *
 * Inside the worker thread, the event scheduler executes without locks.  Therefore we need
 * to message pass to it and have it execute our commands in a managed callback.
 * This is done by passing commands (JSON) over a socket pair.
 *
 * Inside the worker thread, rta_Framework provides service utilities to components
 * and connectors.  It also manages the command socket.
 *
 * When an API calls <code>int rtaTransport_Open(CCNxJSON *params)</code>, rtaTransport
 * will create a socket pair and give one back to the api (api_fd) and send one to
 * rtaFramework (transport_fd).
 *
 * The socket commands are (in JSON):
 *
 * PARAMS := existing SYSTEM and USER JSON objects, i.e.:
 * { "SYSTEM" : {...}, "USER" : {...} }
 *
 * { "RTA" : { "CREATE STACK" : stack_id, PARAMS }
 * { "RTA" : { "OPEN" : [stack_id, api_fd, transport_fd], PARAMS } }
 * { "RTA" : { "CLOSE": transport_fd } }
 * { "RTA" : { "DESTROY STACK": stack_id } }
 * { "RTA" : { "SHUTDOWN" }
 *
 * See rta_Commands.h for an implementation of this.
 */
#ifndef Libccnx_rta_Transport_h
#define Libccnx_rta_Transport_h

#include <ccnx/transport/common/transport.h>
#include <ccnx/transport/transport_rta/commands/rta_Command.h>

/**
 * Transport Ready To Assemble context
 *
 */
struct rta_transport;
typedef struct rta_transport RTATransport;

/**
 * Structure of function points to operate on Transport RTA
 *
 */
extern const struct transport_operations rta_ops;

/**
 * Create the transport.  No locks here, as rtaFramework_Create and rtaFramework_Start
 * are thread-safe functions and we dont maintain any data.
 *
 */
RTATransport *rtaTransport_Create(void);

int rtaTransport_Destroy(RTATransport **ctxPtr);

int rtaTransport_Open(RTATransport *ctx, CCNxTransportConfig *transportConfig);

/**
 * Send a CCNxMetaMessage on the outbound direction of the stack.
 *
 * @param [in] transport A pointer to a valid RTATransport instance.
 * @param [in] queueId The identifier of the asynchronous queue between the top and bottom halves of the stack.
 * @param [in] message A pointer to a valid CCNxMetaMessage instance.
 *
 * @return true The send was successful
 * @return false The send was not successful
 */
//bool rtaTransport_Send(RTATransport *transport, int queueId, const CCNxMetaMessage *message, const struct timeval *restrict timeout);
bool rtaTransport_Send(RTATransport *transport, int queueId, const CCNxMetaMessage *message, const uint64_t *microSeconds);

TransportIOStatus rtaTransport_Recv(RTATransport *transport, const int queueId, CCNxMetaMessage **msgPtr, const uint64_t *microSeconds);

int rtaTransport_Close(RTATransport *transport, int desc);

int rtaTransport_PassCommand(RTATransport *transport, const RtaCommand *rtacommand);

#endif // Libccnx_rta_Transport_h