You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2018/05/27 18:36:56 UTC
[13/51] [partial] celix git commit: CELIX-424: Cleans up the
directory structure. Moves all libraries to the libs subdir and all bundles
to the bundles subdir
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/bundle_context.h
----------------------------------------------------------------------
diff --git a/framework/include/bundle_context.h b/framework/include/bundle_context.h
deleted file mode 100644
index cf42314..0000000
--- a/framework/include/bundle_context.h
+++ /dev/null
@@ -1,171 +0,0 @@
-/**
- *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 BUNDLE_CONTEXT_H_
-#define BUNDLE_CONTEXT_H_
-
-/**
- * A bundle's execution context within the Framework. The context is used to
- * grant access to other methods so that this bundle can interact with the
- * Framework.
- */
-
-#include "celix_types.h"
-
-#include "service_factory.h"
-#include "celix_service_factory.h"
-#include "service_listener.h"
-#include "bundle_listener.h"
-#include "framework_listener.h"
-#include "properties.h"
-#include "array_list.h"
-
-#include "dm_dependency_manager.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-celix_status_t
-bundleContext_create(framework_pt framework, framework_logger_pt, bundle_pt bundle, bundle_context_pt *bundle_context);
-
-celix_status_t bundleContext_destroy(bundle_context_pt context);
-
-FRAMEWORK_EXPORT celix_status_t bundleContext_getBundle(bundle_context_pt context, bundle_pt *bundle);
-
-FRAMEWORK_EXPORT celix_status_t bundleContext_getFramework(bundle_context_pt context, framework_pt *framework);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_installBundle(bundle_context_pt context, const char *location, bundle_pt *bundle);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_installBundle2(bundle_context_pt context, const char *location, const char *inputFile, bundle_pt *bundle);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_registerService(bundle_context_pt context, const char *serviceName, const void *svcObj,
- properties_pt properties, service_registration_pt *service_registration);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_registerServiceFactory(bundle_context_pt context, const char *serviceName, service_factory_pt factory,
- properties_pt properties, service_registration_pt *service_registration);
-
-/**
- * Get a service reference for the bundle context. When the service reference is no longer needed use bundleContext_ungetServiceReference.
- * ServiceReference are coupled to a bundle context. Do not share service reference between bundles. Exchange the service.id instead.
- *
- * @param context The bundle context
- * @param serviceName The name of the service (objectClass) to get
- * @param service_reference _output_ The found service reference, or NULL when no service is found.
- * @return CELIX_SUCCESS on success
- */
-FRAMEWORK_EXPORT celix_status_t bundleContext_getServiceReference(bundle_context_pt context, const char *serviceName,
- service_reference_pt *service_reference);
-
-/** Same as bundleContext_getServiceReference, but than for a optional serviceName combined with a optional filter.
- * The resulting array_list should be destroyed by the caller. For all service references return a unget should be called.
- *
- * @param context the bundle context
- * @param serviceName the serviceName, can be NULL
- * @param filter the filter, can be NULL. If present will be combined (and) with the serviceName
- * @param service_references _output_ a array list, can be size 0.
- * @return CELIX_SUCCESS on success
- */
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_getServiceReferences(bundle_context_pt context, const char *serviceName, const char *filter,
- array_list_pt *service_references);
-
-/**
- * Retains (increases the ref count) the provided service reference. Can be used to retain a service reference.
- * Note that this is a deviation from the OSGi spec, due to the fact that C has no garbage collect.
- *
- * @param context the bundle context
- * @param reference the service reference to retain
- * @return CELIX_SUCCES on success
- */
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_retainServiceReference(bundle_context_pt context, service_reference_pt reference);
-
-/**
- * Ungets the service references. If the ref counter of the service refernce goes to 0, the reference will be destroyed.
- * This is coupled with the bundleContext_getServiceReference(s) and bundleContext_retainServiceReferenc.
- * Note: That this is a deviation from the OSGi standard, due to the fact that C has no garbage collect.
- *
- * @param context The bundle context.
- * @param reference the service reference to unget
- * @return CELIX_SUCCESS on success.
- */
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_ungetServiceReference(bundle_context_pt context, service_reference_pt reference);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_getService(bundle_context_pt context, service_reference_pt reference, void **service_instance);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_ungetService(bundle_context_pt context, service_reference_pt reference, bool *result);
-
-FRAMEWORK_EXPORT celix_status_t bundleContext_getBundles(bundle_context_pt context, array_list_pt *bundles);
-
-FRAMEWORK_EXPORT celix_status_t bundleContext_getBundleById(bundle_context_pt context, long id, bundle_pt *bundle);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_addServiceListener(bundle_context_pt context, service_listener_pt listener, const char *filter);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_removeServiceListener(bundle_context_pt context, service_listener_pt listener);
-
-FRAMEWORK_EXPORT celix_status_t bundleContext_addBundleListener(bundle_context_pt context, bundle_listener_pt listener);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_removeBundleListener(bundle_context_pt context, bundle_listener_pt listener);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_addFrameworkListener(bundle_context_pt context, framework_listener_pt listener);
-
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_removeFrameworkListener(bundle_context_pt context, framework_listener_pt listener);
-
-/**
- * Gets the config property - or environment variable if the config property does not exist - for the provided name.
- *
- * @param context The bundle context.
- * @param name The name of the config property / environment variable to get.
- * @param value A ptr to the output value. This will be set when a value is found or else will be set to NULL.
- * @return 0 if successful.
- */
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_getProperty(bundle_context_pt context, const char *name, const char **value);
-
-/**
- * Gets the config property - or environment variable if the config property does not exist - for the provided name.
- *
- * @param context The bundle context.
- * @param name The name of the config property / environment variable to get.
- * @param defaultValue The default value to return if no value is found.
- * @param value A ptr to the output value. This will be set when a value is found or else will be set to NULL.
- * @return 0 if successful.
- */
-FRAMEWORK_EXPORT celix_status_t
-bundleContext_getPropertyWithDefault(bundle_context_pt context, const char *name, const char *defaultValue, const char **value);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* BUNDLE_CONTEXT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/bundle_event.h
----------------------------------------------------------------------
diff --git a/framework/include/bundle_event.h b/framework/include/bundle_event.h
deleted file mode 100644
index 5a1a8bc..0000000
--- a/framework/include/bundle_event.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *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.
- */
-/*
- * bundle_event.h
- *
- * \date Jun 28, 2012
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef BUNDLE_EVENT_H_
-#define BUNDLE_EVENT_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum bundle_event_type {
- OSGI_FRAMEWORK_BUNDLE_EVENT_INSTALLED = 0x00000001,
- OSGI_FRAMEWORK_BUNDLE_EVENT_STARTED = 0x00000002,
- OSGI_FRAMEWORK_BUNDLE_EVENT_STOPPED = 0x00000004,
- OSGI_FRAMEWORK_BUNDLE_EVENT_UPDATED = 0x00000008,
- OSGI_FRAMEWORK_BUNDLE_EVENT_UNINSTALLED = 0x00000010,
- OSGI_FRAMEWORK_BUNDLE_EVENT_RESOLVED = 0x00000020,
- OSGI_FRAMEWORK_BUNDLE_EVENT_UNRESOLVED = 0x00000040,
- OSGI_FRAMEWORK_BUNDLE_EVENT_STARTING = 0x00000080,
- OSGI_FRAMEWORK_BUNDLE_EVENT_STOPPING = 0x00000100,
- OSGI_FRAMEWORK_BUNDLE_EVENT_LAZY_ACTIVATION = 0x00000200,
-};
-
-typedef enum bundle_event_type bundle_event_type_e;
-typedef struct bundle_event *bundle_event_pt;
-typedef struct bundle_event bundle_event_t;
-typedef struct bundle_event celix_bundle_event_t;
-
-#include "service_reference.h"
-#include "bundle.h"
-
-struct bundle_event {
- long bundleId;
- char *bundleSymbolicName;
- bundle_event_type_e type;
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* BUNDLE_EVENT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/bundle_listener.h
----------------------------------------------------------------------
diff --git a/framework/include/bundle_listener.h b/framework/include/bundle_listener.h
deleted file mode 100644
index 739bcaa..0000000
--- a/framework/include/bundle_listener.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *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 BUNDLE_LISTENER_H_
-#define BUNDLE_LISTENER_H_
-
-typedef struct bundle_listener *bundle_listener_pt;
-typedef struct bundle_listener bundle_listener_t;
-
-#include "celix_errno.h"
-#include "bundle_event.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-struct bundle_listener {
- void *handle;
-
- celix_status_t (*bundleChanged)(void *listener, bundle_event_pt event);
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* service_listener_t_H_ */
-
-/**
- * @}
- */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/bundle_revision.h
----------------------------------------------------------------------
diff --git a/framework/include/bundle_revision.h b/framework/include/bundle_revision.h
deleted file mode 100644
index 7c67a94..0000000
--- a/framework/include/bundle_revision.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- *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.
- */
-/**
- *
- * @defgroup BundleRevision Bundle Revision
- * @ingroup framework
- * @{
- *
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \date April 12, 2011
- * \copyright Apache License, Version 2.0
- */
-#ifndef BUNDLE_REVISION_H_
-#define BUNDLE_REVISION_H_
-
-#include <stdio.h>
-
-#include "celix_types.h"
-
-#include "celix_errno.h"
-#include "manifest.h"
-#include "celix_log.h"
-#include "array_list.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- *
- * A bundle revision represents the content of a bundle. A revision is associated with a bundle archive.
- * An archive can have multiple revisions, each update of a bundle results in a new one.
- *
- * In a revision the content of a bundle (ZIP file) is extracted to a specified location inside the archive.
- */
-
-/**
- * Creates a new revision for the given inputFile or location.
- * The location parameter is used to identify the bundle, in case of an update or download, the inputFile
- * parameter can be used to point to the actual data. In the OSGi specification this is the inputstream.
- *
- * @param pool The pool on which this revision has to be allocated.
- * @param root The root for this revision in which the bundle is extracted and state is stored.
- * @param location The location associated with the revision
- * @param revisionNr The number of the revision
- * @param inputFile The (optional) location of the file to use as input for this revision
- * @param[out] bundle_revision The output parameter for the created revision.
- *
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>bundle_revision</code> failed.
- */
-celix_status_t bundleRevision_create(const char *root, const char *location, long revisionNr, const char *inputFile,
- bundle_revision_pt *bundle_revision);
-
-celix_status_t bundleRevision_destroy(bundle_revision_pt revision);
-
-/**
- * Retrieves the revision number of the given revision.
- *
- * @param revision The revision to get the number for.
- * @param[out] revisionNr The revision number.
- *
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT If <code>revision</code> is illegal.
- */
-celix_status_t bundleRevision_getNumber(bundle_revision_pt revision, long *revisionNr);
-
-/**
- * Retrieves the location of the given revision.
- *
- * @param revision The revision to get the location for.
- * @param[out] location The location.
- *
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT If <code>revision</code> is illegal.
- */
-celix_status_t bundleRevision_getLocation(bundle_revision_pt revision, const char **location);
-
-/**
- * Retrieves the root of the given revision.
- *
- * @param revision The revision to get the location for.
- * @param[out] root The root.
- *
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT If <code>revision</code> is illegal.
- */
-celix_status_t bundleRevision_getRoot(bundle_revision_pt revision, const char **root);
-
-/**
- * Retrieves the manifest of the given revision.
- *
- * @param revision The revision to get the manifest for.
- * @param[out] manifest The manifest.
- *
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT If <code>revision</code> is illegal.
- */
-celix_status_t bundleRevision_getManifest(bundle_revision_pt revision, manifest_pt *manifest);
-
-/**
- * Retrieves the handles of the installed libraries for this revision.
- *
- * @param revision The revision to get the manifest for.
- * @param[out] handles array_list_pt containing the handles.
- *
- * @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ILLEGAL_ARGUMENT If <code>revision</code> is illegal.
- */
-celix_status_t bundleRevision_getHandles(bundle_revision_pt revision, array_list_pt *handles);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* BUNDLE_REVISION_H_ */
-
-/**
- * @}
- */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/bundle_state.h
----------------------------------------------------------------------
diff --git a/framework/include/bundle_state.h b/framework/include/bundle_state.h
deleted file mode 100644
index 2a49c3e..0000000
--- a/framework/include/bundle_state.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- *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.
- */
-/*
- * bundle_state.h
- *
- * \date Sep 27, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef BUNDLE_STATE_H_
-#define BUNDLE_STATE_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum celix_bundleState {
- OSGI_FRAMEWORK_BUNDLE_UNKNOWN = 0x00000000,
- OSGI_FRAMEWORK_BUNDLE_UNINSTALLED = 0x00000001,
- OSGI_FRAMEWORK_BUNDLE_INSTALLED = 0x00000002,
- OSGI_FRAMEWORK_BUNDLE_RESOLVED = 0x00000004,
- OSGI_FRAMEWORK_BUNDLE_STARTING = 0x00000008,
- OSGI_FRAMEWORK_BUNDLE_STOPPING = 0x00000010,
- OSGI_FRAMEWORK_BUNDLE_ACTIVE = 0x00000020,
-};
-
-typedef enum celix_bundleState bundle_state_e;
-typedef enum celix_bundleState celix_bundle_state_e;
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* BUNDLE_STATE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/capability.h
----------------------------------------------------------------------
diff --git a/framework/include/capability.h b/framework/include/capability.h
deleted file mode 100644
index b35d016..0000000
--- a/framework/include/capability.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- *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.
- */
-/*
- * capability.h
- *
- * \date Jul 12, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef CAPABILITY_H_
-#define CAPABILITY_H_
-
-typedef struct capability *capability_pt;
-
-#include "hash_map.h"
-#include "module.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-celix_status_t
-capability_create(module_pt module, hash_map_pt directives, hash_map_pt attributes, capability_pt *capability);
-
-celix_status_t capability_destroy(capability_pt capability);
-
-celix_status_t capability_getServiceName(capability_pt capability, const char **serviceName);
-
-celix_status_t capability_getVersion(capability_pt capability, version_pt *version);
-
-celix_status_t capability_getModule(capability_pt capability, module_pt *module);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* CAPABILITY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/Component.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/Component.h b/framework/include/celix/dm/Component.h
deleted file mode 100644
index 06aaf20..0000000
--- a/framework/include/celix/dm/Component.h
+++ /dev/null
@@ -1,234 +0,0 @@
-/**
- * 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 CELIX_DM_COMPONENT_H
-#define CELIX_DM_COMPONENT_H
-
-#include "celix/dm/types.h"
-#include "dm_component.h"
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace celix { namespace dm {
-
- class BaseComponent {
- private:
- bundle_context_pt context {nullptr};
- dm_component_pt cCmp {nullptr};
- public:
- BaseComponent(const bundle_context_pt con, std::string name) : context{con}, cCmp{nullptr} {
- component_create(this->context, name.c_str(), &this->cCmp);
- component_setImplementation(this->cCmp, this);
- }
- virtual ~BaseComponent() {}
-
- BaseComponent(const BaseComponent&) = delete;
- BaseComponent& operator=(const BaseComponent&) = delete;
-
- /**
- * Returns the C DM Component
- */
- dm_component_pt cComponent() const { return this->cCmp; }
-
- /**
- * Returns the C bundle context
- */
- bundle_context_pt bundleContext() const { return this->context; }
- };
-
-
- template<class T>
- class Component : public BaseComponent {
- using type = T;
- private:
- std::unique_ptr<T> instance {nullptr};
- std::shared_ptr<T> sharedInstance {nullptr};
- std::vector<T> valInstance {};
- std::vector<std::shared_ptr<BaseServiceDependency>> dependencies {};
-
- void (T::*initFp)() = {};
- void (T::*startFp)() = {};
- void (T::*stopFp)() = {};
- void (T::*deinitFp)() = {};
-
- int (T::*initFpNoExc)() = {};
- int (T::*startFpNoExc)() = {};
- int (T::*stopFpNoExc)() = {};
- int (T::*deinitFpNoExc)() = {};
- public:
- Component(const bundle_context_pt context, std::string name);
- virtual ~Component();
-
- /**
- * Creates a Component using the provided bundle context
- * and component name.
- * Will use new(nothrow) if exceptions are disabled.
- * @return newly created DM Component or nullptr
- */
- static Component<T>* create(bundle_context_pt, std::string name);
-
- /**
- * Creates a Component using the provided bundle context.
- * Will use new(nothrow) if exceptions are disabled.
- * @return newly created DM Component or nullptr
- */
- static Component<T>* create(bundle_context_pt);
-
- /**
- * Wether the component is valid. Invalid component can occurs when no new components can be created and
- * exceptions are not allowed.
- * @return
- */
- bool isValid() const;
-
- /**
- * Get the component instance. If no instance is explicitly set with setInstance than a instance will be create
- * using a default constructor.
- *
- * @return A reference to the component instance.
- */
- T& getInstance();
-
- /**
- * Set the component instance using a shared pointer.
- *
- * @return the DM Component reference for chaining (fluent API)
- */
- Component<T>& setInstance(std::shared_ptr<T> inst);
-
- /**
- * Set the component instance using a unique pointer.
- *
- * @return the DM Component reference for chaining (fluent API)
- */
- Component<T>& setInstance(std::unique_ptr<T>&& inst);
-
- /**
- * Set the component instance using a value or rval reference
- * The DM Component will contain the instance.
- *
- * @return the DM Component reference for chaining (fluent API)
- */
- Component<T>& setInstance(T&& inst);
-
- /**
- * Adds a C++ interface to provide as service to the Celix framework.
- *
- * @param serviceName The service name to use
- * @param version The version of the interface (e.g. "1.0.0"), can be an empty string
- * @param properties To (meta) properties to provide with the service
- * @return the DM Component reference for chaining (fluent API)
- */
- template<class I> Component<T>& addInterfaceWithName(const std::string serviceName, const std::string version = std::string{}, const Properties properties = Properties{});
-
- /**
- * Adds a C++ interface to provide as service to the Celix framework.
- *
- * @param serviceName The service name to use
- * @param version The version of the interface (e.g. "1.0.0"), can be an empty string
- * @param properties To (meta) properties to provide with the service
- * @return the DM Component reference for chaining (fluent API)
- */
- template<class I> Component<T>& addInterface(const std::string version = std::string{}, const Properties properties = Properties{});
-
- /**
- * Adds a C interface to provide as service to the Celix framework.
- *
- * @param svc The service struct
- * @param serviceName The service name to use
- * @param version The version of the interface (e.g. "1.0.0"), can be an empty string
- * @param properties To (meta) properties to provide with the service
- */
- template<class I> Component<T>& addCInterface(const I* svc, const std::string serviceName, const std::string version = std::string{}, const Properties properties = Properties{});
-
-
- /**
- * Creates and adds a C++ service dependency to the component
- *
- * @return the Service Dependency reference for chaining (fluent API)
- */
- template<class I>
- ServiceDependency<T,I>& createServiceDependency(const std::string name = std::string{});
-
- /**
- Removes a C++ service dependency from the component
- *
- * @return the DM Component reference for chaining (fluent API)
- */
- template<class I>
- Component<T>& remove(ServiceDependency<T,I>& dep);
-
- /**
- * Adds a C service dependency to the component
- *
- * @return the DM Component reference for chaining (fluent API)
- */
- template<typename I>
- CServiceDependency<T,I>& createCServiceDependency(const std::string name);
-
- /**
- * Removes a C service dependency to the component
- *
- * @return the DM Component reference for chaining (fluent API)
- */
- template<typename I>
- Component<T>& remove(CServiceDependency<T,I>& dep);
-
- /**
- * Set the callback for the component life cycle control
- *
- * @param init The init callback.
- * @param start The start callback.
- * @param stop The stop callback.
- * @param deinit The deinit callback.
- *
- * @return the DM Component reference for chaining (fluent API)
- */
- Component<T>& setCallbacks(
- void (T::*init)(),
- void (T::*start)(),
- void (T::*stop)(),
- void (T::*deinit)()
- );
-
- /**
- * Set the callback for the component life cycle control
- * with a int return to indicate an error.
- *
- * @param init The init callback.
- * @param start The start callback.
- * @param stop The stop callback.
- * @param deinit The deinit callback.
- *
- * @return the DM Component reference for chaining (fluent API)
- */
- Component<T>& setCallbacks(
- int (T::*init)(),
- int (T::*start)(),
- int (T::*stop)(),
- int (T::*deinit)()
- );
- };
-}}
-
-#include "celix/dm/Component_Impl.h"
-
-#endif //CELIX_DM_COMPONENT_H
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/Component_Impl.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/Component_Impl.h b/framework/include/celix/dm/Component_Impl.h
deleted file mode 100644
index 722431f..0000000
--- a/framework/include/celix/dm/Component_Impl.h
+++ /dev/null
@@ -1,320 +0,0 @@
-/**
- * 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 "celix/dm/Component.h"
-#include "celix/dm/DependencyManager.h"
-#include "celix/dm/ServiceDependency.h"
-
-#include <memory>
-#include <iostream>
-#include <iomanip>
-#include <type_traits>
-#include <algorithm>
-
-using namespace celix::dm;
-
-template<class T>
-Component<T>::Component(const bundle_context_pt context, std::string name) : BaseComponent(context, name) {}
-
-template<class T>
-Component<T>::~Component() {
- this->dependencies.clear();
-}
-
-template<class T>
-template<class I>
-Component<T>& Component<T>::addInterfaceWithName(const std::string serviceName, const std::string version, const Properties properties) {
- if (!serviceName.empty()) {
- //setup c properties
- properties_pt cProperties = properties_create();
- properties_set(cProperties, CELIX_FRAMEWORK_SERVICE_LANGUAGE, CELIX_FRAMEWORK_SERVICE_CXX_LANGUAGE);
- for (const auto& pair : properties) {
- properties_set(cProperties, (char *) pair.first.c_str(), (char *) pair.second.c_str());
- }
-
- T* cmpPtr = &this->getInstance();
- I* intfPtr = static_cast<I*>(cmpPtr); //NOTE T should implement I
-
- const char *cVersion = version.empty() ? nullptr : version.c_str();
- component_addInterface(this->cComponent(), (char *) serviceName.c_str(), (char *) cVersion,
- intfPtr, cProperties);
- } else {
- std::cerr << "Cannot add interface with a empty name\n";
- }
-
- return *this;
-}
-
-template<class T>
-template<class I>
-Component<T>& Component<T>::addInterface(const std::string version, const Properties properties) {
- //get name if not provided
- static_assert(std::is_base_of<I,T>::value, "Component T must implement Interface I");
- std::string serviceName = typeName<I>();
- if (serviceName.empty()) {
- std::cerr << "Cannot add interface, because type name could not be inferred. function: '" << __PRETTY_FUNCTION__ << "'\n";
- }
-
- return this->addInterfaceWithName<I>(serviceName, version, properties);
-};
-
-template<class T>
-template<class I>
-Component<T>& Component<T>::addCInterface(const I* svc, const std::string serviceName, const std::string version, const Properties properties) {
- static_assert(std::is_pod<I>::value, "Service I must be a 'Plain Old Data' object");
- properties_pt cProperties = properties_create();
- properties_set(cProperties, CELIX_FRAMEWORK_SERVICE_LANGUAGE, CELIX_FRAMEWORK_SERVICE_C_LANGUAGE);
- for (const auto& pair : properties) {
- properties_set(cProperties, (char*)pair.first.c_str(), (char*)pair.second.c_str());
- }
-
- const char *cVersion = version.empty() ? nullptr : version.c_str();
- component_addInterface(this->cComponent(), (char*)serviceName.c_str(), (char*)cVersion, svc, cProperties);
-
- return *this;
-};
-
-template<class T>
-template<class I>
-ServiceDependency<T,I>& Component<T>::createServiceDependency(const std::string name) {
-#ifdef __EXCEPTIONS
- auto dep = std::shared_ptr<ServiceDependency<T,I>> {new ServiceDependency<T,I>(name)};
-#else
- static ServiceDependency<T,I> invalidDep{std::string{}, false};
- auto dep = std::shared_ptr<ServiceDependency<T,I>> {new(std::nothrow) ServiceDependency<T,I>(name)};
- if (dep == nullptr) {
- return invalidDep;
- }
-#endif
- this->dependencies.push_back(dep);
- component_addServiceDependency(cComponent(), dep->cServiceDependency());
- dep->setComponentInstance(&getInstance());
- return *dep;
-}
-
-template<class T>
-template<class I>
-Component<T>& Component<T>::remove(ServiceDependency<T,I>& dep) {
- component_removeServiceDependency(cComponent(), dep.cServiceDependency());
- this->dependencies.erase(std::remove(this->dependencies.begin(), this->dependencies.end(), dep));
- return *this;
-}
-
-template<class T>
-template<typename I>
-CServiceDependency<T,I>& Component<T>::createCServiceDependency(const std::string name) {
-#ifdef __EXCEPTIONS
- auto dep = std::shared_ptr<CServiceDependency<T,I>> {new CServiceDependency<T,I>(name)};
-#else
- static CServiceDependency<T,I> invalidDep{std::string{}, false};
- auto dep = std::shared_ptr<CServiceDependency<T,I>> {new(std::nothrow) CServiceDependency<T,I>(name)};
- if (dep == nullptr) {
- return invalidDep;
- }
-#endif
- this->dependencies.push_back(dep);
- component_addServiceDependency(cComponent(), dep->cServiceDependency());
- dep->setComponentInstance(&getInstance());
- return *dep;
-}
-
-template<class T>
-template<typename I>
-Component<T>& Component<T>::remove(CServiceDependency<T,I>& dep) {
- component_removeServiceDependency(cComponent(), dep.cServiceDependency());
- this->dependencies.erase(std::remove(this->dependencies.begin(), this->dependencies.end(), dep));
- return *this;
-}
-
-template<class T>
-Component<T>* Component<T>::create(bundle_context_pt context) {
- std::string name = typeName<T>();
- return Component<T>::create(context, name);
-}
-
-template<class T>
-Component<T>* Component<T>::create(bundle_context_pt context, std::string name) {
-#ifdef __EXCEPTIONS
- Component<T>* cmp = new Component<T>{context, name};
-#else
- static Component<T> invalid{nullptr, std::string{}};
- Component<T>* cmp = new(std::nothrow) Component<T>(context, name);
- if (cmp == nullptr) {
- cmp = &invalid;
- }
-#endif
- return cmp;
-}
-
-template<class T>
-bool Component<T>::isValid() const {
- return this->bundleContext() != nullptr;
-}
-
-template<class T>
-T& Component<T>::getInstance() {
- if (this->valInstance.size() == 1) {
- return valInstance.front();
- } else if (this->sharedInstance.get() != nullptr) {
- return *this->sharedInstance;
- } else {
- if (this->instance.get() == nullptr) {
-#ifdef __EXCEPTIONS
- this->instance = std::unique_ptr<T> {new T()};
-#else
- this->instance = std::unique_ptr<T> {new(std::nothrow) T()};
-
-#endif
- }
- return *this->instance;
- }
-}
-
-template<class T>
-Component<T>& Component<T>::setInstance(std::shared_ptr<T> inst) {
- this->valInstance.clear();
- this->instance = std::unique_ptr<T> {nullptr};
- this->sharedInstance = inst;
- return *this;
-}
-
-template<class T>
-Component<T>& Component<T>::setInstance(std::unique_ptr<T>&& inst) {
- this->valInstance.clear();
- this->sharedInstance = std::shared_ptr<T> {nullptr};
- this->instance = std::move(inst);
- return *this;
-}
-
-template<class T>
-Component<T>& Component<T>::setInstance(T&& inst) {
- this->instance = std::unique_ptr<T> {nullptr};
- this->sharedInstance = std::shared_ptr<T> {nullptr};
- this->valInstance.clear();
- this->valInstance.push_back(std::forward<T>(inst));
- return *this;
-}
-
-template<class T>
-Component<T>& Component<T>::setCallbacks(
- void (T::*init)(),
- void (T::*start)(),
- void (T::*stop)(),
- void (T::*deinit)() ) {
-
- this->initFp = init;
- this->startFp = start;
- this->stopFp = stop;
- this->deinitFp = deinit;
-
- int (*cInit)(void *) = [](void *handle) {
- Component<T>* cmp = (Component<T>*)(handle);
- T* inst = &cmp->getInstance();
- void (T::*fp)() = cmp->initFp;
- if (fp != nullptr) {
- (inst->*fp)();
- }
- return 0;
- };
- int (*cStart)(void *) = [](void *handle) {
- Component<T>* cmp = (Component<T>*)(handle);
- T* inst = &cmp->getInstance();
- void (T::*fp)() = cmp->startFp;
- if (fp != nullptr) {
- (inst->*fp)();
- }
- return 0;
- };
- int (*cStop)(void *) = [](void *handle) {
- Component<T>* cmp = (Component<T>*)(handle);
- T* inst = &cmp->getInstance();
- void (T::*fp)() = cmp->stopFp;
- if (fp != nullptr) {
- (inst->*fp)();
- }
- return 0;
- };
- int (*cDeinit)(void *) = [](void *handle) {
- Component<T>* cmp = (Component<T>*)(handle);
- T* inst = &cmp->getInstance();
- void (T::*fp)() = cmp->deinitFp;
- if (fp != nullptr) {
- (inst->*fp)();
- }
- return 0;
- };
-
- component_setCallbacks(this->cComponent(), cInit, cStart, cStop, cDeinit);
-
- return *this;
-}
-
-template<class T>
-Component<T>& Component<T>::setCallbacks(
- int (T::*init)(),
- int (T::*start)(),
- int (T::*stop)(),
- int (T::*deinit)() ) {
-
- this->initFpNoExc = init;
- this->startFpNoExc = start;
- this->stopFpNoExc = stop;
- this->deinitFpNoExc = deinit;
-
- int (*cInit)(void *) = [](void *handle) {
- Component<T>* cmp = (Component<T>*)(handle);
- T* inst = &cmp->getInstance();
- int (T::*fp)() = cmp->initFpNoExc;
- if (fp != nullptr) {
- return (inst->*fp)();
- }
- return 0;
- };
- int (*cStart)(void *) = [](void *handle) {
- Component<T>* cmp = (Component<T>*)(handle);
- T* inst = &cmp->getInstance();
- int (T::*fp)() = cmp->startFpNoExc;
- if (fp != nullptr) {
- return (inst->*fp)();
- }
- return 0;
- };
- int (*cStop)(void *) = [](void *handle) {
- Component<T>* cmp = (Component<T>*)(handle);
- T* inst = &cmp->getInstance();
- int (T::*fp)() = cmp->stopFpNoExc;
- if (fp != nullptr) {
- return (inst->*fp)();
- }
- return 0;
- };
- int (*cDeinit)(void *) = [](void *handle) {
- Component<T>* cmp = (Component<T>*)(handle);
- T* inst = &cmp->getInstance();
- int (T::*fp)() = cmp->deinitFpNoExc;
- if (fp != nullptr) {
- return (inst->*fp)();
- }
- return 0;
- };
-
- component_setCallbacks(this->cComponent(), cInit, cStart, cStop, cDeinit);
-
- return *this;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/DependencyManager.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/DependencyManager.h b/framework/include/celix/dm/DependencyManager.h
deleted file mode 100644
index f90a03c..0000000
--- a/framework/include/celix/dm/DependencyManager.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * 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 "celix/dm/types.h"
-#include "celix/dm/Component.h"
-#include "celix/dm/ServiceDependency.h"
-
-#include "bundle_context.h"
-#include "celix_bundle_context.h"
-#include "dm_dependency_manager.h"
-
-#include <vector>
-#include <mutex>
-
-#ifndef CELIX_DM_DEPENDENCYMANAGER_H
-#define CELIX_DM_DEPENDENCYMANAGER_H
-
-namespace celix { namespace dm {
-
- class DependencyManager {
- public:
- DependencyManager(bundle_context_pt ctx) : context(ctx) {
- this->cDepMan = celix_bundleContext_getDependencyManager(ctx);
- }
-
- virtual ~DependencyManager() {
- this->cDepMan = nullptr;
- }
-
- DependencyManager(DependencyManager&& mgr) : componentsMutex{} {
- std::lock_guard<std::recursive_mutex> lock(this->componentsMutex);
- mgr.context = this->context;
- mgr.queuedComponents = std::move(this->queuedComponents);
- mgr.startedComponents = std::move(this->startedComponents);
- mgr.cDepMan = this->cDepMan;
- this->cDepMan = nullptr;
- this->context = nullptr;
- }
- DependencyManager& operator=(DependencyManager&&) = default;
-
- DependencyManager(const DependencyManager&) = delete;
- DependencyManager& operator=(const DependencyManager&) = delete;
-
- bundle_context_pt bundleContext() const { return context; }
- dm_dependency_manager_pt cDependencyManager() const { return cDepMan; }
-
-
- /**
- * Creates and adds a new DM Component for a component of type T.
- *
- * @return Returns a reference to the DM Component
- */
- template<class T>
- Component<T>& createComponent(std::string name = std::string{});
-
- /**
- * Creates and adds a new DM Component for a component of type T and setting
- * the instance using a unique ptr.
- *
- * @return Returns a reference to the DM Component
- */
- template<class T>
- Component<T>& createComponent(std::unique_ptr<T>&& rhs, std::string name = std::string{});
-
- /**
- * Creates and adds a new DM Component for a component of type T and setting
- * the instance using a shared ptr.
- *
- * @return Returns a reference to the DM Component
- */
- template<class T>
- Component<T>& createComponent(std::shared_ptr<T> rhs, std::string name = std::string{});
-
- /**
- * Creates and adds a new DM Component for a component of type T and setting
- * the instance.
- *
- * @return Returns a reference to the DM Component
- */
- template<class T>
- Component<T>& createComponent(T rhs, std::string name = std::string{});
-
- /**
- * Starts the Dependency Manager
- */
- void start() {
- std::vector<std::unique_ptr<BaseComponent>> toBeStartedComponents {};
- {
- std::lock_guard<std::recursive_mutex> lock(componentsMutex);
- for (auto it = queuedComponents.begin(); it != queuedComponents.end(); ++it) {
- toBeStartedComponents.push_back(std::move(*it));
- }
- queuedComponents.clear();
- }
- for (auto it = toBeStartedComponents.begin(); it != toBeStartedComponents.end(); ++it) {
-
- dependencyManager_add(cDepMan, (*it)->cComponent());
- {
- std::lock_guard<std::recursive_mutex> lock(componentsMutex);
- startedComponents.push_back(std::move(*it));
- }
- }
- }
-
- /**
- * Removes a component from the Dependency Manager and destroys it
- */
- template<typename T>
- void destroyComponent(Component<T> &component) {
- dependencyManager_remove(cDepMan, component.cComponent());
- }
-
- /**
- * Stops the Dependency Manager
- */
- void stop() {
- dependencyManager_removeAllComponents(cDepMan);
- queuedComponents.clear();
- startedComponents.clear();
- }
- private:
- bundle_context_pt context {nullptr};
- std::vector<std::unique_ptr<BaseComponent>> queuedComponents {};
- std::vector<std::unique_ptr<BaseComponent>> startedComponents {};
- dm_dependency_manager_pt cDepMan {nullptr};
- std::recursive_mutex componentsMutex{};
- };
-
-}}
-
-#include "celix/dm/DependencyManager_Impl.h"
-
-#endif //CELIX_DM_DEPENDENCYMANAGER_H
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/DependencyManager_Impl.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/DependencyManager_Impl.h b/framework/include/celix/dm/DependencyManager_Impl.h
deleted file mode 100644
index 82e0802..0000000
--- a/framework/include/celix/dm/DependencyManager_Impl.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.
- */
-
-using namespace celix::dm;
-
-template<class T>
-Component<T>& DependencyManager::createComponent(std::string name) {
- Component<T>* cmp = name.empty() ?
- Component<T>::create(this->context) :
- Component<T>::create(this->context, name);
- if (cmp->isValid()) {
- std::lock_guard<std::recursive_mutex> lock(componentsMutex);
- this->queuedComponents.push_back(std::unique_ptr<BaseComponent> {cmp});
- }
- return *cmp;
-}
-
-template<class T>
-Component<T>& DependencyManager::createComponent(std::unique_ptr<T>&& rhs, std::string name) {
- return this->createComponent<T>(name).setInstance(std::move(rhs));
-}
-
-template<class T>
-Component<T>& DependencyManager::createComponent(std::shared_ptr<T> rhs, std::string name) {
- return this->createComponent<T>(name).setInstance(rhs);
-}
-
-template<class T>
-Component<T>& DependencyManager::createComponent(T rhs, std::string name) {
- return this->createComponent<T>(name).setInstance(std::forward<T>(rhs));
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/DmActivator.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/DmActivator.h b/framework/include/celix/dm/DmActivator.h
deleted file mode 100644
index d7aac3c..0000000
--- a/framework/include/celix/dm/DmActivator.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * 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 CELIX_DM_ACTIVATOR_H
-#define CELIX_DM_ACTIVATOR_H
-
-
-#include <utility>
-
-#include "celix/dm/DependencyManager.h"
-#include "bundle_activator.h"
-
-namespace celix { namespace dm {
-
- class DmActivator {
- public:
- DmActivator(DependencyManager& m) : mng(m), ctx{m.bundleContext()} {}
- virtual ~DmActivator() = default;
-
- DmActivator(const DmActivator&) = delete;
- DmActivator& operator=(const DmActivator&) = delete;
-
- DependencyManager& manager() const { return this->mng; }
-
- bundle_context_pt context() const { return this->ctx; }
-
- /**
- * The init of the DM Activator. Should be overridden by the bundle specific DM activator.
- *
- * @param manager A reference to the Dependency Manager
- */
- virtual void init() {};
-
- /**
- * The init of the DM Activator. Can be overridden by the bundle specific DM activator.
- *
- * @param manager A reference to the Dependency Manager
- */
- virtual void deinit() {};
-
- /**
- * The static method to create a new DM activator.
- * NOTE that this method in intentionally not implemented in the C++ Dependency Manager library.
- * This should be done by the bundle specific DM activator.
- *
- * @param mng A reference to the Dependency Manager
- * @returns A pointer to a DmActivator. The Dependency Manager is responsible for deleting the pointer when the bundle is stopped.
- */
- static DmActivator* create(DependencyManager& mng);
-
- protected:
- DependencyManager& mng;
- bundle_context_pt ctx;
- private:
- int start() {
- celix_status_t status = CELIX_SUCCESS;
- this->init();
- this->mng.start();
-
- return status;
- }
-
- int stop() {
- celix_status_t status = CELIX_SUCCESS;
-
- this->deinit();
-
- // Remove all components
- dependencyManager_removeAllComponents(this->mng.cDependencyManager());
-
- return status;
- }
-
- friend int ::bundleActivator_create(::bundle_context_pt, void**);
- friend int ::bundleActivator_start(void*, ::bundle_context_pt);
- friend int ::bundleActivator_stop(void*, ::bundle_context_pt);
- friend int ::bundleActivator_destroy(void*, ::bundle_context_pt);
- };
-}}
-
-#endif //CELIX_DM_ACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/Properties.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/Properties.h b/framework/include/celix/dm/Properties.h
deleted file mode 100644
index bb4fd78..0000000
--- a/framework/include/celix/dm/Properties.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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 CELIX_DM_PROPERTIES_H
-#define CELIX_DM_PROPERTIES_H
-
-#include <map>
-#include <string>
-
-namespace celix { namespace dm {
- using Properties = std::map<std::string, std::string>;
-}}
-
-#endif //CELIX_DM_PROPERTIES_H
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/ServiceDependency.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/ServiceDependency.h b/framework/include/celix/dm/ServiceDependency.h
deleted file mode 100644
index f439b82..0000000
--- a/framework/include/celix/dm/ServiceDependency.h
+++ /dev/null
@@ -1,326 +0,0 @@
-/**
- * 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 CELIX_DM_SERVICEDEPENDENCY_H
-#define CELIX_DM_SERVICEDEPENDENCY_H
-
-#include "dm_service_dependency.h"
-#include "celix/dm/types.h"
-
-#include <map>
-#include <string>
-#include <list>
-#include <tuple>
-#include <memory>
-#include <iostream>
-#include <functional>
-
-namespace celix { namespace dm {
-
- class DependencyManager; //forward declaration
-
- enum class DependencyUpdateStrategy {
- suspend,
- locking
- };
-
- class BaseServiceDependency {
- protected:
- const bool valid;
- dm_service_dependency_pt cServiceDep {nullptr};
-
- void setDepStrategy(DependencyUpdateStrategy strategy) {
- if (!valid) {
- return;
- }
- if (strategy == DependencyUpdateStrategy::locking) {
- serviceDependency_setStrategy(this->cServiceDependency(), DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
- } else if (strategy == DependencyUpdateStrategy::suspend) {
- serviceDependency_setStrategy(this->cServiceDependency(), DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND);
- } else {
- std::cerr << "Unexpected dependency update strategy. Cannot convert for dm_depdendency\n";
- }
- }
- public:
- BaseServiceDependency(bool v) : valid{v} {
- if (this->valid) {
- serviceDependency_create(&this->cServiceDep);
- //NOTE using suspend as default strategy
- serviceDependency_setStrategy(this->cServiceDep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND);
- }
- }
-
- virtual ~BaseServiceDependency() = default;
-
- BaseServiceDependency(const BaseServiceDependency&) = delete;
- BaseServiceDependency& operator=(const BaseServiceDependency&) = delete;
-
- /**
- * Wether the service dependency is valid.
- */
- bool isValid() const { return valid; }
-
- /**
- * Returns the C DM service dependency
- */
- dm_service_dependency_pt cServiceDependency() const { return cServiceDep; }
- };
-
- template<class T>
- class TypedServiceDependency : public BaseServiceDependency {
- using cmpType = T;
- protected:
- T* componentInstance {nullptr};
- public:
- TypedServiceDependency(bool valid) : BaseServiceDependency(valid) {}
- virtual ~TypedServiceDependency() = default;
-
- TypedServiceDependency(const TypedServiceDependency&) = delete;
- TypedServiceDependency& operator=(const TypedServiceDependency&) = delete;
- TypedServiceDependency(TypedServiceDependency&&) = default;
- TypedServiceDependency& operator=(TypedServiceDependency&&) = default;
-
- /**
- * Set the component instance with a pointer
- */
- void setComponentInstance(T* cmp) { componentInstance = cmp;}
- };
-
- template<class T, typename I>
- class CServiceDependency : public TypedServiceDependency<T> {
- using type = I;
- public:
- CServiceDependency(const std::string name, bool valid = true);
- virtual ~CServiceDependency() = default;
-
- /**
- * Sets the service version range for the C service dependency.
- *
- * @param serviceVersionRange The service version range, can be an empty string
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setVersionRange(const std::string serviceVersionRange);
-
- /**
- * Sets the service filter for the C service dependency.
- *
- * @param filter The (additional) filter to use (e.g. "(location=front)")
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setFilter(const std::string filter);
-
- /**
- * Specify if the service dependency is required. Default is false
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setRequired(bool req);
-
- /**
- * Specify if the update strategy to use
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setStrategy(DependencyUpdateStrategy strategy);
-
- /**
- * Set the set callback for when the service dependency becomes available
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setCallbacks(void (T::*set)(const I* service));
-
- /**
- * Set the set callback for when the service dependency becomes available
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setCallbacks(void (T::*set)(const I* service, Properties&& properties));
-
- /**
- * Set the set callback for when the service dependency becomes available
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setCallbacks(std::function<void(const I* service, Properties&& properties)> set);
-
- /**
- * Set the add and remove callback for when the services of service dependency are added or removed.
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setCallbacks(void (T::*add)(const I* service), void (T::*remove)(const I* service));
-
- /**
- * Set the add and remove callback for when the services of service dependency are added or removed.
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setCallbacks(
- void (T::*add)(const I* service, Properties&& properties),
- void (T::*remove)(const I* service, Properties&& properties)
- );
-
- /**
- * Set the add and remove callback for when the services of service dependency are added or removed.
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- CServiceDependency<T,I>& setCallbacks(
- std::function<void(const I* service, Properties&& properties)> add,
- std::function<void(const I* service, Properties&& properties)> remove
- );
-
- /**
- * Specify if the service dependency should add a service.lang filter part if it is not already present
- * For C service dependencies 'service.lang=C' will be added.
- */
- CServiceDependency<T,I>& setAddLanguageFilter(bool addLang);
- private:
- std::string name {};
- std::string filter {};
- std::string versionRange {};
-
- std::function<void(const I* service, Properties&& properties)> setFp{nullptr};
- std::function<void(const I* service, Properties&& properties)> addFp{nullptr};
- std::function<void(const I* service, Properties&& properties)> removeFp{nullptr};
-
- void setupCallbacks();
- int invokeCallback(std::function<void(const I*, Properties&&)> fp, service_reference_pt ref, const void* service);
-
- void setupService();
- };
-
- template<class T, class I>
- class ServiceDependency : public TypedServiceDependency<T> {
- using type = I;
- public:
- ServiceDependency(const std::string name = std::string{}, bool valid = true);
- virtual ~ServiceDependency() = default;
-
- /**
- * Set the service name of the service dependency.
- *
- * @return the C++ service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setName(const std::string name);
-
- /**
- * Set the service filter of the service dependency.
- *
- * @return the C++ service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setFilter(const std::string filter);
-
- /**
- * Set the service version range of the service dependency.
- *
- * @return the C++ service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setVersionRange(const std::string versionRange);
-
- /**
- * Set the set callback for when the service dependency becomes available
- *
- * @return the C++ service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setCallbacks(void (T::*set)(I* service));
-
- /**
- * Set the set callback for when the service dependency becomes available
- *
- * @return the C++ service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setCallbacks(void (T::*set)(I* service, Properties&& properties));
-
- /**
- * Set the set callback for when the service dependency becomes available
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setCallbacks(std::function<void(I* service, Properties&& properties)> set);
-
- /**
- * Set the add and remove callback for when the services of service dependency are added or removed.
- *
- * @return the C++ service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setCallbacks(void (T::*add)(I* service), void (T::*remove)(I* service));
-
- /**
- * Set the add and remove callback for when the services of service dependency are added or removed.
- *
- * @return the C++ service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setCallbacks(
- void (T::*add)(I* service, Properties&& properties),
- void (T::*remove)(I* service, Properties&& properties)
- );
-
- /**
- * Set the add and remove callback for when the services of service dependency are added or removed.
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setCallbacks(
- std::function<void(I* service, Properties&& properties)> add,
- std::function<void(I* service, Properties&& properties)> remove
- );
-
- /**
- * Specify if the service dependency is required. Default is false
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setRequired(bool req);
-
- /**
- * Specify if the update strategy to use
- *
- * @return the C service dependency reference for chaining (fluent API)
- */
- ServiceDependency<T,I>& setStrategy(DependencyUpdateStrategy strategy);
-
- /**
- * Specify if the service dependency should add a service.lang filter part if it is not already present
- * For C++ service dependencies 'service.lang=C++' will be added.
- * Should be called before
- */
- ServiceDependency<T,I>& setAddLanguageFilter(bool addLang);
- private:
- bool addCxxLanguageFilter {true};
- std::string name {};
- std::string filter {};
- std::string versionRange {};
- std::string modifiedFilter {};
-
- std::function<void(I* service, Properties&& properties)> setFp{nullptr};
- std::function<void(I* service, Properties&& properties)> addFp{nullptr};
- std::function<void(I* service, Properties&& properties)> removeFp{nullptr};
-
- void setupService();
- void setupCallbacks();
- int invokeCallback(std::function<void(I*, Properties&&)> fp, service_reference_pt ref, const void* service);
- };
-}}
-
-#include "celix/dm/ServiceDependency_Impl.h"
-
-
-#endif //CELIX_DM_SERVICEDEPENDENCY_H
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/ServiceDependency_Impl.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/ServiceDependency_Impl.h b/framework/include/celix/dm/ServiceDependency_Impl.h
deleted file mode 100644
index 0f0dc26..0000000
--- a/framework/include/celix/dm/ServiceDependency_Impl.h
+++ /dev/null
@@ -1,449 +0,0 @@
-/**
- * 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 <vector>
-#include <iostream>
-#include "constants.h"
-
-using namespace celix::dm;
-
-template<class T, typename I>
-CServiceDependency<T,I>::CServiceDependency(const std::string name, bool valid) : TypedServiceDependency<T>(valid) {
- this->name = name;
- this->setupService();
-}
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setVersionRange(const std::string serviceVersionRange) {
- this->versionRange = serviceVersionRange;
- this->setupService();
- return *this;
-}
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setFilter(const std::string filter) {
- this->filter = filter;
- this->setupService();
- return *this;
-}
-
-template<class T, typename I>
-void CServiceDependency<T,I>::setupService() {
- if (!this->valid) {
- return;
- }
- const char* cversion = this->versionRange.empty() ? nullptr : versionRange.c_str();
- const char* cfilter = filter.empty() ? nullptr : filter.c_str();
- serviceDependency_setService(this->cServiceDependency(), this->name.c_str(), cversion, cfilter);
-};
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setAddLanguageFilter(bool addLang) {
-// if (!this->valid) {
-// *this;
-// }
- serviceDependency_setAddCLanguageFilter(this->cServiceDependency(), addLang);
- this->setupService();
- return *this;
-};
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setRequired(bool req) {
- if (!this->valid) {
- return *this;
- }
- serviceDependency_setRequired(this->cServiceDependency(), req);
- return *this;
-}
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setStrategy(DependencyUpdateStrategy strategy) {
- if (!this->valid) {
- return *this;
- }
- this->setDepStrategy(strategy);
- return *this;
-}
-
-//set callbacks
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setCallbacks(void (T::*set)(const I* service)) {
- this->setCallbacks([this, set](const I* service, [[gnu::unused]] Properties&& properties) {
- T *cmp = this->componentInstance;
- (cmp->*set)(service);
- });
- return *this;
-}
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setCallbacks(void (T::*set)(const I* service, Properties&& properties)) {
- this->setCallbacks([this, set](const I* service, Properties&& properties) {
- T *cmp = this->componentInstance;
- (cmp->*set)(service, std::move(properties));
- });
- return *this;
-}
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setCallbacks(std::function<void(const I* service, Properties&& properties)> set) {
- this->setFp = set;
- this->setupCallbacks();
- return *this;
-}
-
-//add remove callbacks
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setCallbacks(
- void (T::*add)(const I* service),
- void (T::*remove)(const I* service)) {
- this->setCallbacks(
- [this, add](const I* service, [[gnu::unused]] Properties&& properties) {
- T *cmp = this->componentInstance;
- (cmp->*add)(service);
- },
- [this, remove](const I* service, [[gnu::unused]] Properties&& properties) {
- T *cmp = this->componentInstance;
- (cmp->*remove)(service);
- }
- );
- return *this;
-}
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setCallbacks(
- void (T::*add)(const I* service, Properties&& properties),
- void (T::*remove)(const I* service, Properties&& properties)
-) {
- this->setCallbacks(
- [this, add](const I* service, Properties&& properties) {
- T *cmp = this->componentInstance;
- (cmp->*add)(service, std::move(properties));
- },
- [this, remove](const I* service, Properties&& properties) {
- T *cmp = this->componentInstance;
- (cmp->*remove)(service, std::move(properties));
- }
- );
- return *this;
-}
-
-template<class T, typename I>
-CServiceDependency<T,I>& CServiceDependency<T,I>::setCallbacks(std::function<void(const I* service, Properties&& properties)> add, std::function<void(const I* service, Properties&& properties)> remove) {
- this->addFp = add;;
- this->removeFp = remove;
- this->setupCallbacks();
- return *this;
-}
-
-
-template<class T, typename I>
-void CServiceDependency<T,I>::setupCallbacks() {
- if (!this->valid) {
- return;
- }
-
- int(*cset)(void*, service_reference_pt, const void*) {nullptr};
- int(*cadd)(void*, service_reference_pt, const void*) {nullptr};
- int(*crem)(void*, service_reference_pt, const void*) {nullptr};
-
- if (setFp != nullptr) {
- cset = [](void* handle, service_reference_pt ref, const void* service) -> int {
- auto dep = (CServiceDependency<T,I>*) handle;
- return dep->invokeCallback(dep->setFp, ref, service);
- };
- }
- if (addFp != nullptr) {
- cadd = [](void* handle, service_reference_pt ref, const void* service) -> int {
- auto dep = (CServiceDependency<T,I>*) handle;
- return dep->invokeCallback(dep->addFp, ref, service);
- };
- }
- if (removeFp != nullptr) {
- crem= [](void* handle, service_reference_pt ref, const void* service) -> int {
- auto dep = (CServiceDependency<T,I>*) handle;
- return dep->invokeCallback(dep->removeFp, ref, service);
- };
- }
- serviceDependency_setCallbackHandle(this->cServiceDependency(), this);
- serviceDependency_setCallbacksWithServiceReference(this->cServiceDependency(), cset, cadd, nullptr, crem, nullptr);
-}
-
-template<class T, typename I>
-int CServiceDependency<T,I>::invokeCallback(std::function<void(const I*, Properties&&)> fp, service_reference_pt ref, const void* service) {
- service_registration_pt reg {nullptr};
- properties_pt props {nullptr};
-
- Properties properties {};
- const char* key {nullptr};
- const char* value {nullptr};
-
- if (ref != nullptr) {
- serviceReference_getServiceRegistration(ref, ®);
- serviceRegistration_getProperties(reg, &props);
-
- hash_map_iterator_t iter = hashMapIterator_construct((hash_map_pt)props);
- while(hashMapIterator_hasNext(&iter)) {
- key = (const char*) hashMapIterator_nextKey(&iter);
- value = properties_get(props, key);
- //std::cout << "got property " << key << "=" << value << "\n";
- properties[key] = value;
- }
- }
-
- const I* srv = (const I*) service;
-
- fp(srv, std::move(properties));
- return 0;
-}
-
-template<class T, class I>
-ServiceDependency<T,I>::ServiceDependency(std::string name, bool valid) : TypedServiceDependency<T>(valid) {
- if (!name.empty()) {
- this->setName(name);
- } else {
- this->setupService();
- }
-};
-
-template<class T, class I>
-void ServiceDependency<T,I>::setupService() {
- if (!this->valid) {
- return;
- }
-
- std::string n = name;
-
- if (n.empty()) {
- n = typeName<I>();
- if (n.empty()) {
- std::cerr << "Error in service dependency. Type name cannot be inferred, using '<TYPE_NAME_ERROR>'. function: '" << __PRETTY_FUNCTION__ << "'\n";
- n = "<TYPE_NAME_ERROR>";
- }
- }
-
- const char* v = versionRange.empty() ? nullptr : versionRange.c_str();
-
-
- if (this->addCxxLanguageFilter) {
-
- char langFilter[128];
- snprintf(langFilter, sizeof(langFilter), "(%s=%s)", CELIX_FRAMEWORK_SERVICE_LANGUAGE,
- CELIX_FRAMEWORK_SERVICE_CXX_LANGUAGE);
-
- //setting modified filter. which is in a filter including a lang=c++
- modifiedFilter = std::string{langFilter};
- if (!filter.empty()) {
- char needle[128];
- snprintf(needle, sizeof(needle), "(%s=", CELIX_FRAMEWORK_SERVICE_LANGUAGE);
- size_t langFilterPos = filter.find(needle);
- if (langFilterPos != std::string::npos) {
- //do nothing filter already contains a language part.
- } else if (strncmp(filter.c_str(), "(&", 2) == 0 && filter[filter.size() - 1] == ')') {
- modifiedFilter = filter.substr(0, filter.size() - 1); //remove closing ')'
- modifiedFilter = modifiedFilter.append(langFilter);
- modifiedFilter = modifiedFilter.append(")"); //add closing ')'
- } else if (filter[0] == '(' && filter[filter.size() - 1] == ')') {
- modifiedFilter = "(&";
- modifiedFilter = modifiedFilter.append(filter);
- modifiedFilter = modifiedFilter.append(langFilter);
- modifiedFilter = modifiedFilter.append(")");
- } else {
- std::cerr << "Unexpected filter layout: '" << filter << "'\n";
- }
- }
- } else {
- this->modifiedFilter = this->filter;
- }
-
- serviceDependency_setService(this->cServiceDependency(), n.c_str(), v, this->modifiedFilter.c_str());
-}
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setName(std::string name) {
- this->name = name;
- setupService();
- return *this;
-};
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setFilter(std::string filter) {
- this->filter = filter;
- setupService();
- return *this;
-};
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setVersionRange(std::string versionRange) {
- this->versionRange = versionRange;
- setupService();
- return *this;
-};
-
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setAddLanguageFilter(bool addLang) {
- this->addCxxLanguageFilter = addLang;
- setupService();
- return *this;
-};
-
-//set callbacks
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setCallbacks(void (T::*set)(I* service)) {
- this->setCallbacks([this, set](I* srv, [[gnu::unused]] Properties&& props) {
- T *cmp = this->componentInstance;
- (cmp->*set)(srv);
- });
- return *this;
-}
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setCallbacks(void (T::*set)(I* service, Properties&& properties)) {
- this->setCallbacks([this, set](I* srv, Properties&& props) {
- T *cmp = this->componentInstance;
- (cmp->*set)(srv, std::move(props));
- });
- return *this;
-}
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setCallbacks(std::function<void(I* service, Properties&& properties)> set) {
- this->setFp = set;
- this->setupCallbacks();
- return *this;
-}
-
-//add remove callbacks
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setCallbacks(
- void (T::*add)(I* service),
- void (T::*remove)(I* service)) {
- this->setCallbacks(
- [this, add](I* srv, [[gnu::unused]] Properties&& props) {
- T *cmp = this->componentInstance;
- (cmp->*add)(srv);
- },
- [this, remove](I* srv, [[gnu::unused]] Properties&& props) {
- T *cmp = this->componentInstance;
- (cmp->*remove)(srv);
- }
- );
- return *this;
-}
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setCallbacks(
- void (T::*add)(I* service, Properties&& properties),
- void (T::*remove)(I* service, Properties&& properties)
- ) {
- this->setCallbacks(
- [this, add](I* srv, Properties&& props) {
- T *cmp = this->componentInstance;
- (cmp->*add)(srv, std::move(props));
- },
- [this, remove](I* srv, Properties&& props) {
- T *cmp = this->componentInstance;
- (cmp->*remove)(srv, std::move(props));
- }
- );
- return *this;
-}
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setCallbacks(
- std::function<void(I* service, Properties&& properties)> add,
- std::function<void(I* service, Properties&& properties)> remove) {
- this->addFp = add;
- this->removeFp = remove;
- this->setupCallbacks();
- return *this;
-}
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setRequired(bool req) {
- serviceDependency_setRequired(this->cServiceDependency(), req);
- return *this;
-}
-
-template<class T, class I>
-ServiceDependency<T,I>& ServiceDependency<T,I>::setStrategy(DependencyUpdateStrategy strategy) {
- this->setDepStrategy(strategy);
- return *this;
-};
-
-template<class T, class I>
-int ServiceDependency<T,I>::invokeCallback(std::function<void(I*, Properties&&)> fp, service_reference_pt ref, const void* service) {
- service_registration_pt reg {nullptr};
- properties_pt props {nullptr};
- I *svc = (I*)service;
-
- Properties properties {};
- const char* key {nullptr};
- const char* value {nullptr};
-
- if (ref != nullptr) {
- serviceReference_getServiceRegistration(ref, ®);
- serviceRegistration_getProperties(reg, &props);
- if (props != nullptr) {
- hash_map_iterator_t iter = hashMapIterator_construct((hash_map_pt)props);
- while(hashMapIterator_hasNext(&iter)) {
- key = (const char*) hashMapIterator_nextKey(&iter);
- value = properties_get(props, key);
- //std::cout << "got property " << key << "=" << value << "\n";
- properties[key] = value;
- }
- }
- }
-
- fp(svc, std::move(properties)); //explicit move of lvalue properties.
- return 0;
-}
-
-template<class T, class I>
-void ServiceDependency<T,I>::setupCallbacks() {
- if (!this->valid) {
- return;
- }
-
- int(*cset)(void*, service_reference_pt, const void*) {nullptr};
- int(*cadd)(void*, service_reference_pt, const void*) {nullptr};
- int(*crem)(void*, service_reference_pt, const void*) {nullptr};
-
- if (setFp != nullptr) {
- cset = [](void* handle, service_reference_pt ref, const void* service) -> int {
- auto dep = (ServiceDependency<T,I>*) handle;
- return dep->invokeCallback(dep->setFp, ref, service);
- };
- }
- if (addFp != nullptr) {
- cadd = [](void* handle, service_reference_pt ref, const void* service) -> int {
- auto dep = (ServiceDependency<T,I>*) handle;
- return dep->invokeCallback(dep->addFp, ref, service);
- };
- }
- if (removeFp != nullptr) {
- crem = [](void* handle, service_reference_pt ref, const void* service) -> int {
- auto dep = (ServiceDependency<T,I>*) handle;
- return dep->invokeCallback(dep->removeFp, ref, service);
- };
- }
-
- serviceDependency_setCallbackHandle(this->cServiceDependency(), this);
- serviceDependency_setCallbacksWithServiceReference(this->cServiceDependency(), cset, cadd, nullptr, crem, nullptr);
-};
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/include/celix/dm/types.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/dm/types.h b/framework/include/celix/dm/types.h
deleted file mode 100644
index 43f0f04..0000000
--- a/framework/include/celix/dm/types.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * 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 CELIX_DM_TYPES_H
-#define CELIX_DM_TYPES_H
-
-#include <map>
-#include <string>
-#include <list>
-#include <tuple>
-#include <typeinfo>
-#include <memory>
-#include <cxxabi.h>
-#include <string.h>
-#include "celix/dm/Properties.h"
-#include <stdlib.h>
-#include <iostream>
-
-namespace celix { namespace dm {
- //forward declarations
- class DependencyManager;
-
-
- class BaseServiceDependency;
-
- template<class T, typename I>
- class CServiceDependency;
-
- template<class T, class I>
- class ServiceDependency;
-
- /**
- * Returns the deferred type name for the template I
- */
- template<typename INTERFACE_TYPENAME>
- const std::string typeName() {
- std::string result;
-
-#ifdef __GXX_RTTI
- result = typeid(INTERFACE_TYPENAME).name();
- int status = 0;
- char* demangled_name {abi::__cxa_demangle(result.c_str(), NULL, NULL, &status)};
- if(status == 0) {
- result = std::string{demangled_name};
- free(demangled_name);
- }
-#else
- const char *templateStr = "INTERFACE_TYPENAME = ";
- const size_t templateStrLen = strlen(templateStr);
-
- result = __PRETTY_FUNCTION__; //USING pretty function to retrieve the filled in template argument without using typeid()
- size_t bpos = result.find(templateStr) + templateStrLen; //find begin pos after INTERFACE_TYPENAME = entry
- size_t epos = bpos;
- while (isalnum(result[epos]) || result[epos] == '_' || result[epos] == ':') {
- epos += 1;
- }
- size_t len = epos - bpos;
- result = result.substr(bpos, len);
-#endif
-
-// std::cout << "PRETTY IS '" << __PRETTY_FUNCTION__ << "'\n";
-// std::cout << "RESULT IS '" << result << "'\n";
-
- if (result.empty()) {
- std::cerr << "Cannot infer type name in function call '" << __PRETTY_FUNCTION__ << "'\n'";
- }
-
-
- return result;
- }
-
-}}
-
-#endif //CELIX_DM_TYPES_H