From: Petr Benes Date: Tue, 8 Feb 2011 17:05:38 +0000 (+0100) Subject: Merge branch 'master' of rtime.felk.cvut.cz:/frescor/frsh-forb X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/forb.git/commitdiff_plain/8e57538505f1dc39ebbd9922c8cacd5b75fb61c3?hp=9887bca23aec6102d2259ced053549acf137eb9e Merge branch 'master' of rtime.felk.cvut.cz:/frescor/frsh-forb --- diff --git a/forb-idl/forb-idl-c-stubs.c b/forb-idl/forb-idl-c-stubs.c index f553283..6405e32 100644 --- a/forb-idl/forb-idl-c-stubs.c +++ b/forb-idl/forb-idl-c-stubs.c @@ -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" diff --git a/src/executor.c b/src/executor.c index 7e75eb8..7af1923 100644 --- a/src/executor.c +++ b/src/executor.c @@ -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); } diff --git a/src/executor.h b/src/executor.h index f3cad30..2c3cdc3 100644 --- a/src/executor.h +++ b/src/executor.h @@ -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 index 0000000..d538d21 --- /dev/null +++ b/src/tests/executor/Makefile @@ -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 index 0000000..8e52340 --- /dev/null +++ b/src/tests/executor/Makefile.omk @@ -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 index 0000000..77b80ee --- /dev/null +++ b/src/tests/executor/executor_test.c @@ -0,0 +1,108 @@ +#include +#include +#define WVTEST_CONFIGURED +#include +#include +#include + +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 index 0000000..7aaf9d9 --- /dev/null +++ b/src/tests/executor/executor_test.idl @@ -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); +}; diff --git a/src/tests/executor_id.c b/src/tests/executor_id.c index 1aace5b..fadee53 100644 --- a/src/tests/executor_id.c +++ b/src/tests/executor_id.c @@ -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");