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:03:44 2008
52 * @brief Declarations for FORB's object references.
60 #include <ul_gavlcust.h>
61 #include <forb/forb-internal.h>
63 #include <forb/refcnt.h>
64 #include <forb/basic_types.h>
65 #include <forb/executor.h>
68 * Object reference structure.
70 * The only ways for applications to create an object reference are:
71 * - call IDL generated forb_<interface>_new() function,
72 * - call forb_string_to_object().
73 * - call forb_get_orb_of()
76 * When the created object is not needed, the application should call
77 * forb_object_release().
79 * If the object reference is passed as a parameter of interface
80 * method, the same rules as in CORBA C mapping objref_ptr applies,
83 * - if the method needs to store the object reference, it must call
84 * forb_object_duplicate() and store the duplicate.
87 /** @name Fields valid for both local and remote object references */
90 /** Server implementing this object. @see forb::server_id */
91 forb_server_id server;
92 /** Object key of the object. @see forb::object_key */
93 forb_object_key objkey;
95 forb_orb orb; /**< FORB reference */
96 forb_ref_t ref; /**< Reference count */
99 /** @name Fields used only in implementation (server) */
102 /** Any data for implementation */
105 /** Description of interface implemented by this object (for
106 * servers); FIXME: What about clients? */
107 const forb_interface_t *interface;
109 /** Pointer to the object implementation methods or NULL in
110 * case of remote object. */
111 const void *implementation;
113 /** Executor object, which represents the thread the requests
114 * are executed in. */
115 forb_executor_t *executor;
117 gavl_node_t node; /**< Node for forb->objects tree */
122 * Description of an IDL interface.
124 * Instances of this structure are generated by forb-idl (IDL compiler).
126 struct forb_interface {
127 char *name; /**< Name of the interface */
128 unsigned num_methods; /**< Number of methods */
129 const forb_skel_func *skeletons; /**< Array of pointers to skeleton functions (one function for every method) */
130 uint32_t type_hash; /**< Not implemented */
134 * Returns forb_object::instance_data of an object.
137 #define forb_object_instance_data(obj) ((obj)->instance_data)
139 /** Return forb_t from an object reference. */
140 static inline forb_t *
141 forb_data(forb_orb orb)
142 { return forb_object_instance_data(orb); }
146 * Returns pointer to forb_t from any object reference.
148 * @param obj Object reference.
150 * @return Pointer to forb_t which handles the @a obj.
152 static inline forb_t *
153 forb_object_to_forb(forb_object obj)
154 { return forb_data(obj->orb); }
156 forb_object_key forb_object_to_key(forb_object obj);
157 forb_object forb_key_to_object(forb_t *forb, forb_object_key key);
159 static inline int forb_objkey_cmp(forb_object_key *a, forb_object_key *b)
161 return (*a<*b) ? -1 :
167 forb_object_new(forb_orb orb,
168 forb_server_id *server_id,
169 forb_object_key key);
171 /* Declaration of typesafe function for storing objects in GAVL tree
172 * ordered by object keys. */
173 GAVL_CUST_NODE_INT_DEC(forb_objects_nolock /* cust_prefix */,
174 forb_t /* cust_root_t */,
175 struct forb_object /* cust_item_t */,
176 forb_object_key /* cust_key_t */,
177 objects /* cust_root_node */,
178 node /* cust_item_node */,
179 objkey /* cust_item_key */,
180 forb_objkey_cmp/* cust_cmp_fnc */);
184 * Deletes object reference of an implementation from forb_t::objects.
190 forb_objects_delete(forb_t *forb, forb_object obj)
192 fosa_mutex_lock(&forb->objkey_mutex);
193 forb_objects_nolock_delete(forb, obj);
194 fosa_mutex_unlock(&forb->objkey_mutex);
198 * Finds implementation of an object with a given key.
203 * @return Object references if it exists or NULL otherwise.
205 static inline forb_object
206 forb_objects_find(forb_t *forb, forb_object_key objkey)
209 fosa_mutex_lock(&forb->objkey_mutex);
210 ret = forb_objects_nolock_find(forb, &objkey);
211 fosa_mutex_unlock(&forb->objkey_mutex);
216 * Determines whether the object is local (in-process) or remote.
220 * @return true if local, false otherwise or in case of invalid object reference.
223 forb_object_is_local(forb_object obj)
225 return obj && obj->implementation;
228 * Determines whether the object is remote.
232 * @return true if remote, false otherwise or in case of invalid object reference.
235 forb_object_is_remote(forb_object obj)
237 return obj && (obj->implementation == NULL);
241 forb_object_serialize(CDR_Codec *codec, const forb_object *obj);
243 forb_object_deserialize(CDR_Codec *codec, forb_object *obj, forb_orb orb);