]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/request.h
forb: End of header index removed from stub.
[frescor/forb.git] / src / request.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 #ifndef REQUEST_H
48 #define REQUEST_H
49
50 /**
51  * @file   request.h
52  * @author Michal Sojka <sojkam1@fel.cvut.cz>
53  * @date   Sun Oct 12 15:50:30 2008
54  * 
55  * @brief  Data type and functions for manipulation with requests.
56  * 
57  * 
58  */
59
60
61 #include <forb.h>
62 #include <forb/cdr.h>
63 #include <forb/basic_types.h>
64 #include <forb/syncobj.h>
65 #include <ul_gavlcust.h>
66 #include <forb/forb-internal.h>
67
68
69 /**
70  * Helper structure for sending ORB requests.
71  *
72  * Its purpose is to match incomming reply messages to previously sent
73  * requests. It is allocated in stub's stack and during waiting for
74  * reply is stored in forb_t::requests tree.
75  * 
76  */
77 struct forb_request {
78         CORBA_unsigned_long request_id; /**< Numeric ID of this request. Used to match replies agains this request. */
79         FORB_CDR_Codec cdr_request;     /**< Buffer for the request serialization. */
80         FORB_CDR_Codec *cdr_reply;      /**< Buffer with received reply. */
81         gavl_node_t node;       /**< forb_t::requests node */
82         forb_object obj;        /**< Object being requested. */
83         unsigned method_ind;    /**< Inddex of a method being requested. */
84         char *interface;        /**< Interface being requested. */
85         struct forb_env *env;   /**< Where to store exception returned in reply */
86         forb_syncobj_t reply_ready; /**< Synchronization object for waiting for reply */
87         forb_syncobj_t *reply_processed; /**< Synchronization object for receiver thread to wait for stub. */
88         unsigned end_of_header_index; /**< Index indicating the end of header of a codec buffer. */
89 };
90
91 typedef struct forb_request forb_request_t;
92
93 /* Declaration of AVL tree for storing sent requests. */
94 GAVL_CUST_NODE_INT_DEC(forb_request_nolock /* cust_prefix */,
95                        forb_t /* cust_root_t */,
96                        forb_request_t /* cust_item_t */,
97                        CORBA_unsigned_long /* cust_key_t */,
98                        requests /* cust_root_node */,
99                        node /* cust_item_node */,
100                        request_id /* cust_item_key */,
101                        forb_request_cmp/* cust_cmp_fnc */);
102
103 static inline int
104 forb_request_insert(forb_t *forb, forb_request_t *req)
105 {
106         int ret;
107         fosa_mutex_lock(&forb->request_mutex);
108         ret = forb_request_nolock_insert(forb, req);
109         fosa_mutex_unlock(&forb->request_mutex);
110         return ret;
111 }
112
113 static inline void
114 forb_request_delete(forb_t *forb, forb_request_t *req)
115 {
116         fosa_mutex_lock(&forb->request_mutex);
117         forb_request_nolock_delete(forb, req);
118         fosa_mutex_unlock(&forb->request_mutex);
119 }
120
121 static inline forb_request_t *
122 forb_request_find(forb_t *forb, CORBA_unsigned_long *request_id)
123 {
124         forb_request_t *ret;
125         fosa_mutex_lock(&forb->request_mutex);
126         ret = forb_request_nolock_find(forb, request_id);
127         fosa_mutex_unlock(&forb->request_mutex);
128         return ret;
129 }
130
131 int
132 forb_request_init(forb_request_t *req, forb_object obj, char *iface, unsigned method_ind);
133 void
134 forb_request_destroy(forb_request_t *req);
135 void
136 forb_request_wait_for_reply(forb_request_t *req);
137 void
138 forb_request_signal_processed(forb_request_t *req);
139
140 #endif