]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/exec_req.c
Struct request adjusted for inter-executor invocation.
[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 == FORB_EXEC_REQ_LOCAL) {
99                 forb_request_t *request = exec_req->input_request;
100                 forb_executor_t *executor = exec_req->obj->executor;
101
102                 request->cdr_reply = &reply_codec;
103                 /* Tell the stub where to signal that reply processing is
104                 * finished */
105                 request->reply_processed = &executor->reply_processed;          
106                 // notify that the reply is ready
107                 forb_syncobj_signal(&request->reply_ready);
108                 /* Wait for stub to process the results from the codec's buffer */              
109                 forb_syncobj_wait(&executor->reply_processed);          
110         } else {
111                 forb_iop_send_reply(forb, &exec_req->source,
112                                 &reply_codec,
113                                 exec_req->request_id, &env);            
114         }
115         FORB_CDR_codec_release_buffer(&reply_codec);                    
116         forb_exec_req_destroy(exec_req);
117 }
118
119 void forb_exec_req_ins_tail(forb_executor_t *executor,
120                             forb_exec_req_t *exec_req)
121 {
122         bool was_empty;
123         fosa_mutex_lock(&executor->mutex);
124         was_empty = forb_exec_req_nolock_is_empty(executor);
125         forb_exec_req_nolock_ins_tail(executor, exec_req);
126         if (was_empty) {
127                 fosa_cond_signal(&executor->new_request_in_empty_list);
128         }
129         fosa_mutex_unlock(&executor->mutex);
130 }
131
132 void forb_exec_req_destroy(forb_exec_req_t *exec_req)
133 {
134         forb_object_release(exec_req->obj);
135         FORB_CDR_codec_release_buffer(&exec_req->codec);
136         forb_free(exec_req);
137 }