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>
66 #include <forb/exec_req.h>
69 * Object reference structure.
71 * The only ways for applications to create an object reference are:
72 * - call IDL generated forb_<interface>_new() function,
73 * - call forb_string_to_object().
74 * - call forb_get_orb_of()
77 * When the created object is not needed, the application should call
78 * forb_object_release().
80 * If the object reference is passed as a parameter of interface
81 * method, the same rules as in CORBA C mapping objref_ptr applies,
84 * - if the method needs to store the object reference, it must call
85 * forb_object_duplicate() and store the duplicate.
88 /** @name Fields valid for both local and remote object references */
91 /** Server implementing this object. @see forb::server_id */
92 forb_server_id server;
93 /** Object key of the object. @see forb::object_key */
94 forb_object_key objkey;
96 forb_orb orb; /**< FORB reference */
97 forb_ref_t ref; /**< Reference count */
100 /** @name Fields used only in implementation (server) */
103 /** Any data for implementation */
106 /** Description of interface implemented by this object (for
107 * servers); FIXME: What about clients? */
108 const forb_interface_t *interface;
110 /** Pointer to the object implementation methods or NULL in
111 * case of remote object. */
112 const void *implementation;
114 /** Executor object, which represents the thread the requests
115 * are executed in. */
116 forb_executor_t *executor;
119 * Pointer to the execute request in case of remote
122 * @warning If the object can be called both localy and
123 * remotely this field may contain wrong value as the local
124 * and remote requests can be executed in parallel, in
125 * different threads. This will be fixed after even local
126 * invocations will be executed through executors. */
127 forb_exec_req_t *exec_req;
129 gavl_node_t node; /**< Node for forb->objects tree */
134 * Description of an IDL interface.
136 * Instances of this structure are generated by forb-idl (IDL compiler).
138 struct forb_interface {
139 char *name; /**< Name of the interface */
140 unsigned num_methods; /**< Number of methods */
141 const forb_skel_func *skeletons; /**< Array of pointers to skeleton functions (one function for every method) */
142 uint32_t type_hash; /**< Not implemented */
146 * Returns forb_object::instance_data of an object.
149 #define forb_object_instance_data(obj) ((obj)->instance_data)
151 /** Return forb_t from an object reference. */
152 static inline forb_t *
153 forb_data(forb_orb orb)
154 { return forb_object_instance_data(orb); }
158 * Returns pointer to forb_t from any object reference.
160 * @param obj Object reference.
162 * @return Pointer to forb_t which handles the @a obj.
164 static inline forb_t *
165 forb_object_to_forb(forb_object obj)
166 { return forb_data(obj->orb); }
168 forb_object_key forb_object_to_key(forb_object obj);
169 forb_object forb_key_to_object(forb_t *forb, forb_object_key key);
171 static inline int forb_objkey_cmp(const forb_object_key *a, const forb_object_key *b)
173 return (*a<*b) ? -1 :
179 forb_object_new(forb_orb orb,
180 forb_server_id *server_id,
181 forb_object_key key);
183 /* Declaration of typesafe function for storing objects in GAVL tree
184 * ordered by object keys. */
185 GAVL_CUST_NODE_INT_DEC(forb_objects_nolock /* cust_prefix */,
186 forb_t /* cust_root_t */,
187 struct _forb_object /* cust_item_t */,
188 forb_object_key /* cust_key_t */,
189 objects /* cust_root_node */,
190 node /* cust_item_node */,
191 objkey /* cust_item_key */,
192 forb_objkey_cmp/* cust_cmp_fnc */);
196 * Deletes object reference of an implementation from forb_t::objects.
202 forb_objects_delete(forb_t *forb, forb_object obj)
204 fosa_mutex_lock(&forb->objkey_mutex);
205 forb_objects_nolock_delete(forb, obj);
206 fosa_mutex_unlock(&forb->objkey_mutex);
210 * Finds implementation of an object with a given key.
215 * @return Object references if it exists or NULL otherwise.
217 static inline forb_object
218 forb_objects_find(forb_t *forb, forb_object_key objkey)
221 fosa_mutex_lock(&forb->objkey_mutex);
222 ret = forb_objects_nolock_find(forb, &objkey);
223 ret = forb_object_duplicate(ret);
224 fosa_mutex_unlock(&forb->objkey_mutex);
229 * Determines whether the object is local (in-process) or remote.
233 * @return true if local, false otherwise or in case of invalid object reference.
236 forb_object_is_local(forb_object obj)
238 return obj && obj->implementation;
241 * Determines whether the object is remote.
245 * @return true if remote, false otherwise or in case of invalid object reference.
248 forb_object_is_remote(forb_object obj)
250 return obj && (obj->implementation == NULL);
254 forb_object_serialize(FORB_CDR_Codec *codec, const forb_object *obj);
256 forb_object_deserialize(FORB_CDR_Codec *codec, forb_object *obj);