]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/request.h
forb_request_send() moved to iop.c
[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 /**
71  * Helper structure for sending ORB requests.
72  *
73  * Its purpose is to match incomming reply messages to previously sent
74  * requests. It is allocated in stub's stack and during waiting for
75  * reply is stored in forb_t::requests tree.
76  * 
77  */
78 struct forb_request {
79         CORBA_unsigned_long request_id; /**< Numeric ID of this request. Used to match replies agains this request. */
80         FORB_CDR_Codec cdr_request;     /**< Buffer for the request serialization. */
81         FORB_CDR_Codec *cdr_reply;      /**< Buffer with received reply. */
82         gavl_node_t node;       /**< forb_t::requests node */
83         forb_object obj;        /**< Object being requested. */
84         struct forb_env *env;   /**< Where to store exception returned in reply */
85         forb_syncobj_t reply_ready; /**< Synchronization object for waiting for reply */
86         forb_syncobj_t *reply_processed; /**< Synchronization object for receiver thread to wait for stub. */
87 };
88
89 typedef struct forb_request forb_request_t;
90
91 /* Declaration of AVL tree for storing sent requests. */
92 GAVL_CUST_NODE_INT_DEC(forb_request_nolock /* cust_prefix */,
93                        forb_t /* cust_root_t */,
94                        forb_request_t /* cust_item_t */,
95                        CORBA_unsigned_long /* cust_key_t */,
96                        requests /* cust_root_node */,
97                        node /* cust_item_node */,
98                        request_id /* cust_item_key */,
99                        forb_request_cmp/* cust_cmp_fnc */);
100
101 static inline int
102 forb_request_insert(forb_t *forb, forb_request_t *req)
103 {
104         int ret;
105         fosa_mutex_lock(&forb->request_mutex);
106         ret = forb_request_nolock_insert(forb, req);
107         fosa_mutex_unlock(&forb->request_mutex);
108         return ret;
109 }
110
111 static inline void
112 forb_request_delete(forb_t *forb, forb_request_t *req)
113 {
114         fosa_mutex_lock(&forb->request_mutex);
115         forb_request_nolock_delete(forb, req);
116         fosa_mutex_unlock(&forb->request_mutex);
117 }
118
119 static inline forb_request_t *
120 forb_request_find(forb_t *forb, CORBA_unsigned_long *request_id)
121 {
122         forb_request_t *ret;
123         fosa_mutex_lock(&forb->request_mutex);
124         ret = forb_request_nolock_find(forb, request_id);
125         fosa_mutex_unlock(&forb->request_mutex);
126         return ret;
127 }
128
129 int
130 forb_request_init(forb_request_t *req, forb_object obj);
131 void
132 forb_request_destroy(forb_request_t *req);
133 void
134 forb_request_wait_for_reply(forb_request_t *req);
135 void
136 forb_request_signal_processed(forb_request_t *req);
137
138 #endif