Added: incubator/celix/trunk/remote_services/example_service/private/src/example_activator.c URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/example_service/private/src/example_activator.c?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/example_service/private/src/example_activator.c (added) +++ incubator/celix/trunk/remote_services/example_service/private/src/example_activator.c Mon Nov 7 18:06:09 2011 @@ -0,0 +1,87 @@ +/* + * example_activator.c + * + * Created on: Oct 5, 2011 + * Author: alexander + */ +#include <stdlib.h> + +#include "bundle_activator.h" +#include "bundle_context.h" +#include "service_registration.h" + +#include "example_impl.h" +#include "remote_constants.h" + +struct activator { + apr_pool_t *pool; + SERVICE_REGISTRATION exampleReg; +}; + +celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) { + celix_status_t status = CELIX_SUCCESS; + apr_pool_t *parentpool = NULL; + apr_pool_t *pool = NULL; + struct activator *activator; + + status = bundleContext_getMemoryPool(context, &parentpool); + if (status == CELIX_SUCCESS) { + if (apr_pool_create(&pool, parentpool) != APR_SUCCESS) { + status = CELIX_BUNDLE_EXCEPTION; + } else { + activator = apr_palloc(pool, sizeof(*activator)); + activator->pool = pool; + activator->exampleReg = NULL; + + *userData = activator; + } + } + + return status; +} + +celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) { + celix_status_t status = CELIX_SUCCESS; + struct activator *activator = userData; + example_t example = NULL; + example_service_t service = NULL; + PROPERTIES properties = NULL; + + status = example_create(activator->pool, &example); + if (status == CELIX_SUCCESS) { + service = apr_palloc(activator->pool, sizeof(*service)); + if (!service) { + status = CELIX_ENOMEM; + } else { + service->example = example; + service->add = example_add; + service->sub = example_sub; + service->sqrt = example_sqrt; + + properties = properties_create(); + properties_set(properties, (char *) SERVICE_EXPORTED_INTERFACES, (char *) EXAMPLE_SERVICE); + + bundleContext_registerService(context, (char *) EXAMPLE_SERVICE, service, properties, &activator->exampleReg); + } + } + + return status; +} + +celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) { + celix_status_t status = CELIX_SUCCESS; + struct activator *activator = userData; + + serviceRegistration_unregister(activator->exampleReg); + + return status; +} + +celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) { + celix_status_t status = CELIX_SUCCESS; + struct activator *activator = userData; + + + + return status; +}
Added: incubator/celix/trunk/remote_services/example_service/private/src/example_impl.c URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/example_service/private/src/example_impl.c?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/example_service/private/src/example_impl.c (added) +++ incubator/celix/trunk/remote_services/example_service/private/src/example_impl.c Mon Nov 7 18:06:09 2011 @@ -0,0 +1,51 @@ +/* + * example_impl.c + * + * Created on: Oct 5, 2011 + * Author: alexander + */ +#include <math.h> + +#include "headers.h" +#include "example_impl.h" + +celix_status_t example_create(apr_pool_t *pool, example_t *example) { + celix_status_t status = CELIX_SUCCESS; + + *example = apr_palloc(pool, sizeof(**example)); + if (!*example) { + status = CELIX_ENOMEM; + } else { + (*example)->pool = pool; + } + + return status; +} + +celix_status_t example_add(example_t example, double a, double b, double *result) { + celix_status_t status = CELIX_SUCCESS; + + *result = a + b; + + return status; +} + +celix_status_t example_sub(example_t example, double a, double b, double *result) { + celix_status_t status = CELIX_SUCCESS; + + *result = a - b; + + return status; +} + +celix_status_t example_sqrt(example_t example, double a, double *result) { + celix_status_t status = CELIX_SUCCESS; + + if (a > 0) { + *result = sqrt(a); + } else { + status = CELIX_ILLEGAL_ARGUMENT; + } + + return status; +} Added: incubator/celix/trunk/remote_services/example_service/public/include/example_service.h URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/example_service/public/include/example_service.h?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/example_service/public/include/example_service.h (added) +++ incubator/celix/trunk/remote_services/example_service/public/include/example_service.h Mon Nov 7 18:06:09 2011 @@ -0,0 +1,24 @@ +/* + * example_service.h + * + * Created on: Oct 5, 2011 + * Author: alexander + */ + +#ifndef EXAMPLE_SERVICE_H_ +#define EXAMPLE_SERVICE_H_ + +#define EXAMPLE_SERVICE "example" + +typedef struct example *example_t; + +typedef struct example_service *example_service_t; + +struct example_service { + example_t example; + celix_status_t (*add)(example_t example, double a, double b, double *result); + celix_status_t (*sub)(example_t example, double a, double b, double *result); + celix_status_t (*sqrt)(example_t example, double a, double *result); +}; + +#endif /* EXAMPLE_SERVICE_H_ */ Added: incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt (added) +++ incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt Mon Nov 7 18:06:09 2011 @@ -0,0 +1,34 @@ +# 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. + +link_directories("/opt/local/lib") +include_directories("/opt/local/include") +include_directories("${PROJECT_SOURCE_DIR}/utils/public/include") +include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include") +include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/include") +include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include") + +add_library(remote_service_admin SHARED + private/src/remote_service_admin_impl + private/src/export_registration_impl + private/src/import_registration_impl + private/src/remote_service_admin_activator + private/src/mongoose.c +) +target_link_libraries(remote_service_admin framework jansson.a) + +bundle(remote_service_admin) Added: incubator/celix/trunk/remote_services/remote_service_admin/MANIFEST/MANIFEST.MF URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/MANIFEST/MANIFEST.MF?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/remote_service_admin/MANIFEST/MANIFEST.MF (added) +++ incubator/celix/trunk/remote_services/remote_service_admin/MANIFEST/MANIFEST.MF Mon Nov 7 18:06:09 2011 @@ -0,0 +1,5 @@ +Bundle-SymbolicName: remote_service_admin +Bundle-Version: 1.0.0 +library: remote_service_admin +Export-Service: remote_service_admin +Import-Service: remote_service_admin Added: incubator/celix/trunk/remote_services/remote_service_admin/private/include/export_registration_impl.h URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/include/export_registration_impl.h?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/remote_service_admin/private/include/export_registration_impl.h (added) +++ incubator/celix/trunk/remote_services/remote_service_admin/private/include/export_registration_impl.h Mon Nov 7 18:06:09 2011 @@ -0,0 +1,41 @@ +/* + * export_registration.h + * + * Created on: Oct 6, 2011 + * Author: alexander + */ + +#ifndef EXPORT_REGISTRATION_IMPL_H_ +#define EXPORT_REGISTRATION_IMPL_H_ + +#include "headers.h" +#include "remote_service_admin.h" +#include "remote_endpoint.h" + +struct export_registration { + apr_pool_t *pool; + BUNDLE_CONTEXT context; + remote_service_admin_t rsa; + endpoint_description_t endpointDescription; + SERVICE_REFERENCE reference; + + SERVICE_TRACKER tracker; + SERVICE_TRACKER endpointTracker; + + remote_endpoint_service_t endpoint; + + export_reference_t exportReference; + + bool closed; +}; + +celix_status_t exportRegistration_create(apr_pool_t *pool, SERVICE_REFERENCE reference, endpoint_description_t endpoint, remote_service_admin_t rsa, BUNDLE_CONTEXT context, export_registration_t *registration); +celix_status_t exportRegistration_close(export_registration_t registration); +celix_status_t exportRegistration_getException(export_registration_t registration); +celix_status_t exportRegistration_getExportReference(export_registration_t registration, export_reference_t *reference); + +celix_status_t exportRegistration_setEndpointDescription(export_registration_t registration, endpoint_description_t endpointDescription); +celix_status_t exportRegistration_startTracking(export_registration_t registration); +celix_status_t exportRegistration_stopTracking(export_registration_t registration); + +#endif /* EXPORT_REGISTRATION_IMPL_H_ */ Added: incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h (added) +++ incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h Mon Nov 7 18:06:09 2011 @@ -0,0 +1,37 @@ +/* + * import_registration_impl.h + * + * Created on: Oct 14, 2011 + * Author: alexander + */ + +#ifndef IMPORT_REGISTRATION_IMPL_H_ +#define IMPORT_REGISTRATION_IMPL_H_ + +#include "headers.h" +#include "remote_service_admin.h" +#include "remote_proxy.h" + +struct import_registration { + apr_pool_t *pool; + BUNDLE_CONTEXT context; + remote_service_admin_t rsa; + endpoint_description_t endpointDescription; + + SERVICE_TRACKER proxyTracker; + + remote_proxy_service_t proxy; + + bool closed; +}; + +celix_status_t importRegistration_create(apr_pool_t *pool, endpoint_description_t endpoint, remote_service_admin_t rsa, BUNDLE_CONTEXT context, import_registration_t *registration); +celix_status_t importRegistration_close(import_registration_t registration); +celix_status_t importRegistration_getException(import_registration_t registration); +celix_status_t importRegistration_getImportReference(import_registration_t registration); + +celix_status_t importRegistration_setEndpointDescription(import_registration_t registration, endpoint_description_t endpointDescription); +celix_status_t importRegistration_startTracking(import_registration_t registration); +celix_status_t importRegistration_stopTracking(import_registration_t registration); + +#endif /* IMPORT_REGISTRATION_IMPL_H_ */ Added: incubator/celix/trunk/remote_services/remote_service_admin/private/include/mongoose.h URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/include/mongoose.h?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/remote_service_admin/private/include/mongoose.h (added) +++ incubator/celix/trunk/remote_services/remote_service_admin/private/include/mongoose.h Mon Nov 7 18:06:09 2011 @@ -0,0 +1,233 @@ +// Copyright (c) 2004-2011 Sergey Lyubka +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef MONGOOSE_HEADER_INCLUDED +#define MONGOOSE_HEADER_INCLUDED + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +struct mg_context; // Handle for the HTTP service itself +struct mg_connection; // Handle for the individual connection + + +// This structure contains information about the HTTP request. +struct mg_request_info { + void *user_data; // User-defined pointer passed to mg_start() + char *request_method; // "GET", "POST", etc + char *uri; // URL-decoded URI + char *http_version; // E.g. "1.0", "1.1" + char *query_string; // \0 - terminated + char *remote_user; // Authenticated user + char *log_message; // Mongoose error log message + long remote_ip; // Client's IP address + int remote_port; // Client's port + int status_code; // HTTP reply status code + int is_ssl; // 1 if SSL-ed, 0 if not + int num_headers; // Number of headers + struct mg_header { + char *name; // HTTP header name + char *value; // HTTP header value + } http_headers[64]; // Maximum 64 headers +}; + +// Various events on which user-defined function is called by Mongoose. +enum mg_event { + MG_NEW_REQUEST, // New HTTP request has arrived from the client + MG_HTTP_ERROR, // HTTP error must be returned to the client + MG_EVENT_LOG, // Mongoose logs an event, request_info.log_message + MG_INIT_SSL // Mongoose initializes SSL. Instead of mg_connection *, + // SSL context is passed to the callback function. +}; + +// Prototype for the user-defined function. Mongoose calls this function +// on every event mentioned above. +// +// Parameters: +// event: which event has been triggered. +// conn: opaque connection handler. Could be used to read, write data to the +// client, etc. See functions below that accept "mg_connection *". +// request_info: Information about HTTP request. +// +// Return: +// If handler returns non-NULL, that means that handler has processed the +// request by sending appropriate HTTP reply to the client. Mongoose treats +// the request as served. +// If callback returns NULL, that means that callback has not processed +// the request. Handler must not send any data to the client in this case. +// Mongoose proceeds with request handling as if nothing happened. +typedef void * (*mg_callback_t)(enum mg_event event, + struct mg_connection *conn, + const struct mg_request_info *request_info); + + +// Start web server. +// +// Parameters: +// callback: user defined event handling function or NULL. +// options: NULL terminated list of option_name, option_value pairs that +// specify Mongoose configuration parameters. +// +// Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom +// processing is required for these, signal handlers must be set up +// after calling mg_start(). +// +// +// Example: +// const char *options[] = { +// "document_root", "/var/www", +// "listening_ports", "80,443s", +// NULL +// }; +// struct mg_context *ctx = mg_start(&my_func, NULL, options); +// +// Please refer to http://code.google.com/p/mongoose/wiki/MongooseManual +// for the list of valid option and their possible values. +// +// Return: +// web server context, or NULL on error. +struct mg_context *mg_start(mg_callback_t callback, void *user_data, + const char **options); + + +// Stop the web server. +// +// Must be called last, when an application wants to stop the web server and +// release all associated resources. This function blocks until all Mongoose +// threads are stopped. Context pointer becomes invalid. +void mg_stop(struct mg_context *); + + +// Get the value of particular configuration parameter. +// The value returned is read-only. Mongoose does not allow changing +// configuration at run time. +// If given parameter name is not valid, NULL is returned. For valid +// names, return value is guaranteed to be non-NULL. If parameter is not +// set, zero-length string is returned. +const char *mg_get_option(const struct mg_context *ctx, const char *name); + + +// Return array of strings that represent valid configuration options. +// For each option, a short name, long name, and default value is returned. +// Array is NULL terminated. +const char **mg_get_valid_option_names(void); + + +// Add, edit or delete the entry in the passwords file. +// +// This function allows an application to manipulate .htpasswd files on the +// fly by adding, deleting and changing user records. This is one of the +// several ways of implementing authentication on the server side. For another, +// cookie-based way please refer to the examples/chat.c in the source tree. +// +// If password is not NULL, entry is added (or modified if already exists). +// If password is NULL, entry is deleted. +// +// Return: +// 1 on success, 0 on error. +int mg_modify_passwords_file(const char *passwords_file_name, + const char *domain, + const char *user, + const char *password); + +// Send data to the client. +int mg_write(struct mg_connection *, const void *buf, size_t len); + + +// Send data to the browser using printf() semantics. +// +// Works exactly like mg_write(), but allows to do message formatting. +// Note that mg_printf() uses internal buffer of size IO_BUF_SIZE +// (8 Kb by default) as temporary message storage for formatting. Do not +// print data that is bigger than that, otherwise it will be truncated. +int mg_printf(struct mg_connection *, const char *fmt, ...); + + +// Send contents of the entire file together with HTTP headers. +void mg_send_file(struct mg_connection *conn, const char *path); + + +// Read data from the remote end, return number of bytes read. +int mg_read(struct mg_connection *, void *buf, size_t len); + + +// Get the value of particular HTTP header. +// +// This is a helper function. It traverses request_info->http_headers array, +// and if the header is present in the array, returns its value. If it is +// not present, NULL is returned. +const char *mg_get_header(const struct mg_connection *, const char *name); + + +// Get a value of particular form variable. +// +// Parameters: +// data: pointer to form-uri-encoded buffer. This could be either POST data, +// or request_info.query_string. +// data_len: length of the encoded data. +// var_name: variable name to decode from the buffer +// buf: destination buffer for the decoded variable +// buf_len: length of the destination buffer +// +// Return: +// On success, length of the decoded variable. +// On error, -1 (variable not found, or destination buffer is too small). +// +// Destination buffer is guaranteed to be '\0' - terminated. In case of +// failure, dst[0] == '\0'. +int mg_get_var(const char *data, size_t data_len, + const char *var_name, char *buf, size_t buf_len); + +// Fetch value of certain cookie variable into the destination buffer. +// +// Destination buffer is guaranteed to be '\0' - terminated. In case of +// failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same +// parameter. This function returns only first occurrence. +// +// Return: +// On success, value length. +// On error, 0 (either "Cookie:" header is not present at all, or the +// requested parameter is not found, or destination buffer is too small +// to hold the value). +int mg_get_cookie(const struct mg_connection *, + const char *cookie_name, char *buf, size_t buf_len); + + +// Return Mongoose version. +const char *mg_version(void); + + +// MD5 hash given strings. +// Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of +// asciiz strings. When function returns, buf will contain human-readable +// MD5 hash. Example: +// char buf[33]; +// mg_md5(buf, "aa", "bb", NULL); +void mg_md5(char *buf, ...); + + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // MONGOOSE_HEADER_INCLUDED Added: incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h (added) +++ incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h Mon Nov 7 18:06:09 2011 @@ -0,0 +1,48 @@ +/* + * remote_service_admin_impl.h + * + * Created on: Sep 30, 2011 + * Author: alexander + */ + +#ifndef REMOTE_SERVICE_ADMIN_IMPL_H_ +#define REMOTE_SERVICE_ADMIN_IMPL_H_ + +#include "remote_service_admin.h" +#include "mongoose.h" + +struct export_reference { + endpoint_description_t endpoint; + SERVICE_REFERENCE reference; +}; + +struct import_reference { + +}; + +struct remote_service_admin { + apr_pool_t *pool; + BUNDLE_CONTEXT context; + + HASH_MAP exportedServices; + HASH_MAP importedServices; + + struct mg_context *ctx; +}; + +celix_status_t remoteServiceAdmin_create(apr_pool_t *pool, BUNDLE_CONTEXT context, remote_service_admin_t *admin); +celix_status_t remoteServiceAdmin_stop(remote_service_admin_t admin); + +celix_status_t remoteServiceAdmin_exportService(remote_service_admin_t admin, SERVICE_REFERENCE reference, PROPERTIES properties, ARRAY_LIST *registrations); +celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_t admin, ARRAY_LIST *services); +celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_t admin, ARRAY_LIST *services); +celix_status_t remoteServiceAdmin_importService(remote_service_admin_t admin, endpoint_description_t endpoint, import_registration_t *registration); + + +celix_status_t exportReference_getExportedEndpoint(export_reference_t reference, endpoint_description_t *endpoint); +celix_status_t exportReference_getExportedService(export_reference_t reference); + +celix_status_t importReference_getImportedEndpoint(import_reference_t reference); +celix_status_t importReference_getImportedService(import_reference_t reference); + +#endif /* REMOTE_SERVICE_ADMIN_IMPL_H_ */ Added: incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c (added) +++ incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c Mon Nov 7 18:06:09 2011 @@ -0,0 +1,181 @@ +/* + * export_registration_impl.c + * + * Created on: Oct 6, 2011 + * Author: alexander + */ +#include <stdlib.h> + +#include "headers.h" +#include "celix_errno.h" + +#include "export_registration_impl.h" +#include "remote_service_admin_impl.h" +#include "remote_endpoint.h" +#include "service_tracker.h" +#include "bundle_context.h" + +celix_status_t exportRegistration_endpointAdding(void * handle, SERVICE_REFERENCE reference, void **service); +celix_status_t exportRegistration_endpointAdded(void * handle, SERVICE_REFERENCE reference, void *service); +celix_status_t exportRegistration_endpointModified(void * handle, SERVICE_REFERENCE reference, void *service); +celix_status_t exportRegistration_endpointRemoved(void * handle, SERVICE_REFERENCE reference, void *service); + +celix_status_t exportRegistration_createEndpointTracker(export_registration_t registration, SERVICE_TRACKER *tracker); + +celix_status_t exportRegistration_create(apr_pool_t *pool, SERVICE_REFERENCE reference, endpoint_description_t endpoint, remote_service_admin_t rsa, BUNDLE_CONTEXT context, export_registration_t *registration) { + celix_status_t status = CELIX_SUCCESS; + apr_pool_t *mypool = NULL; + apr_pool_create(&mypool, pool); + + *registration = apr_palloc(mypool, sizeof(**registration)); + if (!*registration) { + status = CELIX_ENOMEM; + } else { + (*registration)->pool = mypool; + (*registration)->context = context; + (*registration)->closed = false; + (*registration)->endpointDescription = endpoint; + (*registration)->reference = reference; + (*registration)->rsa = rsa; + (*registration)->tracker = NULL; + (*registration)->endpoint = NULL; + (*registration)->endpointTracker = NULL; + (*registration)->exportReference = NULL; + } + + return status; +} + +celix_status_t exportRegistration_startTracking(export_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + + if (registration->endpointTracker == NULL) { + status = exportRegistration_createEndpointTracker(registration, ®istration->endpointTracker); + if (status == CELIX_SUCCESS) { + status = serviceTracker_open(registration->endpointTracker); + } + } + + return status; +} + +celix_status_t exportRegistration_stopTracking(export_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + + if (registration->endpointTracker != NULL) { + status = serviceTracker_close(registration->endpointTracker); + if (status != CELIX_SUCCESS) { + celix_log("EXPORT_REGISTRATION: Could not close endpoint tracker"); + } + } + if (registration->tracker != NULL) { + status = serviceTracker_close(registration->tracker); + if (status != CELIX_SUCCESS) { + celix_log("EXPORT_REGISTRATION: Could not close service tracker"); + } + } + + return status; +} + +celix_status_t exportRegistration_createEndpointTracker(export_registration_t registration, SERVICE_TRACKER *tracker) { + celix_status_t status = CELIX_SUCCESS; + + SERVICE_TRACKER_CUSTOMIZER custumizer = (SERVICE_TRACKER_CUSTOMIZER) apr_palloc(registration->pool, sizeof(*custumizer)); + if (!custumizer) { + status = CELIX_ENOMEM; + } else { + custumizer->handle = registration; + custumizer->addingService = exportRegistration_endpointAdding; + custumizer->addedService = exportRegistration_endpointAdded; + custumizer->modifiedService = exportRegistration_endpointModified; + custumizer->removedService = exportRegistration_endpointRemoved; + + status = serviceTracker_create(registration->context, REMOTE_ENDPOINT, custumizer, tracker); + } + + return status; +} + +celix_status_t exportRegistration_endpointAdding(void * handle, SERVICE_REFERENCE reference, void **service) { + celix_status_t status = CELIX_SUCCESS; + export_registration_t registration = handle; + + status = bundleContext_getService(registration->context, reference, service); + + return status; +} + +celix_status_t exportRegistration_endpointAdded(void * handle, SERVICE_REFERENCE reference, void *service) { + celix_status_t status = CELIX_SUCCESS; + export_registration_t registration = handle; + + remote_endpoint_service_t endpoint = service; + if (registration->endpoint == NULL) { + registration->endpoint = endpoint; + void *service = NULL; + status = bundleContext_getService(registration->context, registration->reference, &service); + if (status == CELIX_SUCCESS) { + endpoint->setService(endpoint->endpoint, service); + } + } + + return status; +} + +celix_status_t exportRegistration_endpointModified(void * handle, SERVICE_REFERENCE reference, void *service) { + celix_status_t status = CELIX_SUCCESS; + export_registration_t registration = handle; + + return status; +} + +celix_status_t exportRegistration_endpointRemoved(void * handle, SERVICE_REFERENCE reference, void *service) { + celix_status_t status = CELIX_SUCCESS; + export_registration_t registration = handle; + + remote_endpoint_service_t endpoint = service; + if (registration->endpoint != NULL) { + registration->endpoint = NULL; + endpoint->setService(endpoint->endpoint, NULL); + } + + return status; +} + +celix_status_t exportRegistration_close(export_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + + return status; +} + +celix_status_t exportRegistration_getException(export_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + return status; +} + +celix_status_t exportRegistration_getExportReference(export_registration_t registration, export_reference_t *reference) { + celix_status_t status = CELIX_SUCCESS; + + if (registration->exportReference == NULL) { + registration->exportReference = apr_palloc(registration->pool, sizeof(*registration->exportReference)); + if (registration->exportReference == NULL) { + status = CELIX_ENOMEM; + } else { + registration->exportReference->endpoint = registration->endpointDescription; + registration->exportReference->reference = registration->reference; + } + } + + *reference = registration->exportReference; + + return status; +} + +celix_status_t exportRegistration_setEndpointDescription(export_registration_t registration, endpoint_description_t endpointDescription) { + celix_status_t status = CELIX_SUCCESS; + + registration->endpointDescription = endpointDescription; + + return status; +} Added: incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c?rev=1198846&view=auto ============================================================================== --- incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c (added) +++ incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c Mon Nov 7 18:06:09 2011 @@ -0,0 +1,159 @@ +/* + * import_registration_impl.c + * + * Created on: Oct 14, 2011 + * Author: alexander + */ + +#include <stdlib.h> + +#include "headers.h" +#include "celix_errno.h" + +#include "import_registration_impl.h" +#include "remote_service_admin_impl.h" +#include "remote_proxy.h" +#include "service_tracker.h" +#include "bundle_context.h" + +celix_status_t importRegistration_proxyAdding(void * handle, SERVICE_REFERENCE reference, void **service); +celix_status_t importRegistration_proxyAdded(void * handle, SERVICE_REFERENCE reference, void *service); +celix_status_t importRegistration_proxyModified(void * handle, SERVICE_REFERENCE reference, void *service); +celix_status_t importRegistration_proxyRemoved(void * handle, SERVICE_REFERENCE reference, void *service); + +celix_status_t importRegistration_createProxyTracker(import_registration_t registration, SERVICE_TRACKER *tracker); + +celix_status_t importRegistration_create(apr_pool_t *pool, endpoint_description_t endpoint, remote_service_admin_t rsa, BUNDLE_CONTEXT context, import_registration_t *registration) { + celix_status_t status = CELIX_SUCCESS; + + *registration = apr_palloc(pool, sizeof(**registration)); + if (!*registration) { + status = CELIX_ENOMEM; + } else { + (*registration)->pool = pool; + (*registration)->context = context; + (*registration)->closed = false; + (*registration)->endpointDescription = endpoint; + (*registration)->rsa = rsa; + (*registration)->proxy = NULL; + (*registration)->proxyTracker = NULL; + } + + return status; +} + +celix_status_t importRegistration_startTracking(import_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + + if (registration->proxyTracker == NULL) { + importRegistration_createProxyTracker(registration, ®istration->proxyTracker); + serviceTracker_open(registration->proxyTracker); + } + + return status; +} + +celix_status_t importRegistration_stopTracking(import_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + + if (registration->proxyTracker != NULL) { + serviceTracker_close(registration->proxyTracker); + } + + return status; +} + +celix_status_t importRegistration_createProxyTracker(import_registration_t registration, SERVICE_TRACKER *tracker) { + celix_status_t status = CELIX_SUCCESS; + + SERVICE_TRACKER_CUSTOMIZER custumizer = (SERVICE_TRACKER_CUSTOMIZER) apr_palloc(registration->pool, sizeof(*custumizer)); + if (!custumizer) { + status = CELIX_ENOMEM; + } else { + custumizer->handle = registration; + custumizer->addingService = importRegistration_proxyAdding; + custumizer->addedService = importRegistration_proxyAdded; + custumizer->modifiedService = importRegistration_proxyModified; + custumizer->removedService = importRegistration_proxyRemoved; + + status = serviceTracker_create(registration->context, REMOTE_PROXY, custumizer, tracker); + } + + return status; +} + +celix_status_t importRegistration_proxyAdding(void * handle, SERVICE_REFERENCE reference, void **service) { + celix_status_t status = CELIX_SUCCESS; + import_registration_t registration = handle; + + bundleContext_getService(registration->context, reference, service); + + return status; +} + +celix_status_t importRegistration_proxyAdded(void * handle, SERVICE_REFERENCE reference, void *service) { + celix_status_t status = CELIX_SUCCESS; + import_registration_t registration = handle; + + remote_proxy_service_t proxy = service; + if (registration->proxy == NULL) { + registration->proxy = proxy; + if (registration->endpointDescription != NULL) { + proxy->setEndpointDescription(proxy->proxy, registration->endpointDescription); + } + } + + return status; +} + +celix_status_t importRegistration_proxyModified(void * handle, SERVICE_REFERENCE reference, void *service) { + celix_status_t status = CELIX_SUCCESS; + import_registration_t registration = handle; + + //remote_proxy_service_t endpoint = service; + //if (registration->endpoint != NULL) { + // registration->endpoint = endpoint; + // endpoint->setServiceReference(endpoint->endpoint, registration->reference); + //} + + return status; +} + +celix_status_t importRegistration_proxyRemoved(void * handle, SERVICE_REFERENCE reference, void *service) { + celix_status_t status = CELIX_SUCCESS; + import_registration_t registration = handle; + + remote_proxy_service_t proxy = service; + if (registration->proxy != NULL) { + registration->proxy = NULL; + proxy->setEndpointDescription(proxy->proxy, NULL); + } + + return status; +} + +celix_status_t importRegistration_close(import_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + return status; +} + +celix_status_t importRegistration_getException(import_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + return status; +} + +celix_status_t importRegistration_getImportReference(import_registration_t registration) { + celix_status_t status = CELIX_SUCCESS; + return status; +} + +celix_status_t importRegistration_setEndpointDescription(import_registration_t registration, endpoint_description_t endpointDescription) { + celix_status_t status = CELIX_SUCCESS; + + registration->endpointDescription = endpointDescription; + if (registration->proxy != NULL) { + registration->proxy->setEndpointDescription(registration->proxy->proxy, endpointDescription); + } + + return status; +}
