Author: abroekhuis
Date: Thu Sep 29 06:57:23 2011
New Revision: 1177180
URL: http://svn.apache.org/viewvc?rev=1177180&view=rev
Log:
Added examples
Added:
incubator/celix/trunk/examples/osgi-in-action/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/CMakeLists.txt
- copied, changed from r1173981,
incubator/celix/trunk/examples/CMakeLists.txt
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/README.TXT
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/CMakeLists.txt
- copied, changed from r1173981,
incubator/celix/trunk/examples/CMakeLists.txt
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/MANIFEST/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/MANIFEST/MANIFEST.MF
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/private/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/private/src/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/private/src/client.c
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/CMakeLists.txt
- copied, changed from r1173981,
incubator/celix/trunk/examples/CMakeLists.txt
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/MANIFEST/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/MANIFEST/MANIFEST.MF
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/include/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/include/greeting_impl.h
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/activator.c
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/greeting_impl.c
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/public/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/public/include/
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/public/include/greeting_service.h
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/CMakeLists.txt
- copied, changed from r1173981,
incubator/celix/trunk/examples/CMakeLists.txt
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/MANIFEST/
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/MANIFEST/MANIFEST.MF
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/README.TXT
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/private/
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/private/src/
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/private/src/activator.c
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/CMakeLists.txt
- copied, changed from r1173981,
incubator/celix/trunk/examples/CMakeLists.txt
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/MANIFEST/
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/MANIFEST/MANIFEST.MF
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/private/
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/private/src/
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c
Modified:
incubator/celix/trunk/examples/CMakeLists.txt
incubator/celix/trunk/examples/echo_service/client/echo_client_activator.c
incubator/celix/trunk/examples/echo_service/server/echo_server_activator.c
incubator/celix/trunk/target.cmake
Modified: incubator/celix/trunk/examples/CMakeLists.txt
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/CMakeLists.txt?rev=1177180&r1=1177179&r2=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/examples/CMakeLists.txt (original)
+++ incubator/celix/trunk/examples/CMakeLists.txt Thu Sep 29 06:57:23 2011
@@ -25,4 +25,10 @@ add_subdirectory(mongoose)
#add_subdirectory(echo_service/client)
#add_subdirectory(echo_service/server)
add_subdirectory(whiteboard)
-#add_subdirectory(echo_service)
\ No newline at end of file
+add_subdirectory(echo_service)
+
+add_subdirectory(osgi-in-action/chapter04-correct-lookup)
+add_subdirectory(osgi-in-action/chapter04-correct-listener)
+add_subdirectory(osgi-in-action/chapter01-greeting-example)
+
+deploy(chapter01-greeting-example BUNDLES shell shell_tui log_service
chapter01-greeting-example-client chapter01-greeting-example)
\ No newline at end of file
Modified:
incubator/celix/trunk/examples/echo_service/client/echo_client_activator.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/echo_service/client/echo_client_activator.c?rev=1177180&r1=1177179&r2=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/examples/echo_service/client/echo_client_activator.c
(original)
+++ incubator/celix/trunk/examples/echo_service/client/echo_client_activator.c
Thu Sep 29 06:57:23 2011
@@ -36,15 +36,17 @@ struct echoActivator {
SERVICE_TRACKER tracker;
};
-void * bundleActivator_create() {
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
struct echoActivator * act = malloc(sizeof(*act));
act->client = NULL;
act->tracker = NULL;
- return act;
+ *userData = act;
+
+ return CELIX_SUCCESS;
}
-void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
struct echoActivator * act = (struct echoActivator *) userData;
SERVICE_TRACKER tracker = tracker_create(context, ECHO_SERVICE_NAME,
NULL);
@@ -55,16 +57,22 @@ void bundleActivator_start(void * userDa
echoClient_start(act->client);
tracker_open(act->tracker);
+
+ return CELIX_SUCCESS;
}
-void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
struct echoActivator * act = (struct echoActivator *) userData;
tracker_close(act->tracker);
echoClient_stop(act->client);
+
+ return CELIX_SUCCESS;
}
-void bundleActivator_destroy(void * userData) {
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT
context) {
struct echoActivator * act = (struct echoActivator *) userData;
echoClient_destroy(act->client);
tracker_destroy(act->tracker);
+
+ return CELIX_SUCCESS;
}
Modified:
incubator/celix/trunk/examples/echo_service/server/echo_server_activator.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/echo_service/server/echo_server_activator.c?rev=1177180&r1=1177179&r2=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/examples/echo_service/server/echo_server_activator.c
(original)
+++ incubator/celix/trunk/examples/echo_service/server/echo_server_activator.c
Thu Sep 29 06:57:23 2011
@@ -34,13 +34,14 @@ struct echoActivator {
ECHO_SERVICE es;
};
-void * bundleActivator_create() {
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
struct echoActivator * act = malloc(sizeof(*act));
act->reg = NULL;
- return act;
+ *userData = act;
+ return CELIX_SUCCESS;
}
-void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
struct echoActivator * act = (struct echoActivator *) userData;
ECHO_SERVICE es = malloc(sizeof(*es));
@@ -51,16 +52,20 @@ void bundleActivator_start(void * userDa
act->es = es;
bundleContext_registerService(context, ECHO_SERVICE_NAME, es, NULL,
&act->reg);
+
+ return CELIX_SUCCESS;
}
-void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
struct echoActivator * act = (struct echoActivator *) userData;
serviceRegistration_unregister(act->reg);
act->reg = NULL;
+
+ return CELIX_SUCCESS;
}
-void bundleActivator_destroy(void * userData) {
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT
context) {
struct echoActivator * act = (struct echoActivator *) userData;
act->es->echo = NULL;
echoServer_destroy(act->es->server);
@@ -69,4 +74,6 @@ void bundleActivator_destroy(void * user
act->es = NULL;
act->reg = NULL;
free(act);
+
+ return CELIX_SUCCESS;
}
Copied:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/CMakeLists.txt
(from r1173981, incubator/celix/trunk/examples/CMakeLists.txt)
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/CMakeLists.txt?p2=incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/CMakeLists.txt&p1=incubator/celix/trunk/examples/CMakeLists.txt&r1=1173981&r2=1177180&rev=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/examples/CMakeLists.txt (original)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/CMakeLists.txt
Thu Sep 29 06:57:23 2011
@@ -15,14 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-add_subdirectory(hello_world)
-add_subdirectory(mongoose)
-
-#add_subdirectory(receiver)
-#add_subdirectory(receiver-2.0)
-#add_subdirectory(sender)
-
-#add_subdirectory(echo_service/client)
-#add_subdirectory(echo_service/server)
-add_subdirectory(whiteboard)
-#add_subdirectory(echo_service)
\ No newline at end of file
+add_subdirectory(greeting)
+add_subdirectory(client)
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/README.TXT
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/README.TXT?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/README.TXT
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/README.TXT
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,7 @@
+The example activates the bundles `chapter01-greeting-example` and
`chapter01-greeting-example-client`.
+The activator of the client bundle (client.c) tries to find the greeting
service, but may fail at start-up,
+because it is activated before the greeting service is installed.
+
+When the text 'Greetings' does not appear, stop and start the
`chapter01-greeting-example-client` bundle.
+Now the `chapter01-greeting-example` is already installed and the text
`Greetings` does appear after the
+restart of the client bundle.
Copied:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/CMakeLists.txt
(from r1173981, incubator/celix/trunk/examples/CMakeLists.txt)
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/CMakeLists.txt?p2=incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/CMakeLists.txt&p1=incubator/celix/trunk/examples/CMakeLists.txt&r1=1173981&r2=1177180&rev=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/examples/CMakeLists.txt (original)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/CMakeLists.txt
Thu Sep 29 06:57:23 2011
@@ -15,14 +15,11 @@
# specific language governing permissions and limitations
# under the License.
-add_subdirectory(hello_world)
-add_subdirectory(mongoose)
+add_library(chapter01-greeting-example-client SHARED private/src/client)
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("public/include")
+include_directories("private/include")
+include_directories("../greeting/public/include")
+target_link_libraries(chapter01-greeting-example-client framework)
-#add_subdirectory(receiver)
-#add_subdirectory(receiver-2.0)
-#add_subdirectory(sender)
-
-#add_subdirectory(echo_service/client)
-#add_subdirectory(echo_service/server)
-add_subdirectory(whiteboard)
-#add_subdirectory(echo_service)
\ No newline at end of file
+bundle(chapter01-greeting-example-client)
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/MANIFEST/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/MANIFEST/MANIFEST.MF?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/MANIFEST/MANIFEST.MF
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/MANIFEST/MANIFEST.MF
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,6 @@
+Bundle-SymbolicName: chapter01-greeting-example-client
+Bundle-Version: 1.0.0
+library: chapter01-greeting-example-client
+Import-Service: greeting-service
+
+
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/private/src/client.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/private/src/client.c?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/private/src/client.c
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/client/private/src/client.c
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,60 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <apr_general.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "greeting_service.h"
+
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT ctx) {
+ SERVICE_REFERENCE ref = NULL;
+ celix_status_t status = bundleContext_getServiceReference(ctx, (char *)
GREETING_SERVICE_NAME, &ref);
+ if (status == CELIX_SUCCESS) {
+ if (ref == NULL) {
+ printf("Greeting service reference not available\n");
+ } else {
+ GREETING_SERVICE greeting = NULL;
+ bundleContext_getService(ctx, ref, (void *) &greeting);
+ if (greeting == NULL){
+ printf("Greeting service not available\n");
+ } else {
+ bool result;
+
(*greeting->greeting_sayHello)(greeting->instance);
+ bundleContext_ungetService(ctx, ref, &result);
+ }
+ }
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT
context) {
+ return CELIX_SUCCESS;
+}
Copied:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/CMakeLists.txt
(from r1173981, incubator/celix/trunk/examples/CMakeLists.txt)
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/CMakeLists.txt?p2=incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/CMakeLists.txt&p1=incubator/celix/trunk/examples/CMakeLists.txt&r1=1173981&r2=1177180&rev=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/examples/CMakeLists.txt (original)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/CMakeLists.txt
Thu Sep 29 06:57:23 2011
@@ -15,14 +15,10 @@
# specific language governing permissions and limitations
# under the License.
-add_subdirectory(hello_world)
-add_subdirectory(mongoose)
+add_library(chapter01-greeting-example SHARED private/src/activator
private/src/greeting_impl)
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("public/include")
+include_directories("private/include")
+target_link_libraries(chapter01-greeting-example framework)
-#add_subdirectory(receiver)
-#add_subdirectory(receiver-2.0)
-#add_subdirectory(sender)
-
-#add_subdirectory(echo_service/client)
-#add_subdirectory(echo_service/server)
-add_subdirectory(whiteboard)
-#add_subdirectory(echo_service)
\ No newline at end of file
+bundle(chapter01-greeting-example)
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/MANIFEST/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/MANIFEST/MANIFEST.MF?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/MANIFEST/MANIFEST.MF
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/MANIFEST/MANIFEST.MF
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,6 @@
+Bundle-SymbolicName: chapter01-greeting-example
+Bundle-Version: 1.0.0
+library: chapter01-greeting-example
+Export-Service: greeting-service
+Import-Service: greeting-service
+
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/include/greeting_impl.h
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/include/greeting_impl.h?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/include/greeting_impl.h
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/include/greeting_impl.h
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,29 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+#ifndef GREETING_IMPL_H_
+#define GREETING_IMPL_H_
+
+struct greeting {
+ char *name;
+};
+
+extern void greeting_sayHello(struct greeting *instance);
+
+
+#endif /* GREETING_IMPL_H_ */
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/activator.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/activator.c?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/activator.c
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/activator.c
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,74 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <apr_general.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "greeting_impl.h"
+#include "greeting_service.h"
+#include "service_registration.h"
+
+struct greetingActivator {
+ SERVICE_REGISTRATION reg;
+ apr_pool_t *pool;
+};
+
+typedef struct greetingActivator *GREETING_ACTIVATOR;
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
+ apr_pool_t *pool;
+ GREETING_ACTIVATOR activator;
+ celix_status_t status = bundleContext_getMemoryPool(context, &pool);
+ if (status == CELIX_SUCCESS) {
+ *userData = apr_palloc(pool, sizeof(struct greetingActivator));
+ activator = *userData;
+ activator->reg = NULL;
+ activator->pool = pool;
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ struct greetingActivator * act = (struct greetingActivator *) userData;
+ celix_status_t status = CELIX_SUCCESS;
+ GREETING_SERVICE es = apr_palloc(act->pool, sizeof(*es));
+ es->instance = apr_palloc(act->pool, sizeof(*es->instance));
+ es->instance->name = GREETING_SERVICE_NAME;
+ es->greeting_sayHello = greeting_sayHello;
+
+ status = bundleContext_registerService(context, GREETING_SERVICE_NAME, es,
NULL, &act->reg);
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct greetingActivator * act = (struct greetingActivator *) userData;
+ serviceRegistration_unregister(act->reg);
+ act->reg = NULL;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT
context) {
+ struct greetingActivator * act = (struct greetingActivator *) userData;
+ act->reg = NULL;
+ return CELIX_SUCCESS;
+}
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/greeting_impl.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/greeting_impl.c?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/greeting_impl.c
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/greeting_impl.c
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,25 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+#include <stdio.h>
+#include "greeting_impl.h"
+
+void greeting_sayHello(struct greeting *instance){
+ printf("Greetings from %s\n", instance->name);
+}
+
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/public/include/greeting_service.h
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/public/include/greeting_service.h?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/public/include/greeting_service.h
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/public/include/greeting_service.h
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,32 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#ifndef GREETING_H_
+#define GREETING_H_
+
+#define GREETING_SERVICE_NAME "greeting-service"
+
+typedef struct greeting *GREETING;
+typedef struct greeting_service * GREETING_SERVICE;
+
+struct greeting_service {
+ GREETING instance;
+ void (*greeting_sayHello)(GREETING instance);
+};
+#endif /* GREETING_H_ */
Copied:
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/CMakeLists.txt
(from r1173981, incubator/celix/trunk/examples/CMakeLists.txt)
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/CMakeLists.txt?p2=incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/CMakeLists.txt&p1=incubator/celix/trunk/examples/CMakeLists.txt&r1=1173981&r2=1177180&rev=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/examples/CMakeLists.txt (original)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/CMakeLists.txt
Thu Sep 29 06:57:23 2011
@@ -15,14 +15,9 @@
# specific language governing permissions and limitations
# under the License.
-add_subdirectory(hello_world)
-add_subdirectory(mongoose)
+add_library(chapter04-correct-listener SHARED private/src/activator)
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
+target_link_libraries(chapter04-correct-listener framework)
-#add_subdirectory(receiver)
-#add_subdirectory(receiver-2.0)
-#add_subdirectory(sender)
-
-#add_subdirectory(echo_service/client)
-#add_subdirectory(echo_service/server)
-add_subdirectory(whiteboard)
-#add_subdirectory(echo_service)
\ No newline at end of file
+bundle(chapter04-correct-listener)
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/MANIFEST/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/MANIFEST/MANIFEST.MF?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/MANIFEST/MANIFEST.MF
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/MANIFEST/MANIFEST.MF
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,4 @@
+Bundle-SymbolicName: chapter04-correct-listener
+Bundle-Version: 1.0.0
+library: chapter04-correct-listener
+Import-Service: log_service
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/README.TXT
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/README.TXT?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/README.TXT
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/README.TXT
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,6 @@
+In the log server a listener registers when the log_service bundle is stopped
and
+started by means of the serviceChanged() routine. This routine maintains the
set of log
+services in the variable m_logServiceRefs. The function getLogService()
returns the
+current LOG_SERVICE, if it is active or NULL.
+Starting and stopping the log_service bundle shows that the logServiceTest
thread
+correctly recognizes the non-availability of the log_services, when stopped.
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/private/src/activator.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/private/src/activator.c?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/private/src/activator.c
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/private/src/activator.c
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,258 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <apr_general.h>
+#include <unistd.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "log_service.h"
+#include "array_list.h"
+
+typedef log_service_t LOG_SERVICE;
+
+struct clientActivator {
+ BUNDLE_CONTEXT m_context;
+ SERVICE_LISTENER m_Loglistener;
+ apr_pool_t *pool;
+ char * service;
+};
+typedef struct clientActivator * CLIENT_ACTIVATOR;
+
+ARRAY_LIST m_logServiceRefs = NULL;
+static pthread_t m_logTestThread;
+pthread_mutex_t logListenerMutex;
+
+//*******************************************************************************
+// function prototypes
+//*******************************************************************************
+void serviceChanged(SERVICE_LISTENER listener, SERVICE_EVENT event);
+void startTestThread(void *userData);
+void stopTestThread();
+void pauseTestThread();
+void alternativeLog(char *message, BUNDLE_CONTEXT m_context);
+void logListener(CLIENT_ACTIVATOR activator);
+//*******************************************************************************
+// global functions
+//*******************************************************************************
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
+ apr_pool_t *pool;
+ CLIENT_ACTIVATOR activator;
+ celix_status_t status = bundleContext_getMemoryPool(context, &pool);
+ if (status == CELIX_SUCCESS) {
+ *userData = apr_palloc(pool, sizeof(struct clientActivator));
+ activator = (CLIENT_ACTIVATOR) (*userData);
+ activator->service = "chapter04-correct-listener";
+ activator->m_Loglistener = NULL;
+ activator->pool = pool;
+ activator->m_context = context;
+ m_logServiceRefs = arrayList_create();
+ /* init the logServiceListener mutex */
+ pthread_mutex_init(&logListenerMutex, NULL);
+ } else {
+ status = CELIX_START_ERROR;
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ int i;
+ celix_status_t status = CELIX_SUCCESS;
+ CLIENT_ACTIVATOR clientActivator = (CLIENT_ACTIVATOR) userData;
+ ARRAY_LIST refs = NULL;
+ SERVICE_EVENT event = NULL;
+ struct clientActivator * activator = (struct clientActivator *)
userData;
+ logListener(activator);
+ // after adding the listener check for any existing services that need
pseudo events
+ // to register the existing services in the m_logServiceRefs list
+ status = bundleContext_getServiceReferences(context, NULL, NULL, &refs);
+ if (status == CELIX_SUCCESS){
+ if (refs != NULL) {
+ for (i = 0; (i < arrayList_size(refs)); i++){
+ event = apr_palloc(clientActivator->pool,
sizeof(struct serviceEvent));
+ event->reference =
arrayList_get(m_logServiceRefs, i);
+ event->type = REGISTERED;
+ serviceChanged(clientActivator->m_Loglistener,
event);
+ }
+ } else {
+ alternativeLog("no bundle references\n", context);
+ }
+ startTestThread(userData);
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+ struct clientActivator * act = (struct clientActivator *) userData;
+ stopTestThread();
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT
context) {
+ struct clientActivator * act = (struct clientActivator *) userData;
+ arrayList_destroy(m_logServiceRefs);
+ return CELIX_SUCCESS;
+}
+
+void serviceChanged(SERVICE_LISTENER listener, SERVICE_EVENT event) {
+ pthread_mutex_lock(&logListenerMutex);
+ switch (event->type) {
+ case REGISTERED:
+ printf("reg\n");
+ arrayList_add(m_logServiceRefs, event->reference);
+ break;
+ case MODIFIED:
+ printf("mod\n");
+ // only the service metadata has changed, so no need to do
anything here
+ break;
+ case UNREGISTERING:
+ printf("unr\n");
+ arrayList_remove(m_logServiceRefs,
+ arrayList_indexOf(m_logServiceRefs,
event->reference));
+ break;
+ default:
+ break;
+ }
+ pthread_mutex_unlock(&logListenerMutex);
+}
+
+// we must lock the listener before querying the internal state
+LOG_SERVICE getLogService(BUNDLE_CONTEXT context) {
+ LOG_SERVICE logService = NULL;
+ celix_status_t status = CELIX_SUCCESS;
+ pthread_mutex_lock(&logListenerMutex);
+ if (arrayList_size(m_logServiceRefs) > 0) {
+ // the last service reference should have the highest ranking
+ status = bundleContext_getService(context,
+ arrayList_get(m_logServiceRefs, 0), (void **)
&logService);
+ if (status != CELIX_SUCCESS){
+ printf("could not find service\n");
+ }
+ }
+ pthread_mutex_unlock(&logListenerMutex);
+ return logService;
+}
+
+// Test LogService by periodically sending a message
+void *logServiceTest (void *argument){
+ int tid;
+ LOG_SERVICE logService = NULL;
+ CLIENT_ACTIVATOR data = (CLIENT_ACTIVATOR) argument;
+ while (pthread_self() == m_logTestThread) {
+ SERVICE_REFERENCE logServiceRef = NULL;
+ // lookup the current "best" LogService each time, just before
we need to use it
+ //bundleContext_getServiceReference(m_context, (char *)
LOG_SERVICE_NAME, &logServiceRef);
+ logService = getLogService(data->m_context);
+ // if the dereferenced instance is null then we know the
service has been removed
+ if (logService != NULL) {
+ (*(logService->log))(logService->logger, LOG_INFO,
"ping");
+ } else {
+ alternativeLog("LogService has gone", data->m_context);
+ }
+ pauseTestThread();
+ }
+ return NULL;
+}
+
+
+
+//------------------------------------------------------------------------------------------
+// The rest of this is just support code, not meant to show any particular
best practices
+//------------------------------------------------------------------------------------------
+
+
+void startTestThread(void *userData) {
+ // start separate worker thread to run the actual tests, managed by the
bundle lifecycle
+ pthread_create(&m_logTestThread, NULL,logServiceTest, userData);
+}
+
+void stopTestThread() {
+ // thread should cooperatively shutdown on the next iteration, because
field is now null
+ pthread_t testThread = m_logTestThread;
+ pthread_cancel(testThread);
+ pthread_join(testThread, NULL);
+ m_logTestThread = 0;
+}
+
+void pauseTestThread() {
+ // sleep for a bit
+ sleep(5);
+}
+
+void alternativeLog(char *message, BUNDLE_CONTEXT m_context) {
+ // this provides similar style debug logging output for when the
LogService disappears
+ BUNDLE bundle = NULL;
+ celix_status_t status = CELIX_SUCCESS;
+ char tid[20], bid[20];
+ long bundleId;
+ if (m_context != NULL) {
+ celix_status_t rc = bundleContext_getBundle(m_context, &bundle);
+ if (status == CELIX_SUCCESS) {
+ celix_status_t rc = bundle_getBundleId(bundle,
&bundleId);
+ if (status == CELIX_SUCCESS) {
+ sprintf(tid, "thread=%s", "Thread");
+ sprintf(bid, "bundle=%ld", bundleId);
+ printf("<--> %s, %s : %s\n", tid, bid, message);
+ } else {
+ printf("%s:%s:%d:getBundleId failed: %s\n",
__FILE__, __FUNCTION__, __LINE__, message);
+ }
+ } else {
+ printf("%s:%s:%d:getBundle failed: %s\n", __FILE__,
__FUNCTION__, __LINE__, message);
+ }
+ } else {
+ printf("%s:%d:bundle context NULL: %s\n", __FILE__, __LINE__,
message);
+ }
+}
+
+void logListener(CLIENT_ACTIVATOR activator)
+{
+ celix_status_t status;
+ char filter[30];
+ int i;
+ SERVICE_REFERENCE r = NULL;
+ SERVICE_LISTENER m_Loglistener = NULL;
+ SERVICE_EVENT e = NULL;
+ ARRAY_LIST refs = NULL;
+ /* listener code */
+ m_Loglistener = (SERVICE_LISTENER) apr_palloc(activator->pool,
sizeof(*m_Loglistener));
+ activator->m_Loglistener = m_Loglistener;
+ m_Loglistener->handle = NULL;
+ m_Loglistener->serviceChanged = (void *) serviceChanged;
+ sprintf(filter, "(objectClass=%s)", LOG_SERVICE_NAME);
+ status = bundleContext_addServiceListener(activator->m_context,
m_Loglistener, filter);
+ if (status == CELIX_SUCCESS) {
+ // after adding the listener check for any existing services
that need pseudo events
+ bundleContext_getServiceReferences(activator->m_context, NULL,
filter, &refs);
+ if (refs != NULL) {
+ for (i = 0; i < arrayList_size(refs); i++) {
+ r = (SERVICE_REFERENCE) arrayList_get(refs, i);
+ e = apr_palloc(activator->pool, sizeof(struct
clientActivator));
+ e->type = REGISTERED;
+ e->reference = r;
+ (*m_Loglistener->serviceChanged)(m_Loglistener,
e);
+ }
+ }
+ } else {
+ printf("could not add service listener\n");
+ }
+}
Copied:
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/CMakeLists.txt
(from r1173981, incubator/celix/trunk/examples/CMakeLists.txt)
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/CMakeLists.txt?p2=incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/CMakeLists.txt&p1=incubator/celix/trunk/examples/CMakeLists.txt&r1=1173981&r2=1177180&rev=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/examples/CMakeLists.txt (original)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/CMakeLists.txt
Thu Sep 29 06:57:23 2011
@@ -15,14 +15,9 @@
# specific language governing permissions and limitations
# under the License.
-add_subdirectory(hello_world)
-add_subdirectory(mongoose)
+add_library(chapter04-correct-lookup SHARED private/src/activator)
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
+target_link_libraries(chapter04-correct-lookup framework pthread)
-#add_subdirectory(receiver)
-#add_subdirectory(receiver-2.0)
-#add_subdirectory(sender)
-
-#add_subdirectory(echo_service/client)
-#add_subdirectory(echo_service/server)
-add_subdirectory(whiteboard)
-#add_subdirectory(echo_service)
\ No newline at end of file
+bundle(chapter04-correct-lookup)
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/MANIFEST/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/MANIFEST/MANIFEST.MF?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/MANIFEST/MANIFEST.MF
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/MANIFEST/MANIFEST.MF
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,4 @@
+Bundle-SymbolicName: chapter04-correct-lookup
+Bundle-Version: 1.0.0
+library: chapter04-correct-lookup
+Import-Service: log_service
Added:
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c?rev=1177180&view=auto
==============================================================================
---
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c
(added)
+++
incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c
Thu Sep 29 06:57:23 2011
@@ -0,0 +1,158 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <apr_general.h>
+#include <unistd.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "pthread.h"
+#include "log_service.h"
+#include "bundle.h"
+
+typedef log_service_t LOG_SERVICE;
+
+struct threadData {
+ char * service;
+ int threadId;
+ BUNDLE_CONTEXT m_context;
+};
+
+typedef struct threadData *THREAD_DATA;
+
+static pthread_t m_logTestThread;
+
+
+//*******************************************************************************
+// function prototypes
+//*******************************************************************************
+void startTestThread(THREAD_DATA data);
+void stopTestThread();
+void pauseTestThread();
+void alternativeLog(char *message, THREAD_DATA data);
+//*******************************************************************************
+// global functions
+//*******************************************************************************
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData)
{
+ apr_pool_t *pool;
+ celix_status_t status = bundleContext_getMemoryPool(context, &pool);
+ if (status == CELIX_SUCCESS) {
+ *userData = apr_palloc(pool, sizeof(struct threadData));
+ ((THREAD_DATA)(*userData))->service =
"chapter04-correct-lookup";
+ ((THREAD_DATA)(*userData))->threadId = 0;
+ ((THREAD_DATA)(*userData))->m_context = context;
+ } else {
+ status = CELIX_START_ERROR;
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ ((THREAD_DATA) userData)->m_context = context;
+ startTestThread(((THREAD_DATA) userData));
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+ stopTestThread();
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT
context) {
+ return CELIX_SUCCESS;
+}
+
+//------------------------------------------------------------------------------------------
+// The rest of this is just support code, not meant to show any particular
best practices
+//------------------------------------------------------------------------------------------
+
+// Test LogService by periodically sending a message
+void *LogServiceTest (void *argument){
+ celix_status_t status = CELIX_SUCCESS;
+ THREAD_DATA data = (THREAD_DATA) argument;
+ BUNDLE_CONTEXT m_context = ((THREAD_DATA) argument)->m_context;
+ while (pthread_self() == m_logTestThread) {
+ SERVICE_REFERENCE logServiceRef = NULL;
+ // lookup the current "best" LogService each time, just before
we need to use it
+ status = bundleContext_getServiceReference(m_context, (char *)
LOG_SERVICE_NAME, &logServiceRef);
+ // if the service reference is null then we know there's no log
service available
+ if (status == CELIX_SUCCESS && logServiceRef != NULL) {
+ void *log = NULL;
+ LOG_SERVICE logService = NULL;
+ bundleContext_getService(m_context, logServiceRef,
&log);
+ logService = (LOG_SERVICE) log;
+ // if the dereferenced instance is null then we know
the service has been removed
+ if (logService != NULL) {
+ (*(logService->log))(logService->logger,
LOG_INFO, "ping");
+ } else {
+ alternativeLog("LogService has gone", data);
+ }
+ } else {
+ alternativeLog("LogService has gone", data);
+ }
+ pauseTestThread();
+ }
+ return NULL;
+}
+
+void startTestThread(THREAD_DATA data) {
+ // start separate worker thread to run the actual tests, managed by the
bundle lifecycle
+ data->threadId++;
+ int rc = pthread_create(&m_logTestThread, NULL, LogServiceTest, data);
+}
+
+void stopTestThread() {
+ // thread should cooperatively shutdown on the next iteration, because
field is now null
+ pthread_t testThread = m_logTestThread;
+ pthread_cancel(testThread);
+ pthread_join(testThread, NULL);
+ m_logTestThread = 0;
+}
+
+void pauseTestThread() {
+ // sleep for a bit
+ sleep(5);
+}
+
+void alternativeLog(char *message, THREAD_DATA data) {
+ // this provides similar style debug logging output for when the
LogService disappears
+ celix_status_t status = CELIX_SUCCESS;
+ BUNDLE bundle = NULL;
+ char tid[20], bid[20];
+ long bundleId;
+ if (data->m_context != NULL) {
+ status = bundleContext_getBundle(data->m_context, &bundle);
+ if (status == CELIX_SUCCESS) {
+ status = bundle_getBundleId(bundle, &bundleId);
+ if (status == CELIX_SUCCESS) {
+ sprintf(tid, "thread=%d", data->threadId);
+ sprintf(bid, "bundle=%ld", bundleId);
+ printf("<--> %s, %s : %s\n", tid, bid, message);
+ } else {
+ printf("%s:%s:%d:getBundleId failed: %s\n",
__FILE__, __FUNCTION__, __LINE__, message);
+ }
+ } else {
+ printf("%s:%s:%d:getBundle failed: %s\n", __FILE__,
__FUNCTION__, __LINE__, message);
+ }
+ } else {
+ printf("%s:%s:%d:bundle context NULL: %s\n", __FILE__,
__FUNCTION__, __LINE__, message);
+ }
+}
Modified: incubator/celix/trunk/target.cmake
URL:
http://svn.apache.org/viewvc/incubator/celix/trunk/target.cmake?rev=1177180&r1=1177179&r2=1177180&view=diff
==============================================================================
--- incubator/celix/trunk/target.cmake (original)
+++ incubator/celix/trunk/target.cmake Thu Sep 29 06:57:23 2011
@@ -21,4 +21,4 @@ deploy("hello_world" BUNDLES shell shell
#deploy("deployer" BUNDLES shell shell_tui deployer)
deploy("wb" BUNDLES tracker publisherA publisherB shell shell_tui log_service
log_writer)
deploy("wb_dp" BUNDLES tracker_depman publisherA publisherB shell shell_tui
log_service log_writer)
-#deploy("echo" BUNDLES echo_server echo_client shell shell_tui)
\ No newline at end of file
+deploy("echo" BUNDLES echo_server echo_client shell shell_tui)
\ No newline at end of file