]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - src/forb/src/tests/regobjref.c
814d1ae3bc088f56884063e1c5c059bc8889713f
[frescor/frsh-forb.git] / src / forb / src / tests / regobjref.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 /**
48  * @file   regobjref.c
49  * @author Michal Sojka <sojkam1@fel.cvut.cz>
50  * @date   Sat Oct 11 21:12:09 2008
51  * 
52  * @brief  Test for forb_register_reference() and forb_resolve_reference()
53  *
54  * This test is the same as hello_remote.c. The only difference is
55  * that in hello_remote.c, the object reference of the server is
56  * passed as a string to the client, whereas here we use
57  * forb_register_reference()/forb_resolve_reference() for this.
58  */
59
60
61 #include <hello.h>
62 #include "hello_impl.h"
63 #include <forb.h>
64 #include <error.h>
65 #include <fosa.h>
66 #include <forb/executor.h>
67
68 int argc_g;
69 char **argv_g;
70
71 void *server_thread(void *arg)
72 {
73         hello hobj = arg;
74
75         forb_execute_object(hobj);
76         return NULL;
77 }
78
79 void start_server()
80 {
81         forb_orb orb;
82         hello hobj;
83         int ret;
84
85         fosa_thread_id_t tid;
86         struct forb_init_attr attr = {
87                 .orb_id = "hello_remote_server"
88         };
89
90         orb = forb_init(&argc_g, &argv_g, &attr);
91         hobj = hello_impl_initialize(orb);
92         fosa_thread_create(&tid, NULL, server_thread, hobj);
93
94         ret = forb_register_reference(hobj, "hello");
95         if (ret != 0) {
96                 error(1, errno, "Cannot register reference to hello");
97         }
98 }
99
100
101
102 void client(void)
103 {
104         forb_orb orb;
105         hello hobj;
106         struct forb_env env;
107         struct forb_init_attr attr = {
108                 .orb_id = "hello_remote_client"
109         };
110                 
111         orb = forb_init(&argc_g, &argv_g, &attr);
112
113         hobj = forb_resolve_reference(orb, "hello");
114         if (!hobj) {
115                 error(1, errno, "Cannot resolve reference to hello server)");
116         }
117
118         hello_message(hobj, "Hello world!", &env);
119         if (forb_exception_occurred(&env)) {
120                 error(1, 0, "FORB exception %d", env.major);
121         }
122 }
123
124 int main(int argc, char *argv[])
125 {
126
127         argc_g = argc;
128         argv_g = argv;
129
130         start_server();
131
132         client();
133                 
134         return 0;       
135 }