]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/peer.h
Discovery handling moved to discovery.c
[frescor/forb.git] / src / peer.h
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
5 /*   Universidad de Cantabria,              SPAIN                         */
6 /*   University of York,                    UK                            */
7 /*   Scuola Superiore Sant'Anna,            ITALY                         */
8 /*   Kaiserslautern University,             GERMANY                       */
9 /*   Univ. Politécnica  Valencia,           SPAIN                        */
10 /*   Czech Technical University in Prague,  CZECH REPUBLIC                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
19 /*          FRESCOR project (FP6/2005/IST/5-034026) is funded             */
20 /*       in part by the European Union Sixth Framework Programme          */
21 /*       The European Union is not liable of any use that may be          */
22 /*       made of this code.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FORB (Frescor Object Request Broker)             */
26 /*                                                                        */
27 /* FORB is free software; you can redistribute it and/or modify it        */
28 /* under terms of the GNU General Public License as published by the      */
29 /* Free Software Foundation; either version 2, or (at your option) any    */
30 /* later version.  FORB is distributed in the hope that it will be        */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
33 /* General Public License for more details. You should have received a    */
34 /* copy of the GNU General Public License along with FORB; see file       */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
36 /* Cambridge, MA 02139, USA.                                              */
37 /*                                                                        */
38 /* As a special exception, including FORB header files in a file,         */
39 /* instantiating FORB generics or templates, or linking other files       */
40 /* with FORB objects to produce an executable application, does not       */
41 /* by itself cause the resulting executable application to be covered     */
42 /* by the GNU General Public License. This exception does not             */
43 /* however invalidate any other reasons why the executable file might be  */
44 /* covered by the GNU Public License.                                     */
45 /**************************************************************************/
46
47 /**
48  * @file   peer.h
49  * @author Michal Sojka <sojkam1@fel.cvut.cz>
50  * @date   Sun Oct 12 17:31:51 2008
51  * 
52  * @brief  Declarations of peer data structure and functions.
53  * 
54  * 
55  */
56
57 #ifndef FORB_PEER_H
58 #define FORB_PEER_H
59
60 #include <forb/forb-internal.h>
61 #include "port.h"
62 #include "refcnt.h"
63 #include <ul_gavl.h>
64 #include <ul_list.h>
65 #include <fosa_mutexes_and_condvars.h>
66 /**
67  * State of a peer.
68  * 
69  */
70 enum forb_peer_state {
71         FORB_PEER_WANTED,       /**< Somebody is waiting for the peer to be discovered. In this state, only @a server_id field is set. */
72         FORB_PEER_DISCOVERED,   /**< The peer is already discovered, so it is addr is known and messages can be sent to him. */
73 };
74
75 /**
76  * Description of a peer FORB. We consider peers only in one-hop
77  * distance. For more distant forbs, we need to use a routing table.
78  *
79  * @note This structure is reference counted. Use forb_peer_get() when
80  * you copy a pointer to peer and forb_peer_put() when the pointer is
81  * not needed.
82  */
83 typedef struct forb_peer {
84          forb_server_id server_id; /**< Server_id of the peer */
85          forb_port_t *port;     /**< Port of this peer is connected to */
86          void *addr;            /**< Protocol specific address of the peer. */
87          char *orb_id;          /**< ORB ID of the peer */
88          void *proto_priv;      /**< Protocol private data (e.g. info about established connection) */
89          gavl_node_t gnode;     /**< Node of forb_t::peers tree */
90          ul_list_node_t lnode;  /**< Node of forb_port_t::peers list */
91          forb_ref_t ref;        /**< Reference count */
92          enum forb_peer_state state;
93          fosa_cond_t cond;      /**< Condition variable for waiting after the peer is discovered. Used together with forb_t::peer_mutex. */
94          fosa_mutex_t send_lock;
95 } forb_peer_t;
96
97 UL_LIST_CUST_DEC(forb_port_peer, /* cust_prefix */
98                  forb_port_t,    /* cust_head_t */
99                  forb_peer_t,    /* cust_item_t */
100                  peers,          /* cust_head_field */
101                  lnode)          /* cust_node_field */
102
103 forb_peer_t *
104 forb_peer_new(void);
105
106 void
107 forb_peer_release(forb_ref_t *ref);
108
109 static inline forb_peer_t *
110 forb_peer_get(forb_peer_t *peer)
111 {
112         forb_ref_get(&peer->ref);
113         return peer;
114 }
115         
116 static inline void
117 forb_peer_put(forb_peer_t *peer)
118 {
119         forb_ref_put(&peer->ref, forb_peer_release);
120 }
121
122 void
123 forb_peer_delete_by_port(forb_t *forb, forb_port_t *port);
124
125 #endif