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 19:04:21 2008
52 * @brief Implementation of request handling functions
57 #include <forb/forb-internal.h>
59 #include <forb/iop-idl.h>
60 #include <forb/object.h>
66 extern UL_LOG_CUST(ulogd_forb_request);
68 static inline int forb_request_cmp(const CORBA_unsigned_long *a,
69 const CORBA_unsigned_long *b)
76 GAVL_CUST_NODE_INT_IMP(forb_request_nolock /* cust_prefix */,
77 forb_t /* cust_root_t */,
78 forb_request_t /* cust_item_t */,
79 CORBA_unsigned_long /* cust_key_t */,
80 requests /* cust_root_node */,
81 node /* cust_item_node */,
82 request_id /* cust_item_key */,
83 forb_request_cmp/* cust_cmp_fnc */);
86 * Initializes @a req structure for sending new request to object @a obj.
88 * @param req Request structure to initialize
89 * @param obj Destination object
91 * @return Zero on success, FOSA error code on error.
94 forb_request_init(forb_request_t *req, forb_object obj, char *iface, unsigned method_ind)
97 forb_t *forb = forb_object_to_forb(obj);
100 memset(req, 0, sizeof(*req));
102 req->interface = iface;
103 req->method_ind = method_ind;
105 fosa_mutex_lock(&forb->request_id_mutex);
106 req->request_id = forb->request_id++;
107 fosa_mutex_unlock(&forb->request_id_mutex);
109 FORB_CDR_codec_init_static(&req->cdr_request, obj->orb);
110 bret = FORB_CDR_buffer_init(&req->cdr_request, 4096-8, forb_iop_MESSAGE_HEADER_SIZE);
111 if (bret == CORBA_FALSE) {
115 ret = forb_syncobj_init(&req->reply_ready, 0);
120 forb_request_destroy(forb_request_t *req)
122 forb_t *forb = forb_object_to_forb(req->obj);
124 forb_request_delete(forb, req);
125 //FORB_CDR_codec_release_buffer(&req->cdr_request);
126 forb_syncobj_destroy(&req->reply_ready);
130 forb_request_signal_reply(forb_request_t *req)
132 forb_syncobj_signal(&req->reply_ready);
136 forb_request_wait_for_reply(forb_request_t *req)
138 fosa_abs_time_t timeout;
141 /* FIXME: What is the appropriate length for timeout? Maybe,
142 * we can specify timeout in forb_env, but since it is
143 * out-direction parameter, we cannot distinguish between
144 * initialized and uninitialized env.timeout. */
145 fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &timeout);
146 timeout = fosa_abs_time_incr(timeout,
147 fosa_msec_to_rel_time(10000));
149 ret = forb_syncobj_timedwait(&req->reply_ready, &timeout);
151 if (ret == ETIMEDOUT) {
152 req->env->major = FORB_EX_TIMEOUT;
154 req->env->major = FORB_EX_INTERNAL;
159 forb_request_signal_processed(forb_request_t *req)
161 /* Signal, that we are done */
162 forb_syncobj_signal(req->reply_processed);