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(CORBA_unsigned_long *a, CORBA_unsigned_long *b)
75 GAVL_CUST_NODE_INT_IMP(forb_request_nolock /* cust_prefix */,
76 forb_t /* cust_root_t */,
77 forb_request_t /* cust_item_t */,
78 CORBA_unsigned_long /* cust_key_t */,
79 requests /* cust_root_node */,
80 node /* cust_item_node */,
81 request_id /* cust_item_key */,
82 forb_request_cmp/* cust_cmp_fnc */);
85 * Initializes @a req structure for sending new request to object @a obj.
87 * @param req Request structure to initialize
88 * @param obj Destination object
90 * @return Zero on success, FOSA error code on error.
93 forb_request_init(forb_request_t *req, forb_object obj)
96 forb_t *forb = forb_object_to_forb(obj);
99 memset(req, 0, sizeof(*req));
102 fosa_mutex_lock(&forb->request_id_mutex);
103 req->request_id = forb->request_id++;
104 fosa_mutex_unlock(&forb->request_id_mutex);
106 CDR_codec_init_static(&req->cdr_request);
107 bret = CDR_buffer_init(&req->cdr_request, 256, forb_iop_MESSAGE_HEADER_SIZE);
108 if (bret == CORBA_FALSE) {
112 ret = forb_syncobj_init(&req->reply_ready, 0);
117 forb_request_destroy(forb_request_t *req)
119 CDR_codec_release_buffer(&req->cdr_request);
120 forb_syncobj_destroy(&req->reply_ready);
124 forb_request_signal_reply(forb_request_t *req)
126 forb_syncobj_signal(&req->reply_ready);
130 forb_request_wait_for_reply(forb_request_t *req)
132 forb_syncobj_wait(&req->reply_ready);
136 forb_request_signal_processed(forb_request_t *req)
138 /* Signal, that we are done */
139 forb_syncobj_signal(req->reply_processed);
143 * Sends REQUEST message to another FORB.
145 * The request @a req has to be prepared by
146 * forb_iop_prepare_request(). Then, this function adds a message
147 * header, connects to the destination FORB and sends the request.
149 * If no exception is reported, then the caller must wait for response
150 * by calling forb_wait_for_reply().
152 * @param req A request prepared by forb_iop_prepare_request()
153 * @param env Environment for returning exceptions
156 forb_request_send(forb_request_t *req, CORBA_Environment *env)
161 fosa_abs_time_t timeout;
162 forb_t *forb = forb_object_to_forb(req->obj);
165 env->major = FORB_EX_INTERNAL;
169 req->env = env; /* Remember, where to return exceptions */
171 ret = forb_iop_prepend_message_header(&req->cdr_request, forb_iop_REQUEST);
173 /* This should never happen */
174 env->major = FORB_EX_INTERNAL;
178 fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &timeout);
179 timeout = fosa_abs_time_incr(timeout,
180 fosa_msec_to_rel_time(1000));
181 peer = forb_get_next_hop(forb, &req->obj->server, &timeout);
184 ul_logerr("Cannot find peer to send request for server %s\n",
185 forb_server_id_to_string(str, &req->obj->server, sizeof(str)));
186 env->major = FORB_EX_TRANSIENT;
190 ret = forb_request_insert(forb, req);
192 ul_logerr("Insert request error %d\n", ret);
193 env->major = FORB_EX_INTERNAL;
197 size = forb_proto_send(peer, &req->cdr_request);
199 forb_request_delete(forb, req);
200 env->major = FORB_EX_COMM_FAILURE;