]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/exec_req.c
028c532411361085a73ba7124ff26836be430ba6
[frescor/forb.git] / src / exec_req.c
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  * @file   exec_req.c
48  * @author Michal Sojka <sojkam1@fel.cvut.cz>
49  * @date   Sun Oct 12 16:47:25 2008
50  * 
51  * @brief  Hanlding of requests in executors.
52  * 
53  */
54
55 #include "exec_req.h"
56 #include "executor.h"
57 #include <stdbool.h>
58 #include "forb-internal.h"
59 #include "object.h"
60 #include "iop-idl.h"
61 #include <ul_log.h>
62 #include "iop.h"
63
64 extern UL_LOG_CUST(ulogd_forb_exec_req);
65
66 void forb_exec_req_process(forb_exec_req_t *exec_req)
67 {
68         FORB_CDR_Codec reply_codec;
69         struct forb_env env;
70         const forb_skel_func *skeletons;
71         forb_t *forb = forb_object_to_forb(exec_req->obj);
72         CORBA_boolean ret;
73         
74         FORB_CDR_codec_init_static(&reply_codec, exec_req->obj->orb);   
75         ret = FORB_CDR_buffer_init(&reply_codec, 4096,
76                               forb_iop_MESSAGE_HEADER_SIZE +
77                               forb_iop_REPLY_HEADER_SIZE);
78         if (!ret) {
79                 /* Without codec, we cannot send any reply so return silently. */
80                 ul_logerr("No memory for reply buffer\n");
81                 return;
82         }
83
84         env.major = FORB_EX_NONE;
85
86         /* Allow the implementation to know about request details
87          * (e.g. source). */
88         exec_req->obj->exec_req = exec_req;
89
90         /* Invoke the skeleton */
91         skeletons = exec_req->obj->interface->skeletons;
92         skeletons[exec_req->method_index](&exec_req->codec,
93                                          &reply_codec,
94                                          exec_req->obj,
95                                          &env);
96
97         // The local invocation case
98         if ((exec_req->request_type = local)) {
99                 *(exec_req->input_request->cdr_reply) = reply_codec; //FIXME: better without copying?
100                 // notify that the reply is ready
101                 forb_syncobj_signal(&exec_req->input_request->reply_ready);
102         } else {
103                 forb_iop_send_reply(forb, &exec_req->source,
104                                 &reply_codec,
105                                 exec_req->request_id, &env);            
106         }
107         FORB_CDR_codec_release_buffer(&reply_codec);
108         forb_exec_req_destroy(exec_req);
109 }
110
111 void forb_exec_req_ins_tail(forb_executor_t *executor,
112                             forb_exec_req_t *exec_req)
113 {
114         bool was_empty;
115         fosa_mutex_lock(&executor->mutex);
116         was_empty = forb_exec_req_nolock_is_empty(executor);
117         forb_exec_req_nolock_ins_tail(executor, exec_req);
118         if (was_empty) {
119                 fosa_cond_signal(&executor->new_request_in_empty_list);
120         }
121         fosa_mutex_unlock(&executor->mutex);
122 }
123
124 void forb_exec_req_destroy(forb_exec_req_t *exec_req)
125 {
126         forb_object_release(exec_req->obj);
127         FORB_CDR_codec_release_buffer(&exec_req->codec);
128         forb_free(exec_req);
129 }