1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners: */
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 */
12 /* Thales Communication S.A. FRANCE */
13 /* Visual Tools S.A. SPAIN */
14 /* Rapita Systems Ltd UK */
17 /* See http://www.frescor.org for a link to partners' websites */
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. */
25 /* This file is part of FORB (Frescor Object Request Broker) */
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. */
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 /**************************************************************************/
49 * @author Michal Sojka <sojkam1@fel.cvut.cz>
50 * @date Sun Oct 12 17:31:51 2008
52 * @brief Declarations of peer data structure and functions.
60 #include <forb/forb-internal.h>
65 #include <fosa_mutexes_and_condvars.h>
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. */
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.
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
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;
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 */
107 forb_peer_release(forb_ref_t *ref);
109 static inline forb_peer_t *
110 forb_peer_get(forb_peer_t *peer)
112 forb_ref_get(&peer->ref);
117 forb_peer_put(forb_peer_t *peer)
119 forb_ref_put(&peer->ref, forb_peer_release);
123 forb_peer_delete_by_port(forb_t *forb, forb_port_t *port);