]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Merge branch 'master' of rtime.felk.cvut.cz:/frescor/frsh-forb
authorPetr Benes <benesp16@fel.cvut.cz>
Tue, 8 Feb 2011 17:05:38 +0000 (18:05 +0100)
committerPetr Benes <benesp16@fel.cvut.cz>
Tue, 8 Feb 2011 17:05:38 +0000 (18:05 +0100)
forb-idl/forb-idl-c-stubs.c
src/executor.c
src/executor.h
src/tests/executor/Makefile [new file with mode: 0644]
src/tests/executor/Makefile.omk [new file with mode: 0644]
src/tests/executor/executor_test.c [new file with mode: 0644]
src/tests/executor/executor_test.idl [new file with mode: 0644]
src/tests/executor_id.c

index f553283be8ef856bdd7afc1692bad599bf49184d..6405e32aa4b544b0bc0606b12c4361ca0c25b1d2 100644 (file)
@@ -44,7 +44,8 @@ cs_output_stub (IDL_tree     tree,
 /*             fprintf(of, "    return "FORB_RETVAL_VAR_NAME";\n"); */
 /*     } */
         fprintf(of, "  if (ev) ev->major = FORB_EX_NONE;\n");
-        fprintf(of, "  if (forb_object_is_local(_obj)) {\n");
+        fprintf(of, "  if (forb_object_is_local(_obj) &&\n"
+                          "forb_get_current_executor() == forb_object_get_executor(_obj)) {\n");
         fprintf(of, "    if (!_obj->interface ||\n"
                     "        strncmp(_obj->interface->name, \"%s\", %zd) != 0) {\n"
                     "      ev->major = FORB_EX_BAD_OPERATION;\n"
index 7e75eb8b33d8a0fe8b76faccfd13109343a106c3..7af1923975a17d4e479a24ddbbb21c66ae4f1816 100644 (file)
@@ -196,16 +196,10 @@ error:
 /**
  * Determines the executor we are currently in.
  *
- * @param executor Current executor pointer.
- *
- * @return Zero in case of success.
+ * @return Pointer to the current executor or NULL if not called
+ * within executor.
  */
-int forb_get_current_executor(forb_executor_t **executor)
+forb_executor_t *forb_get_current_executor(void)
 {
-       int ret = 0;
-       *executor = (void *) pthread_getspecific(forb_executor_key);
-                                           
-       if (!(*executor))
-               ret = 1;
-       return ret;
+       return pthread_getspecific(forb_executor_key);
 }
index f3cad30910da70e071afff5bbab2f09e03020203..2c3cdc388cd3bf28befe8abe2bb218d14260f91d 100644 (file)
@@ -88,6 +88,6 @@ void forb_executor_unregister_object(forb_executor_t *executor, forb_object obj)
 int forb_executor_run(forb_executor_t *executor);
 
 int forb_execute_object(forb_object obj);
-int forb_get_current_executor(forb_executor_t **executor);
+forb_executor_t *forb_get_current_executor(void);
 
 #endif
diff --git a/src/tests/executor/Makefile b/src/tests/executor/Makefile
new file mode 100644 (file)
index 0000000..d538d21
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory: `pwd`\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/src/tests/executor/Makefile.omk b/src/tests/executor/Makefile.omk
new file mode 100644 (file)
index 0000000..8e52340
--- /dev/null
@@ -0,0 +1,8 @@
+wvtest_PROGRAMS = executor_test
+executor_test_SOURCES = executor_test.c
+executor_test_SERVER_IDL = executor_test.idl
+executor_test_CLIENT_IDL = executor_test.idl
+
+INCLUDES += -I.
+
+lib_LOADLIBES = forb ulut fosa rt wvtest
diff --git a/src/tests/executor/executor_test.c b/src/tests/executor/executor_test.c
new file mode 100644 (file)
index 0000000..77b80ee
--- /dev/null
@@ -0,0 +1,108 @@
+#include <forb.h>
+#include <executor_test.h>
+#define WVTEST_CONFIGURED
+#include <wvtest.h>
+#include <forb/executor.h>
+#include <forb/object.h>
+
+static CORBA_long add(executor_test obj, CORBA_long val, CORBA_Environment *ev)
+{
+       int to_add = (intptr_t)forb_object_instance_data(obj);
+       return val + to_add;
+}
+
+static CORBA_long add_indirect(executor_test obj, executor_test indirect_obj, CORBA_long val, CORBA_Environment *ev)
+{
+       return executor_test_add(indirect_obj, val, ev);
+}
+
+static const struct forb_executor_test_impl executor_test_impl = {
+       .add = add,
+       .add_indirect = add_indirect,
+};
+
+
+void *executor_thread(void *arg)
+{
+       forb_executor_t *executor = arg;
+       forb_executor_run(executor);
+       return NULL;
+}
+
+WVTEST_MAIN("remote (inter-server) invocation")
+{
+       forb_orb orb1, orb2;
+       fosa_thread_id_t tid;
+       executor_test testobj, remote_obj;
+       forb_executor_t executor;
+       char *str;
+       struct forb_env env;
+
+       /* Create the first FORB server */
+       WVPASS(orb1 = forb_init(NULL, NULL,
+                               &(struct forb_init_attr){.orb_id = "server1"}));
+
+       /* This object adds 1 to the argument of add() */
+       WVPASS(testobj = forb_executor_test_new(orb1, &executor_test_impl, (void*)1));
+       WVPASSEQ(forb_executor_init(&executor), 0);
+       WVPASSEQ(forb_executor_register_object(&executor, testobj), 0);
+
+       /* Execute executor in a separate thread */
+       fosa_thread_create(&tid, NULL, executor_thread, &executor);
+
+       /* Create the second FORB server in the same process */
+       WVPASS(orb2 = forb_init(NULL, NULL,
+                               &(struct forb_init_attr){.orb_id = "server2"}));
+
+       str = forb_object_to_string(testobj);
+       remote_obj = forb_string_to_object(orb2, str);
+
+       WVPASS(forb_object_is_local(testobj));
+       WVFAIL(forb_object_is_local(remote_obj));
+
+       /* Remote invocation of the object */
+       WVPASSEQ(executor_test_add(remote_obj, 1, &env), 2);
+       WVFAIL(forb_exception_occurred(&env));
+}
+
+WVTEST_MAIN("inter_thread_invocation")
+{
+       forb_orb orb;
+       fosa_thread_id_t tid1, tid2;
+       executor_test testobj1, testobj2;
+       forb_executor_t executor1, executor2;
+       struct forb_env env;
+
+       /* Create the first FORB server */
+       WVPASS(orb = forb_init(NULL, NULL,
+                              &(struct forb_init_attr){.orb_id = "server"}));
+
+       /* This object adds 1 to the argument of add() */
+       WVPASS(testobj1 = forb_executor_test_new(orb, &executor_test_impl, (void*)1));
+       WVPASSEQ(forb_executor_init(&executor1), 0);
+       WVPASSEQ(forb_executor_register_object(&executor1, testobj1), 0);
+
+       /* This object adds 2 to the argument of add() */
+       WVPASS(testobj2 = forb_executor_test_new(orb, &executor_test_impl, (void*)2));
+       WVPASSEQ(forb_executor_init(&executor2), 0);
+       WVPASSEQ(forb_executor_register_object(&executor2, testobj2), 0);
+
+       /* Execute executors in separate threads */
+       fosa_thread_create(&tid1, NULL, executor_thread, &executor1);
+       fosa_thread_create(&tid2, NULL, executor_thread, &executor2);
+
+       WVPASS(forb_object_is_local(testobj1));
+       WVPASS(forb_object_is_local(testobj2));
+
+       /* Inter-thread invocation: application->executor */
+       WVPASSEQ(executor_test_add(testobj1, 1, &env), 2);
+       WVFAIL(forb_exception_occurred(&env));
+
+       /* Inter-thread invocation: (application->)executor->executor */
+       WVPASSEQ(executor_test_add_indirect(testobj1, testobj2, 1, &env), 3);
+       WVFAIL(forb_exception_occurred(&env));
+
+       /* Direct invocation in the same executor: (application->)executor->executor */
+       WVPASSEQ(executor_test_add_indirect(testobj1, testobj1, 1, &env), 2);
+       WVFAIL(forb_exception_occurred(&env));
+}
diff --git a/src/tests/executor/executor_test.idl b/src/tests/executor/executor_test.idl
new file mode 100644 (file)
index 0000000..7aaf9d9
--- /dev/null
@@ -0,0 +1,6 @@
+interface executor_test {
+       // Adds some number the value @a val
+       long add(in long val);
+       // Adds some number the value @a val by calling @a add method of indirect_obj
+       long add_indirect(in executor_test indirect_obj, in long val);
+};
index 1aace5b1e0f11a39294d8e0b600b99b34754ea57..fadee53574ae0e404b88f3de481e2d383f6b14d9 100644 (file)
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
        }
 
        // ------------------------------------------------------
-       if (forb_get_current_executor(&executor)) {
+       if ((executor = forb_get_current_executor())) {
                printf("Test: Error while getting current executor\n");
                if (executor == NULL)
                printf("Test: Executor: NULL\n");