]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/proto.h
Source files moved to a separate directory
[frescor/forb.git] / src / proto.h
1 /**
2  * @file   proto.h
3  * @author Michal Sojka <sojkam1@fel.cvut.cz>
4  * @date   Thu Aug 28 10:36:23 2008
5  * 
6  * @brief  FORB transport protocol module
7  * 
8  * 
9  */
10
11 #ifndef FORB_PROTO_H
12 #define FORB_PROTO_H
13
14 #include "forb-internal.h"
15 #include "syncobj.h"
16 #include "request.h"
17 #include <ul_logbase.h>
18 #include "port.h"
19 #include "peer.h"
20
21 typedef struct forb_proto forb_proto_t;
22
23 /**
24  * Description of a FORB transport protocol.
25  */
26 struct forb_proto {
27         /** Number of seconds between sending of HELLO messages for discovery process */
28         unsigned hello_interval;
29
30         /** 
31          * Called to free any protocol resources associated with the port.
32          * 
33          * @param port The port to be destroyed.
34          * 
35          * @return Zero on success, negatove error code on error.
36          */
37         int (*port_destroy)(forb_port_t *port);
38
39         /** 
40          * Sends data to a peer.
41          *
42          * If the protocol is connection-oriented, the connection data
43          * can be stored at @c port->proto_priv and used by later
44          * requests.
45          * 
46          * @param peer Peer to send data
47          * @param buf Data to send
48          * @param len Length of data to send
49          * 
50          * @return Length of the sent data (should be equal to @a len on
51          * success) or negative error code on error.
52          */
53         size_t (*send)(forb_peer_t *peer, const void *buf, size_t len);
54
55         /** 
56          * Called to free any protocol resources associated with the
57          * peer.
58          * 
59          * @param peer Peer to destroy
60          * 
61          * @return Zero on success, negatove error code on error.
62          */
63         int (*peer_destroy)(forb_peer_t *peer);
64         /** 
65          * Receives data through a port
66          * 
67          * @param port Port to use 
68          * @param buf Where to store the received data
69          * @param len Length the buffer @a buf
70          * 
71          * @return Length of the received data or negative error code
72          * on error.
73          */
74         size_t (*recv)(forb_port_t *port, void *buf, size_t len);
75
76         /** 
77          * Broadcasts/multicasts a message. All FORBs connected the
78          * the network/bus represented by the @a port should receive
79          * it.
80          *
81          * This function is used by peer discovery protocol.
82          * 
83          * @param port Port to use 
84          * @param buf Data to broadcast 
85          * @param len Length of the @a data
86          * 
87          * @return Zero or positive number on success, negative error
88          * code on error.
89          */
90         size_t (*broadcast)(forb_port_t *port, const void *buf, size_t len);
91
92         /** Serializes the protocol specific address */
93         CORBA_boolean (*serialize_addr)(CDR_Codec *codec, const void *addr);
94
95         /** Deserializes the protocol specific address */
96         CORBA_boolean (*deserialize_addr)(CDR_Codec *codec, void **addr);
97 };
98
99 size_t forb_proto_send(forb_peer_t *peer, CDR_Codec *codec);
100
101 forb_peer_t *
102 forb_get_next_hop(forb_t *forb, forb_server_id *server);
103
104
105 #endif