]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/object.h
Added possibility invoking remote methods on forb_orb interfaces
[frescor/forb.git] / src / object.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   object.h
49  * @author Michal Sojka <sojkam1@fel.cvut.cz>
50  * @date   Sun Oct 12 17:03:44 2008
51  * 
52  * @brief  Declarations for FORB's object references.
53  * 
54  * 
55  */
56
57 #ifndef FORB_OBJECT_H
58 #define FORB_OBJECT_H
59
60 #include <ul_gavlcust.h>
61 #include <forb/forb-internal.h>
62 #include <stdbool.h>
63 #include <forb/refcnt.h>
64 #include <forb/basic_types.h>
65 #include <forb/executor.h>
66
67 /**
68  * Object reference structure.
69  *
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()
74  * - call forb_init()
75  *
76  * When the created object is not needed, the application should call
77  * forb_object_release().
78  *
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,
81  * which is:
82  * 
83  * - if the method needs to store the object reference, it must call
84  *   forb_object_duplicate() and store the duplicate.
85  */
86 struct forb_object {
87         /** @name Fields valid for both local and remote object references */
88         /*@{*/
89         
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;
94
95         forb_orb orb;           /**< FORB reference */
96         forb_ref_t ref;         /**< Reference count */
97         /*@}*/
98
99         /** @name Fields used only in implementation (server) */
100         /*@{*/
101
102         /** Any data for implementation */
103         void *instance_data;
104
105         /** Description of interface implemented by this object (for
106          * servers); FIXME: What about clients? */
107         const forb_interface_t *interface;
108
109         /** Pointer to the object implementation methods or NULL in
110          * case of remote object. */
111         const void *implementation;
112
113         /** Executor object, which represents the thread the requests
114          * are executed in. */
115         forb_executor_t *executor;
116
117         gavl_node_t node;       /**< Node for forb->objects tree */
118         /*@}*/
119 };
120
121 /**
122  * Description of an IDL interface.
123  *
124  * Instances of this structure are generated by forb-idl (IDL compiler).
125  */
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 */
131 };
132
133 /**
134  * Returns forb_object::instance_data of an object.
135  * 
136  */
137 #define forb_object_instance_data(obj) ((obj)->instance_data)
138
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); }
143
144
145 /** 
146  * Returns pointer to forb_t from any object reference.
147  * 
148  * @param obj Object reference.
149  * 
150  * @return Pointer to forb_t which handles the @a obj.
151  */
152 static inline forb_t *
153 forb_object_to_forb(forb_object obj)
154 { return forb_data(obj->orb); }
155
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);
158
159 static inline int forb_objkey_cmp(forb_object_key *a, forb_object_key *b)
160 {
161         return (*a<*b) ? -1 :
162                 ((*a>*b) ? +1 :
163                  0);
164 }
165
166 forb_object
167 forb_object_new(forb_orb orb,
168                 forb_server_id *server_id,
169                 forb_object_key key);
170
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 */);
181
182
183 /** 
184  * Deletes object reference of an implementation from forb_t::objects.
185  * 
186  * @param forb 
187  * @param obj 
188  */
189 static inline void
190 forb_objects_delete(forb_t *forb, forb_object obj)
191 {
192         fosa_mutex_lock(&forb->objkey_mutex);
193         forb_objects_nolock_delete(forb, obj);
194         fosa_mutex_unlock(&forb->objkey_mutex);
195 }
196
197 /** 
198  * Finds implementation of an object with a given key.
199  * 
200  * @param forb 
201  * @param objkey 
202  * 
203  * @return Object references if it exists or NULL otherwise.
204  */
205 static inline forb_object
206 forb_objects_find(forb_t *forb, forb_object_key objkey)
207 {
208         forb_object ret;
209         fosa_mutex_lock(&forb->objkey_mutex);
210         ret = forb_objects_nolock_find(forb, &objkey);
211         fosa_mutex_unlock(&forb->objkey_mutex);
212         return ret;
213 }
214
215 /** 
216  * Determines whether the object is local (in-process) or remote.
217  * 
218  * @param obj 
219  * 
220  * @return true if local, false otherwise or in case of invalid object reference.
221  */
222 static inline bool
223 forb_object_is_local(forb_object obj)
224 {
225         return obj && obj->implementation;
226 }
227 /** 
228  * Determines whether the object is remote.
229  * 
230  * @param obj 
231  * 
232  * @return true if remote, false otherwise or in case of invalid object reference.
233  */
234 static inline bool
235 forb_object_is_remote(forb_object obj)
236 {
237         return obj && (obj->implementation == NULL);
238 }
239
240 CORBA_boolean
241 forb_object_serialize(CDR_Codec *codec, const forb_object *obj);
242 CORBA_boolean
243 forb_object_deserialize(CDR_Codec *codec, forb_object *obj, forb_orb orb);
244
245 #endif