Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-426-cxx-api [created] 764bd7f7a


http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/include/celix/impl/FrameworkImpl.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/impl/FrameworkImpl.h 
b/framework/include/celix/impl/FrameworkImpl.h
new file mode 100644
index 0000000..4a68307
--- /dev/null
+++ b/framework/include/celix/impl/FrameworkImpl.h
@@ -0,0 +1,113 @@
+/**
+ *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_IMPL_FRAMEWORKIMPL_H
+#define CELIX_IMPL_FRAMEWORKIMPL_H
+
+#include "celix_framework_factory.h"
+#include "framework.h"
+
+#include "celix/impl/BundleImpl.h"
+
+namespace celix {
+
+    namespace impl {
+
+        class FrameworkImpl :public celix::Framework {
+        public:
+            FrameworkImpl(framework_t *c_fw) : owner{false} {
+                //wrapper framework
+                this->c_fwm = c_fw;
+                //assume started framework
+                this->setFrameworkContext();
+            }
+
+            FrameworkImpl(celix::Properties config) : owner{true} {
+                //framework which also owns the underlining c framework
+                auto c_config = properties_create();
+                for (auto &pair : config) {
+                    properties_set(c_config, pair.first.c_str(), 
pair.second.c_str());
+                }
+                this->c_fwm = frameworkFactory_newFramework(c_config); 
//should be started
+
+                this->setFrameworkContext();
+            };
+
+            virtual ~FrameworkImpl() {
+                if (this->owner && this->c_fwm != nullptr) {
+                    framework_stop(this->c_fwm);
+                    framework_waitForStop(this->c_fwm);
+                    framework_destroy(this->c_fwm);
+                }
+            }
+
+            virtual void start() noexcept override {
+                framework_start(this->c_fwm);
+            }
+
+            virtual void stop() noexcept override {
+                framework_stop(this->c_fwm);
+            }
+
+            virtual void waitForStop() noexcept override {
+                framework_waitForStop(this->c_fwm);
+            }
+            //TODO also in c virtual void breakWaitForStops() noexcept = 0;
+
+            virtual std::string getUUID() const noexcept override {
+                return std::string{framework_getUUID(this->c_fwm)};
+            }
+
+            celix::BundleContext& getFrameworkContext() noexcept override {
+                BundleContext &ctx = this->bundleContextsCache.at(0);
+                return ctx;
+            }
+
+            celix::Bundle& getFrameworkBundle() noexcept override {
+                if (this->fwBundle.size() == 0) {
+                    bundle_t* c_bnd = nullptr;
+                    framework_getFrameworkBundle(this->c_fwm, &c_bnd);
+                    
this->fwBundle.emplace_back(celix::impl::BundleImpl{c_bnd});
+
+                }
+                return this->fwBundle[0];
+            }
+
+        private:
+
+            void setFrameworkContext() {
+                //create and set framework bundle context (replace invalid 
bundle context)
+                bundle_t *fwmBundle = nullptr;
+                bundle_context_t *fwmCtx = nullptr;
+                framework_getFrameworkBundle(this->c_fwm, &fwmBundle);
+                bundle_getContext(fwmBundle, &fwmCtx);
+                this->bundleContextsCache.emplace(0, fwmCtx);
+            }
+
+
+            bool owner;
+            framework_t *c_fwm{nullptr};
+            std::map<long,celix::impl::BundleContextImpl> 
bundleContextsCache{};
+            std::vector<celix::impl::BundleImpl> fwBundle{}; //optional entry
+
+        };
+    }
+}
+
+#endif //CELIX_IMPL_FRAMEWORKIMPL_H

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/include/celix_api.h
----------------------------------------------------------------------
diff --git a/framework/include/celix_api.h b/framework/include/celix_api.h
index b770876..12c87e0 100644
--- a/framework/include/celix_api.h
+++ b/framework/include/celix_api.h
@@ -21,7 +21,9 @@
 #define CELIX_CELIX_API_H_
 
 #include "celix_utils_api.h"
-#include "bundle.h"
+
+#include "celix_constants.h"
+#include "celix_bundle.h"
 #include "bundle_context.h"
 #include "service_registration.h"
 #include "service_factory.h"

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/include/celix_bundle.h
----------------------------------------------------------------------
diff --git a/framework/include/celix_bundle.h b/framework/include/celix_bundle.h
new file mode 100644
index 0000000..6013635
--- /dev/null
+++ b/framework/include/celix_bundle.h
@@ -0,0 +1,153 @@
+/**
+ *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_BUNDLE_H_
+#define CELIX_BUNDLE_H_
+
+#include "celix_types.h"
+
+#include "celix_errno.h"
+#include "bundle_state.h"
+#include "bundle_archive.h"
+#include "framework.h"
+#include "wire.h"
+#include "module.h"
+#include "service_reference.h"
+#include "bundle_context.h"
+#include "celix_log.h"
+#include "celix_threads.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+FRAMEWORK_EXPORT celix_status_t bundle_create(bundle_pt *bundle);
+
+FRAMEWORK_EXPORT celix_status_t
+bundle_createFromArchive(bundle_pt *bundle, framework_pt framework, 
bundle_archive_pt archive);
+
+FRAMEWORK_EXPORT celix_status_t bundle_destroy(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool 
*systemBundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getArchive(bundle_pt bundle, 
bundle_archive_pt *archive);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getCurrentModule(bundle_pt bundle, 
module_pt *module);
+
+FRAMEWORK_EXPORT array_list_pt bundle_getModules(bundle_pt bundle);
+
+FRAMEWORK_EXPORT void *bundle_getHandle(bundle_pt bundle);
+
+FRAMEWORK_EXPORT void bundle_setHandle(bundle_pt bundle, void *handle);
+
+FRAMEWORK_EXPORT activator_pt bundle_getActivator(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_setActivator(bundle_pt bundle, 
activator_pt activator);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getContext(bundle_pt bundle, 
bundle_context_pt *context);
+
+FRAMEWORK_EXPORT celix_status_t bundle_setContext(bundle_pt bundle, 
bundle_context_pt context);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getEntry(bundle_pt bundle, const char 
*name, char **entry);
+
+FRAMEWORK_EXPORT celix_status_t bundle_start(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_startWithOptions(bundle_pt bundle, int 
options);
+
+FRAMEWORK_EXPORT celix_status_t bundle_update(bundle_pt bundle, const char 
*inputFile);
+
+FRAMEWORK_EXPORT celix_status_t bundle_stop(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_stopWithOptions(bundle_pt bundle, int 
options);
+
+FRAMEWORK_EXPORT celix_status_t bundle_uninstall(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_setState(bundle_pt bundle, 
bundle_state_e state);
+
+FRAMEWORK_EXPORT celix_status_t bundle_setPersistentStateInactive(bundle_pt 
bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_setPersistentStateUninstalled(bundle_pt 
bundle);
+
+FRAMEWORK_EXPORT void uninstallBundle(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_revise(bundle_pt bundle, const char 
*location, const char *inputFile);
+
+FRAMEWORK_EXPORT celix_status_t bundle_addModule(bundle_pt bundle, module_pt 
module);
+
+FRAMEWORK_EXPORT celix_status_t bundle_closeModules(bundle_pt bundle);
+
+// Service Reference Functions
+FRAMEWORK_EXPORT array_list_pt getUsingBundles(service_reference_pt reference);
+
+FRAMEWORK_EXPORT int compareTo(service_reference_pt a, service_reference_pt b);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getState(bundle_pt bundle, 
bundle_state_e *state);
+
+FRAMEWORK_EXPORT celix_status_t bundle_isLockable(bundle_pt bundle, bool 
*lockable);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getLockingThread(bundle_pt bundle, 
celix_thread_t *thread);
+
+FRAMEWORK_EXPORT celix_status_t bundle_lock(bundle_pt bundle, bool *locked);
+
+FRAMEWORK_EXPORT celix_status_t bundle_unlock(bundle_pt bundle, bool 
*unlocked);
+
+FRAMEWORK_EXPORT celix_status_t bundle_closeAndDelete(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_close(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_refresh(bundle_pt bundle);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getBundleId(bundle_pt bundle, long *id);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getRegisteredServices(bundle_pt bundle, 
array_list_pt *list);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getServicesInUse(bundle_pt bundle, 
array_list_pt *list);
+
+FRAMEWORK_EXPORT celix_status_t bundle_setFramework(bundle_pt bundle, 
framework_pt framework);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getFramework(bundle_pt bundle, 
framework_pt *framework);
+
+FRAMEWORK_EXPORT celix_status_t bundle_getBundleLocation(bundle_pt bundle, 
const char **location);
+
+
+
+/**********************************************************************************************************************
+ 
**********************************************************************************************************************
+ * Updated API
+ 
**********************************************************************************************************************
+ 
**********************************************************************************************************************/
+
+long celix_bundle_getId(const bundle_t *bnd);
+
+celix_bundle_state_e celix_bundle_getState(const bundle_t *bnd);
+
+/**
+ * Note returned string pointer is owned by the caller.
+ * @param bnd
+ * @param relPath
+ * @return
+ */
+char* celix_bundle_getEntry(const bundle_t *bnd, const char *relPath);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CELIX_BUNDLE_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/include/celix_constants.h
----------------------------------------------------------------------
diff --git a/framework/include/celix_constants.h 
b/framework/include/celix_constants.h
new file mode 100644
index 0000000..d46c8fb
--- /dev/null
+++ b/framework/include/celix_constants.h
@@ -0,0 +1,79 @@
+/**
+ *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.
+ */
+/*
+ * constants.h
+ *
+ *  \date       Apr 29, 2010
+ *  \author            <a href="mailto:[email protected]";>Apache Celix 
Project Team</a>
+ *  \copyright Apache License, Version 2.0
+ */
+
+#ifndef CELIX_CONSTANTS_H_
+#define CELIX_CONSTANTS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define OSGI_FRAMEWORK_OBJECTCLASS "objectClass"
+#define OSGI_FRAMEWORK_SERVICE_NAME "objectClass" //TODO rename in future?
+#define OSGI_FRAMEWORK_SERVICE_ID "service.id"
+#define OSGI_FRAMEWORK_SERVICE_PID "service.pid"
+#define OSGI_FRAMEWORK_SERVICE_RANKING "service.ranking"
+
+#define CELIX_FRAMEWORK_SERVICE_VERSION "service.version"
+#define CELIX_FRAMEWORK_SERVICE_LANGUAGE "service.lang"
+#define CELIX_FRAMEWORK_SERVICE_C_LANGUAGE "C"
+#define CELIX_FRAMEWORK_SERVICE_CXX_LANGUAGE "C++"
+#define CELIX_FRAMEWORK_SERVICE_SHARED_LANGUAGE "shared" //e.g. marker services
+
+#define OSGI_FRAMEWORK_BUNDLE_ACTIVATOR "Bundle-Activator"
+#define OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_CREATE "bundleActivator_create"
+#define OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_START "bundleActivator_start"
+#define OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_STOP "bundleActivator_stop"
+#define OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_DESTROY "bundleActivator_destroy"
+
+#define OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_CREATE "dm_create"
+#define OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_INIT "dm_init"
+#define OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_DESTROY "dm_destroy"
+
+#define OSGI_FRAMEWORK_BUNDLE_SYMBOLICNAME "Bundle-SymbolicName"
+#define OSGI_FRAMEWORK_BUNDLE_VERSION "Bundle-Version"
+#define OSGI_FRAMEWORK_PRIVATE_LIBRARY "Private-Library"
+#define OSGI_FRAMEWORK_EXPORT_LIBRARY "Export-Library"
+#define OSGI_FRAMEWORK_IMPORT_LIBRARY "Import-Library"
+    
+#define OSGI_FRAMEWORK_FRAMEWORK_STORAGE "org.osgi.framework.storage"
+#define OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN 
"org.osgi.framework.storage.clean"
+#define OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT "onFirstInit"
+#define OSGI_FRAMEWORK_FRAMEWORK_UUID "org.osgi.framework.uuid"
+
+#define CELIX_AUTO_START_0 "CELIX_AUTO_START_0"
+#define CELIX_AUTO_START_1 "CELIX_AUTO_START_1"
+#define CELIX_AUTO_START_2 "CELIX_AUTO_START_2"
+#define CELIX_AUTO_START_3 "CELIX_AUTO_START_3"
+#define CELIX_AUTO_START_4 "CELIX_AUTO_START_4"
+#define CELIX_AUTO_START_5 "CELIX_AUTO_START_5"
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CONSTANTS_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/include/celix_launcher.h
----------------------------------------------------------------------
diff --git a/framework/include/celix_launcher.h 
b/framework/include/celix_launcher.h
index 579eef7..8675c73 100644
--- a/framework/include/celix_launcher.h
+++ b/framework/include/celix_launcher.h
@@ -24,8 +24,8 @@
  *  \copyright Apache License, Version 2.0
  */
 
-#ifndef CELIX_LAUNCHER_H
-#define CELIX_LAUNCHER_H
+#ifndef CELIX_LAUNCHER_H_
+#define CELIX_LAUNCHER_H_
 
 #include <stdio.h>
 #include "framework.h"
@@ -113,4 +113,4 @@ void celixLauncher_destroy(framework_t *framework);
 }
 #endif
 
-#endif //CELIX_LAUNCHER_H
+#endif //CELIX_LAUNCHER_H_

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/include/constants.h
----------------------------------------------------------------------
diff --git a/framework/include/constants.h b/framework/include/constants.h
index 06d89be..ac00241 100644
--- a/framework/include/constants.h
+++ b/framework/include/constants.h
@@ -16,64 +16,5 @@
  *specific language governing permissions and limitations
  *under the License.
  */
-/*
- * constants.h
- *
- *  \date       Apr 29, 2010
- *  \author            <a href="mailto:[email protected]";>Apache Celix 
Project Team</a>
- *  \copyright Apache License, Version 2.0
- */
-
-#ifndef CONSTANTS_H_
-#define CONSTANTS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static const char *const OSGI_FRAMEWORK_OBJECTCLASS = "objectClass";
-static const char *const OSGI_FRAMEWORK_SERVICE_ID = "service.id";
-static const char *const OSGI_FRAMEWORK_SERVICE_PID = "service.pid";
-static const char *const OSGI_FRAMEWORK_SERVICE_RANKING = "service.ranking";
-
-static const char *const CELIX_FRAMEWORK_SERVICE_VERSION = "service.version";
-static const char *const CELIX_FRAMEWORK_SERVICE_LANGUAGE = "service.lang";
-static const char *const CELIX_FRAMEWORK_SERVICE_C_LANGUAGE = "C";
-static const char *const CELIX_FRAMEWORK_SERVICE_CXX_LANGUAGE = "C++";
-static const char *const CELIX_FRAMEWORK_SERVICE_SHARED_LANGUAGE = "shared"; 
//e.g. marker services
-
-static const char *const OSGI_FRAMEWORK_BUNDLE_ACTIVATOR = "Bundle-Activator";
-static const char *const OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_CREATE = 
"bundleActivator_create";
-static const char *const OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_START = 
"bundleActivator_start";
-static const char *const OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_STOP = 
"bundleActivator_stop";
-static const char *const OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_DESTROY = 
"bundleActivator_destroy";
-
-static const char *const OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_CREATE = 
"dm_create";
-static const char *const OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_INIT = "dm_init";
-static const char *const OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_DESTROY = 
"dm_destroy";
-
-
-static const char *const OSGI_FRAMEWORK_BUNDLE_SYMBOLICNAME = 
"Bundle-SymbolicName";
-static const char *const OSGI_FRAMEWORK_BUNDLE_VERSION = "Bundle-Version";
-static const char *const OSGI_FRAMEWORK_PRIVATE_LIBRARY = "Private-Library";
-static const char *const OSGI_FRAMEWORK_EXPORT_LIBRARY = "Export-Library";
-static const char *const OSGI_FRAMEWORK_IMPORT_LIBRARY = "Import-Library";
-
-static const char *const OSGI_FRAMEWORK_FRAMEWORK_STORAGE = 
"org.osgi.framework.storage";
-static const char *const OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN = 
"org.osgi.framework.storage.clean";
-static const char *const OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT = 
"onFirstInit";
-static const char *const OSGI_FRAMEWORK_FRAMEWORK_UUID = 
"org.osgi.framework.uuid";
-
-#define CELIX_AUTO_START_0 "CELIX_AUTO_START_0"
-#define CELIX_AUTO_START_1 "CELIX_AUTO_START_1"
-#define CELIX_AUTO_START_2 "CELIX_AUTO_START_2"
-#define CELIX_AUTO_START_3 "CELIX_AUTO_START_3"
-#define CELIX_AUTO_START_4 "CELIX_AUTO_START_4"
-#define CELIX_AUTO_START_5 "CELIX_AUTO_START_5"
-
-
-#ifdef __cplusplus
-}
-#endif
 
-#endif /* CONSTANTS_H_ */
+#include "celix_constants.h"

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/include/framework.h
----------------------------------------------------------------------
diff --git a/framework/include/framework.h b/framework/include/framework.h
index 5143f47..0b718af 100644
--- a/framework/include/framework.h
+++ b/framework/include/framework.h
@@ -27,10 +27,10 @@
 #ifndef FRAMEWORK_H_
 #define FRAMEWORK_H_
 
-typedef struct activator *activator_pt;
+typedef struct activator * activator_pt;
 typedef struct activator activator_t;
 
-typedef struct framework *framework_pt;
+typedef struct framework * framework_pt;
 typedef struct framework framework_t;
 
 #include "celix_errno.h"
@@ -43,7 +43,6 @@ typedef struct framework framework_t;
 extern "C" {
 #endif
 
-// #TODO: Move to FrameworkFactory according the OSGi Spec
 FRAMEWORK_EXPORT celix_status_t framework_create(framework_t **framework, 
properties_t *config);
 
 FRAMEWORK_EXPORT celix_status_t framework_start(framework_t *framework);
@@ -52,11 +51,15 @@ FRAMEWORK_EXPORT celix_status_t framework_stop(framework_t 
*framework);
 
 FRAMEWORK_EXPORT celix_status_t framework_destroy(framework_t *framework);
 
+FRAMEWORK_EXPORT const char* framework_getUUID(framework_t *framework);
+
+FRAMEWORK_EXPORT celix_status_t fw_init(framework_t *framework);
+
 FRAMEWORK_EXPORT celix_status_t framework_waitForStop(framework_t *framework);
 
-FRAMEWORK_EXPORT celix_status_t framework_getFrameworkBundle(framework_t 
*framework, bundle_t **bundle);
+FRAMEWORK_EXPORT celix_status_t framework_getFrameworkBundle(framework_t 
*framework, bundle_pt *bundle);
 
-bundle_context_t* framework_getContext(framework_t *framework);
+FRAMEWORK_EXPORT bundle_context_t* framework_getContext(framework_t 
*framework);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/include/service_reference.h
----------------------------------------------------------------------
diff --git a/framework/include/service_reference.h 
b/framework/include/service_reference.h
index 3d84526..18b5455 100644
--- a/framework/include/service_reference.h
+++ b/framework/include/service_reference.h
@@ -28,6 +28,7 @@
 #define SERVICE_REFERENCE_H_
 
 typedef struct serviceReference * service_reference_pt;
+typedef struct serviceReference service_reference_t;
 
 #include "celixbool.h"
 #include "array_list.h"

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/private/mock/bundle_context_mock.c
----------------------------------------------------------------------
diff --git a/framework/private/mock/bundle_context_mock.c 
b/framework/private/mock/bundle_context_mock.c
index 67bf3be..e32f5e1 100644
--- a/framework/private/mock/bundle_context_mock.c
+++ b/framework/private/mock/bundle_context_mock.c
@@ -276,7 +276,7 @@ void celix_bundleContext_useBundles(
 }
 
 
-void celix_bundleContext_useBundle(
+bool celix_bundleContext_useBundle(
                bundle_context_t *ctx,
                long bundleId,
                void *callbackHandle,
@@ -286,6 +286,7 @@ void celix_bundleContext_useBundle(
                        ->withLongIntParameters("bundleId", bundleId)
                        ->withPointerParameters("callbackHandle", 
callbackHandle)
                        ->withPointerParameters("use", use);
+       return mock_c()->returnValue().value.boolValue;
 }
 
 void celix_bundleContext_stopTracker(bundle_context_t *ctx, long trackerId) {

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/private/mock/bundle_mock.c
----------------------------------------------------------------------
diff --git a/framework/private/mock/bundle_mock.c 
b/framework/private/mock/bundle_mock.c
index 8ab5068..b842ffb 100644
--- a/framework/private/mock/bundle_mock.c
+++ b/framework/private/mock/bundle_mock.c
@@ -291,4 +291,18 @@ celix_bundle_state_e celix_bundle_getState(const bundle_t 
*bnd) {
 }
 
 
+celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char 
**location) {
+       mock_c()->actualCall("bundle_getBundleLocation")
+                       ->withPointerParameters("bundle", bundle)
+                       ->withOutputParameter("location", location);
+       return mock_c()->returnValue().value.intValue;
+}
+
+
+celix_status_t bundle_getBundleCache(bundle_pt bundle, const char **cache) {
+       mock_c()->actualCall("bundle_getBundleCache")
+                       ->withPointerParameters("bundle", bundle)
+                       ->withOutputParameter("cache", cache);
+       return mock_c()->returnValue().value.intValue;
+}
 

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/src/BundleImpl.c
----------------------------------------------------------------------
diff --git a/framework/src/BundleImpl.c b/framework/src/BundleImpl.c
new file mode 100644
index 0000000..fccabae
--- /dev/null
+++ b/framework/src/BundleImpl.c
@@ -0,0 +1,771 @@
+/**
+ *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.c
+ *
+ *  \date       Mar 23, 2010
+ *  \author            <a href="mailto:[email protected]";>Apache Celix 
Project Team</a>
+ *  \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "framework_private.h"
+#include "bundle_private.h"
+#include "resolver.h"
+#include "utils.h"
+
+celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module);
+celix_status_t bundle_closeRevisions(bundle_pt bundle);
+
+celix_status_t bundle_create(bundle_pt * bundle) {
+    celix_status_t status;
+    bundle_archive_pt archive = NULL;
+
+       *bundle = (bundle_pt) malloc(sizeof(**bundle));
+       if (*bundle == NULL) {
+               return CELIX_ENOMEM;
+       }
+       status = bundleArchive_createSystemBundleArchive(&archive);
+       if (status == CELIX_SUCCESS) {
+        module_pt module;
+
+        (*bundle)->archive = archive;
+        (*bundle)->activator = NULL;
+        (*bundle)->context = NULL;
+        (*bundle)->framework = NULL;
+        (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
+        (*bundle)->modules = NULL;
+        arrayList_create(&(*bundle)->modules);
+        (*bundle)->handle = NULL;
+        (*bundle)->manifest = NULL;
+
+        module = module_createFrameworkModule((*bundle));
+        bundle_addModule(*bundle, module);
+
+        status = celixThreadMutex_create(&(*bundle)->lock, NULL);
+        if (status != CELIX_SUCCESS) {
+               status = CELIX_ILLEGAL_STATE;
+        } else {
+                       (*bundle)->lockCount = 0;
+                       (*bundle)->lockThread = celix_thread_default;
+        }
+       }
+       framework_logIfError(logger, status, NULL, "Failed to create bundle");
+
+       return status;
+}
+
+celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt 
framework, bundle_archive_pt archive) {
+    module_pt module;
+       
+       celix_status_t status;
+
+       *bundle = (bundle_pt) malloc(sizeof(**bundle));
+       if (*bundle == NULL) {
+               return CELIX_ENOMEM;
+       }
+       (*bundle)->archive = archive;
+       (*bundle)->activator = NULL;
+       (*bundle)->context = NULL;
+       (*bundle)->handle = NULL;
+       (*bundle)->manifest = NULL;
+       (*bundle)->framework = framework;
+       (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
+       (*bundle)->modules = NULL;
+       arrayList_create(&(*bundle)->modules);
+       
+       status = bundle_createModule(*bundle, &module);
+       if (status == CELIX_SUCCESS) {
+               bundle_addModule(*bundle, module);
+        status = celixThreadMutex_create(&(*bundle)->lock, NULL);
+        if (status != CELIX_SUCCESS) {
+                       status = CELIX_ILLEGAL_STATE;
+               } else {
+                       (*bundle)->lockCount = 0;
+                       (*bundle)->lockThread = celix_thread_default;
+               }
+       } else {
+           status = CELIX_FILE_IO_EXCEPTION;
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to create bundle");
+
+       return status;
+}
+
+celix_status_t bundle_destroy(bundle_pt bundle) {
+       array_list_iterator_pt iter = arrayListIterator_create(bundle->modules);
+       while (arrayListIterator_hasNext(iter)) {
+               module_pt module = arrayListIterator_next(iter);
+               module_destroy(module);
+       }
+       arrayListIterator_destroy(iter);
+       arrayList_destroy(bundle->modules);
+       celixThreadMutex_destroy(&bundle->lock);
+
+       free(bundle);
+
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundle_getArchive(bundle_pt bundle, bundle_archive_pt *archive) 
{
+       celix_status_t status = CELIX_SUCCESS;
+
+       if (bundle != NULL && *archive == NULL) {
+               *archive = bundle->archive;
+       } else {
+               status = CELIX_ILLEGAL_ARGUMENT;
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to get bundle 
archive");
+
+       return status;
+}
+
+celix_status_t bundle_getCurrentModule(bundle_pt bundle, module_pt *module) {
+       celix_status_t status = CELIX_SUCCESS;
+
+       if (bundle == NULL || arrayList_size(bundle->modules)==0 ) {
+               status = CELIX_ILLEGAL_ARGUMENT;
+       } else {
+               *module = arrayList_get(bundle->modules, 
arrayList_size(bundle->modules) - 1);
+       }
+
+       return status;
+}
+
+array_list_pt bundle_getModules(bundle_pt bundle) {
+    return bundle->modules;
+}
+
+void * bundle_getHandle(bundle_pt bundle) {
+       return bundle->handle;
+}
+
+void bundle_setHandle(bundle_pt bundle, void * handle) {
+       bundle->handle = handle;
+}
+
+activator_pt bundle_getActivator(bundle_pt bundle) {
+       return bundle->activator;
+}
+
+celix_status_t bundle_setActivator(bundle_pt bundle, activator_pt activator) {
+       bundle->activator = activator;
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundle_getContext(bundle_pt bundle, bundle_context_pt *context) 
{
+       *context = bundle->context;
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundle_setContext(bundle_pt bundle, bundle_context_pt context) {
+       bundle->context = context;
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundle_getEntry(bundle_pt bundle, const char* name, char** out) 
{
+       char *entry = celix_bundle_getEntry(bundle, name);
+       if (out != NULL ) {
+               *out = entry;
+       }
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundle_getState(bundle_pt bundle, bundle_state_e *state) {
+       if(bundle==NULL){
+               *state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
+               return CELIX_BUNDLE_EXCEPTION;
+       }
+       *state = bundle->state;
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) {
+       bundle->state = state;
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) {
+       celix_status_t status = CELIX_SUCCESS;
+       bundle_archive_pt archive = NULL;
+       bundle_revision_pt revision = NULL;
+       manifest_pt headerMap = NULL;
+
+       status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
+       status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, 
&revision));
+       status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, 
&headerMap));
+       if (status == CELIX_SUCCESS) {
+               long bundleId = 0;
+        status = bundleArchive_getId(bundle->archive, &bundleId);
+        if (status == CELIX_SUCCESS) {
+                       int revision = 0;
+                       char moduleId[512];
+
+                       snprintf(moduleId, sizeof(moduleId), "%ld.%d", 
bundleId, revision);
+                       *module = module_create(headerMap, moduleId, bundle);
+
+                       if (*module != NULL) {
+                               version_pt bundleVersion = 
module_getVersion(*module);
+                               const char * symName = NULL;
+                               status = module_getSymbolicName(*module, 
&symName);
+                               if (status == CELIX_SUCCESS) {
+                                       array_list_pt bundles = 
framework_getBundles(bundle->framework);
+                                       unsigned int i;
+                                       for (i = 0; i < 
arrayList_size(bundles); i++) {
+                                               bundle_pt check = (bundle_pt) 
arrayList_get(bundles, i);
+
+                                               long id;
+                                               if 
(bundleArchive_getId(check->archive, &id) == CELIX_SUCCESS) {
+                                                       if (id != bundleId) {
+                                                               module_pt mod = 
NULL;
+                                                               const char * 
sym = NULL;
+                                                               version_pt 
version;
+                                                               int cmp;
+                                                               status = 
bundle_getCurrentModule(check, &mod);
+                                                               status = 
module_getSymbolicName(mod, &sym);
+
+                                                               version = 
module_getVersion(mod);
+                                                               
version_compareTo(bundleVersion, version, &cmp);
+                                                               if ((symName != 
NULL) && (sym != NULL) && !strcmp(symName, sym) &&
+                                                                               
!cmp) {
+                                                                       char 
*versionString = NULL;
+                                                                       
version_toString(version, &versionString);
+                                                                       
printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, 
versionString);
+                                                                       
free(versionString);
+                                                                       status 
= CELIX_BUNDLE_EXCEPTION;
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                                       arrayList_destroy(bundles);
+                               }
+                       }
+        }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to create module");
+
+       return status;
+}
+
+celix_status_t bundle_start(bundle_pt bundle) {
+       return bundle_startWithOptions(bundle, 0);
+}
+
+celix_status_t bundle_startWithOptions(bundle_pt bundle, int options) {
+       celix_status_t status = CELIX_SUCCESS;
+    if (bundle != NULL) {
+       bool systemBundle = false;
+       status = bundle_isSystemBundle(bundle, &systemBundle);
+       if (status == CELIX_SUCCESS) {
+               if (systemBundle) {
+                       framework_start(bundle->framework);
+               } else {
+                       status = fw_startBundle(bundle->framework, bundle, 
options);
+               }
+       }
+    }
+
+       framework_logIfError(logger, status, NULL, "Failed to start bundle");
+
+    return status;
+}
+
+celix_status_t bundle_update(bundle_pt bundle, const char *inputFile) {
+       celix_status_t status = CELIX_SUCCESS;
+       if (bundle != NULL) {
+               bool systemBundle = false;
+               status = bundle_isSystemBundle(bundle, &systemBundle);
+               if (status == CELIX_SUCCESS) {
+                       if (systemBundle) {
+                               // #TODO: Support framework update
+                               status = CELIX_BUNDLE_EXCEPTION;
+                       } else {
+                               status = 
framework_updateBundle(bundle->framework, bundle, inputFile);
+                       }
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to update bundle");
+
+       return status;
+}
+
+celix_status_t bundle_stop(bundle_pt bundle) {
+       return bundle_stopWithOptions(bundle, 0);
+}
+
+celix_status_t bundle_stopWithOptions(bundle_pt bundle, int options) {
+       celix_status_t status = CELIX_SUCCESS;
+       if (bundle != NULL) {
+               bool systemBundle = false;
+               status = bundle_isSystemBundle(bundle, &systemBundle);
+               if (status == CELIX_SUCCESS) {
+                       if (systemBundle) {
+                               framework_stop(bundle->framework);
+                       } else {
+                               status = fw_stopBundle(bundle->framework, 
bundle, options);
+                       }
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to stop bundle");
+
+       return status;
+}
+
+celix_status_t bundle_uninstall(bundle_pt bundle) {
+       celix_status_t status = CELIX_SUCCESS;
+       if (bundle != NULL) {
+               bool systemBundle = false;
+               status = bundle_isSystemBundle(bundle, &systemBundle);
+               if (status == CELIX_SUCCESS) {
+                       if (systemBundle) {
+                               status = CELIX_BUNDLE_EXCEPTION;
+                       } else {
+                               status = fw_uninstallBundle(bundle->framework, 
bundle);
+                       }
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to uninstall 
bundle");
+
+       return status;
+}
+
+celix_status_t bundle_setPersistentStateInactive(bundle_pt bundle) {
+       celix_status_t status;
+       bool systemBundle;
+
+       status = bundle_isSystemBundle(bundle, &systemBundle);
+       if (status == CELIX_SUCCESS) {
+               if (!systemBundle) {
+                       status = 
bundleArchive_setPersistentState(bundle->archive, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED);
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to set persistent 
state to inactive");
+
+       return status;
+}
+
+celix_status_t bundle_setPersistentStateUninstalled(bundle_pt bundle) {
+       celix_status_t status;
+       bool systemBundle;
+
+       status = bundle_isSystemBundle(bundle, &systemBundle);
+       if (status == CELIX_SUCCESS) {
+               if (!systemBundle) {
+                       status = 
bundleArchive_setPersistentState(bundle->archive, 
OSGI_FRAMEWORK_BUNDLE_UNINSTALLED);
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to set persistent 
state to uninstalled");
+
+    return status;
+}
+
+celix_status_t bundle_revise(bundle_pt bundle, const char * location, const 
char *inputFile) {
+       celix_status_t status;
+
+       bundle_archive_pt archive = NULL;
+       status = bundle_getArchive(bundle, &archive);
+       if (status == CELIX_SUCCESS) {
+               status = bundleArchive_revise(archive, location, inputFile);
+               if (status == CELIX_SUCCESS) {
+                       module_pt module;
+                       status = bundle_createModule(bundle, &module);
+                       if (status == CELIX_SUCCESS) {
+                               status = bundle_addModule(bundle, module);
+                       } else {
+                               bool rolledback;
+                               status = bundleArchive_rollbackRevise(archive, 
&rolledback);
+                               if (status == CELIX_SUCCESS) {
+                                       status = CELIX_BUNDLE_EXCEPTION;
+                               }
+                       }
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to revise bundle");
+
+       return status;
+}
+
+//bool bundle_rollbackRevise(bundle_pt bundle) {
+//     module_pt module = arrayList_remove(bundle->modules, 
arrayList_set(bundle->modules) - 1);
+//     return resolver_removeModule(module);
+//}
+
+celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) {
+       arrayList_add(bundle->modules, module);
+       resolver_addModule(module);
+       return CELIX_SUCCESS;
+}
+
+celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool *systemBundle) {
+       celix_status_t status;
+       long bundleId;
+       bundle_archive_pt archive = NULL;
+
+       status = bundle_getArchive(bundle, &archive);
+       if (status == CELIX_SUCCESS) {
+               status = bundleArchive_getId(archive, &bundleId);
+               if (status == CELIX_SUCCESS) {
+                       *systemBundle = (bundleId == 0);
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to check if bundle 
is the systembundle");
+
+       return status;
+}
+
+celix_status_t bundle_isLockable(bundle_pt bundle, bool *lockable) {
+       celix_status_t status;
+
+       status = celixThreadMutex_lock(&bundle->lock);
+       if (status != CELIX_SUCCESS) {
+               status = CELIX_BUNDLE_EXCEPTION;
+       } else {
+               bool equals;
+               status = thread_equalsSelf(bundle->lockThread, &equals);
+               if (status == CELIX_SUCCESS) {
+                       *lockable = (bundle->lockCount == 0) || (equals);
+               }
+
+               status = celixThreadMutex_unlock(&bundle->lock);
+               if (status != CELIX_SUCCESS) {
+                       status = CELIX_BUNDLE_EXCEPTION;
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to check if bundle 
is lockable");
+
+       return status;
+}
+
+celix_status_t bundle_getLockingThread(bundle_pt bundle, celix_thread_t 
*thread) {
+       celix_status_t status;
+
+       status = celixThreadMutex_lock(&bundle->lock);
+       if (status != CELIX_SUCCESS) {
+               status = CELIX_BUNDLE_EXCEPTION;
+       } else {
+               *thread = bundle->lockThread;
+
+               status = celixThreadMutex_unlock(&bundle->lock);
+               if (status != CELIX_SUCCESS) {
+                       status = CELIX_BUNDLE_EXCEPTION;
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to get locking 
thread");
+
+       return status;
+}
+
+celix_status_t bundle_lock(bundle_pt bundle, bool *locked) {
+       celix_status_t status;
+       bool equals;
+
+       celixThreadMutex_lock(&bundle->lock);
+
+       status = thread_equalsSelf(bundle->lockThread, &equals);
+       if (status == CELIX_SUCCESS) {
+               if ((bundle->lockCount > 0) && !equals) {
+                       *locked = false;
+               } else {
+                       bundle->lockCount++;
+                       bundle->lockThread = celixThread_self();
+                       *locked = true;
+               }
+       }
+
+       celixThreadMutex_unlock(&bundle->lock);
+
+       framework_logIfError(logger, status, NULL, "Failed to lock bundle");
+
+       return status;
+}
+
+celix_status_t bundle_unlock(bundle_pt bundle, bool *unlocked) {
+       celix_status_t status = CELIX_SUCCESS;
+
+       bool equals;
+
+       celixThreadMutex_lock(&bundle->lock);
+
+       if (bundle->lockCount == 0) {
+               *unlocked = false;
+       } else {
+               status = thread_equalsSelf(bundle->lockThread, &equals);
+               if (status == CELIX_SUCCESS) {
+                       if ((bundle->lockCount > 0) && !equals) {
+                               *unlocked = false;
+                       }
+                       else{
+                          bundle->lockCount--;
+                          if (bundle->lockCount == 0) {
+                               bundle->lockThread = celix_thread_default;
+                          }
+                          *unlocked = true;
+                  }
+          }
+       }
+
+       celixThreadMutex_unlock(&bundle->lock);
+
+       framework_logIfError(logger, status, NULL, "Failed to unlock bundle");
+
+       return status;
+}
+
+celix_status_t bundle_close(bundle_pt bundle) {
+       bundle_archive_pt archive = NULL;
+       
+       celix_status_t status;
+
+    bundle_closeModules(bundle);
+    bundle_closeRevisions(bundle);
+    status = bundle_getArchive(bundle, &archive);
+    if (status == CELIX_SUCCESS) {
+               bundleArchive_close(archive);
+    }
+
+       framework_logIfError(logger, status, NULL, "Failed to close bundle");
+
+    return status;
+}
+
+celix_status_t bundle_closeAndDelete(bundle_pt bundle) {
+       celix_status_t status;
+
+       bundle_archive_pt archive = NULL;
+
+    bundle_closeModules(bundle);
+    bundle_closeRevisions(bundle);
+    status = bundle_getArchive(bundle, &archive);
+    if (status == CELIX_SUCCESS) {
+       bundleArchive_closeAndDelete(archive);
+    }
+
+       framework_logIfError(logger, status, NULL, "Failed to close and delete 
bundle");
+
+    return status;
+}
+
+celix_status_t bundle_closeRevisions(bundle_pt bundle) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    // TODO implement this
+    return status;
+}
+
+celix_status_t bundle_closeModules(bundle_pt bundle) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    unsigned int i = 0;
+    for (i = 0; i < arrayList_size(bundle->modules); i++) {
+        module_pt module = (module_pt) arrayList_get(bundle->modules, i);
+        resolver_removeModule(module);
+        module_setWires(module, NULL);
+    }
+
+    return status;
+}
+
+celix_status_t bundle_refresh(bundle_pt bundle) {
+       celix_status_t status;
+       module_pt module;
+
+       status = bundle_closeModules(bundle);
+       if (status == CELIX_SUCCESS) {
+               arrayList_clear(bundle->modules);
+               status = bundle_createModule(bundle, &module);
+               if (status == CELIX_SUCCESS) {
+                       status = bundle_addModule(bundle, module);
+                       if (status == CELIX_SUCCESS) {
+                               bundle->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
+                       }
+               }
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to refresh bundle");
+
+    return status;
+}
+
+celix_status_t bundle_getBundleId(bundle_t *bundle, long *bndId) {
+       celix_status_t status = CELIX_SUCCESS;
+       long id = celix_bundle_getId(bundle);
+       if (id >= 0) {
+               *bndId = id;
+       } else {
+               status = CELIX_BUNDLE_EXCEPTION;
+               *bndId = -1;
+       }
+       return status;
+}
+
+celix_status_t bundle_getRegisteredServices(bundle_pt bundle, array_list_pt 
*list) {
+       celix_status_t status;
+
+       status = fw_getBundleRegisteredServices(bundle->framework, bundle, 
list);
+
+       framework_logIfError(bundle->framework->logger, status, NULL, "Failed 
to get registered services");
+
+       return status;
+}
+
+celix_status_t bundle_getServicesInUse(bundle_pt bundle, array_list_pt *list) {
+       celix_status_t status;
+
+       status = fw_getBundleServicesInUse(bundle->framework, bundle, list);
+
+       framework_logIfError(logger, status, NULL, "Failed to get in use 
services");
+
+       return status;
+}
+
+celix_status_t bundle_setFramework(bundle_pt bundle, framework_pt framework) {
+       celix_status_t status = CELIX_SUCCESS;
+
+       if (bundle != NULL && framework != NULL) {
+               bundle->framework = framework;
+       } else {
+               status = CELIX_ILLEGAL_ARGUMENT;
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to set framework");
+
+       return status;
+}
+
+celix_status_t bundle_getFramework(bundle_pt bundle, framework_pt *framework) {
+       celix_status_t status = CELIX_SUCCESS;
+
+       if (bundle != NULL && *framework == NULL) {
+               *framework = bundle->framework;
+       } else {
+               status = CELIX_ILLEGAL_ARGUMENT;
+       }
+
+       framework_logIfError(logger, status, NULL, "Failed to get framework");
+
+       return status;
+}
+
+celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char 
**location){
+       celix_status_t status;
+
+       bundle_archive_pt archive = NULL;
+
+       status = bundle_getArchive(bundle, &archive);
+       if (status != CELIX_SUCCESS){
+               printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchive) 
\n");
+               return status;
+       }
+
+       status =  bundleArchive_getLocation(archive, location);
+       if (status != CELIX_SUCCESS){
+               printf("[ ERROR ]:  Bundle - getBundleLocation 
(BundleArchiveLocation) \n");
+               return status;
+       }
+
+       return CELIX_SUCCESS;
+}
+
+
+celix_status_t bundle_getBundleCache(bundle_pt bundle, const char **out) {
+    celix_status_t status;
+    
+    const char *cache = NULL;
+    bundle_archive_pt archive = NULL;
+    bundle_revision_pt rev = NULL;
+    
+    status = bundle_getArchive(bundle, &archive);
+    if (status != CELIX_SUCCESS){
+        printf("[ ERROR ]: Bundle - bundle_getBundleCache (BundleArchive) \n");
+        return status;
+    }
+    
+    status = bundleArchive_getCurrentRevision(archive, &rev);
+    if (status != CELIX_SUCCESS){
+        printf("[ ERROR ]:  Bundle - bundle_getBundleCache 
(BundleArchiveRevision) \n");
+        return status;
+    }
+    
+    status = bundleRevision_getRoot(rev, &cache);
+    if (status != CELIX_SUCCESS){
+        printf("[ ERROR ]:  Bundle - bundle_getBundleCache 
(BundleArchiveRevision) \n");
+        return status;
+    }
+    
+    if (out != NULL) {
+        *out = cache;
+    }
+    
+    return CELIX_SUCCESS;
+}
+
+
+
+
+/**********************************************************************************************************************
+ 
**********************************************************************************************************************
+ * Updated API
+ 
**********************************************************************************************************************
+ 
**********************************************************************************************************************/
+
+long celix_bundle_getId(const bundle_t* bnd) {
+       long bndId = -1;
+       bundle_archive_pt archive = NULL;
+       if (bnd != NULL) {
+               bundle_getArchive((bundle_t *) bnd, &archive);
+       }
+       if (archive != NULL) {
+               bundleArchive_getId(archive, &bndId);
+       }
+       if (bndId < 0) {
+               framework_logIfError(logger, CELIX_BUNDLE_EXCEPTION, NULL, 
"Failed to get bundle id");
+       }
+       return bndId;
+}
+
+celix_bundle_state_e celix_bundle_getState(const bundle_t *bnd) {
+       celix_bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
+       if (bnd != NULL) {
+               state = bnd->state;
+       }
+       return state;
+}
+
+char* celix_bundle_getEntry(const bundle_t *bnd, const char *relPath) {
+       char *entry = NULL;
+       if (bnd != NULL) {
+               framework_getBundleEntry(bnd->framework, (bundle_t*)bnd, 
relPath, &entry);
+       }
+       return entry;
+}
+

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/src/bundle.c
----------------------------------------------------------------------
diff --git a/framework/src/bundle.c b/framework/src/bundle.c
deleted file mode 100644
index 5feb729..0000000
--- a/framework/src/bundle.c
+++ /dev/null
@@ -1,723 +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.c
- *
- *  \date       Mar 23, 2010
- *  \author            <a href="mailto:[email protected]";>Apache Celix 
Project Team</a>
- *  \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <string.h>
-
-#include "framework_private.h"
-#include "bundle_private.h"
-#include "resolver.h"
-#include "utils.h"
-
-celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module);
-celix_status_t bundle_closeRevisions(bundle_pt bundle);
-
-celix_status_t bundle_create(bundle_pt * bundle) {
-    celix_status_t status;
-    bundle_archive_pt archive = NULL;
-
-       *bundle = (bundle_pt) malloc(sizeof(**bundle));
-       if (*bundle == NULL) {
-               return CELIX_ENOMEM;
-       }
-       status = bundleArchive_createSystemBundleArchive(&archive);
-       if (status == CELIX_SUCCESS) {
-        module_pt module;
-
-        (*bundle)->archive = archive;
-        (*bundle)->activator = NULL;
-        (*bundle)->context = NULL;
-        (*bundle)->framework = NULL;
-        (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
-        (*bundle)->modules = NULL;
-        arrayList_create(&(*bundle)->modules);
-        (*bundle)->handle = NULL;
-        (*bundle)->manifest = NULL;
-
-        module = module_createFrameworkModule((*bundle));
-        bundle_addModule(*bundle, module);
-
-        status = celixThreadMutex_create(&(*bundle)->lock, NULL);
-        if (status != CELIX_SUCCESS) {
-               status = CELIX_ILLEGAL_STATE;
-        } else {
-                       (*bundle)->lockCount = 0;
-                       (*bundle)->lockThread = celix_thread_default;
-        }
-       }
-       framework_logIfError(logger, status, NULL, "Failed to create bundle");
-
-       return status;
-}
-
-celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt 
framework, bundle_archive_pt archive) {
-    module_pt module;
-       
-       celix_status_t status;
-
-       *bundle = (bundle_pt) malloc(sizeof(**bundle));
-       if (*bundle == NULL) {
-               return CELIX_ENOMEM;
-       }
-       (*bundle)->archive = archive;
-       (*bundle)->activator = NULL;
-       (*bundle)->context = NULL;
-       (*bundle)->handle = NULL;
-       (*bundle)->manifest = NULL;
-       (*bundle)->framework = framework;
-       (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
-       (*bundle)->modules = NULL;
-       arrayList_create(&(*bundle)->modules);
-       
-       status = bundle_createModule(*bundle, &module);
-       if (status == CELIX_SUCCESS) {
-               bundle_addModule(*bundle, module);
-        status = celixThreadMutex_create(&(*bundle)->lock, NULL);
-        if (status != CELIX_SUCCESS) {
-                       status = CELIX_ILLEGAL_STATE;
-               } else {
-                       (*bundle)->lockCount = 0;
-                       (*bundle)->lockThread = celix_thread_default;
-               }
-       } else {
-           status = CELIX_FILE_IO_EXCEPTION;
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to create bundle");
-
-       return status;
-}
-
-celix_status_t bundle_destroy(bundle_pt bundle) {
-       array_list_iterator_pt iter = arrayListIterator_create(bundle->modules);
-       while (arrayListIterator_hasNext(iter)) {
-               module_pt module = arrayListIterator_next(iter);
-               module_destroy(module);
-       }
-       arrayListIterator_destroy(iter);
-       arrayList_destroy(bundle->modules);
-       celixThreadMutex_destroy(&bundle->lock);
-
-       free(bundle);
-
-       return CELIX_SUCCESS;
-}
-
-celix_status_t bundle_getArchive(bundle_pt bundle, bundle_archive_pt *archive) 
{
-       celix_status_t status = CELIX_SUCCESS;
-
-       if (bundle != NULL && *archive == NULL) {
-               *archive = bundle->archive;
-       } else {
-               status = CELIX_ILLEGAL_ARGUMENT;
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to get bundle 
archive");
-
-       return status;
-}
-
-celix_status_t bundle_getCurrentModule(bundle_pt bundle, module_pt *module) {
-       celix_status_t status = CELIX_SUCCESS;
-
-       if (bundle == NULL || arrayList_size(bundle->modules)==0 ) {
-               status = CELIX_ILLEGAL_ARGUMENT;
-       } else {
-               *module = arrayList_get(bundle->modules, 
arrayList_size(bundle->modules) - 1);
-       }
-
-       return status;
-}
-
-array_list_pt bundle_getModules(bundle_pt bundle) {
-    return bundle->modules;
-}
-
-void * bundle_getHandle(bundle_pt bundle) {
-       return bundle->handle;
-}
-
-void bundle_setHandle(bundle_pt bundle, void * handle) {
-       bundle->handle = handle;
-}
-
-activator_pt bundle_getActivator(bundle_pt bundle) {
-       return bundle->activator;
-}
-
-celix_status_t bundle_setActivator(bundle_pt bundle, activator_pt activator) {
-       bundle->activator = activator;
-       return CELIX_SUCCESS;
-}
-
-celix_status_t bundle_getContext(bundle_pt bundle, bundle_context_pt *context) 
{
-       *context = bundle->context;
-       return CELIX_SUCCESS;
-}
-
-celix_status_t bundle_setContext(bundle_pt bundle, bundle_context_pt context) {
-       bundle->context = context;
-       return CELIX_SUCCESS;
-}
-
-celix_status_t bundle_getEntry(bundle_pt bundle, const char* name, char** 
entry) {
-       return framework_getBundleEntry(bundle->framework, bundle, name, entry);
-}
-
-celix_status_t bundle_getState(bundle_pt bundle, bundle_state_e *state) {
-       if(bundle==NULL){
-               *state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
-               return CELIX_BUNDLE_EXCEPTION;
-       }
-       *state = bundle->state;
-       return CELIX_SUCCESS;
-}
-
-celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) {
-       bundle->state = state;
-       return CELIX_SUCCESS;
-}
-
-celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) {
-       celix_status_t status = CELIX_SUCCESS;
-       bundle_archive_pt archive = NULL;
-       bundle_revision_pt revision = NULL;
-       manifest_pt headerMap = NULL;
-
-       status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
-       status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, 
&revision));
-       status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, 
&headerMap));
-       if (status == CELIX_SUCCESS) {
-               long bundleId = 0;
-        status = bundleArchive_getId(bundle->archive, &bundleId);
-        if (status == CELIX_SUCCESS) {
-                       int revision = 0;
-                       char moduleId[512];
-
-                       snprintf(moduleId, sizeof(moduleId), "%ld.%d", 
bundleId, revision);
-                       *module = module_create(headerMap, moduleId, bundle);
-
-                       if (*module != NULL) {
-                               version_pt bundleVersion = 
module_getVersion(*module);
-                               const char * symName = NULL;
-                               status = module_getSymbolicName(*module, 
&symName);
-                               if (status == CELIX_SUCCESS) {
-                                       array_list_pt bundles = 
framework_getBundles(bundle->framework);
-                                       unsigned int i;
-                                       for (i = 0; i < 
arrayList_size(bundles); i++) {
-                                               bundle_pt check = (bundle_pt) 
arrayList_get(bundles, i);
-
-                                               long id;
-                                               if 
(bundleArchive_getId(check->archive, &id) == CELIX_SUCCESS) {
-                                                       if (id != bundleId) {
-                                                               module_pt mod = 
NULL;
-                                                               const char * 
sym = NULL;
-                                                               version_pt 
version;
-                                                               int cmp;
-                                                               status = 
bundle_getCurrentModule(check, &mod);
-                                                               status = 
module_getSymbolicName(mod, &sym);
-
-                                                               version = 
module_getVersion(mod);
-                                                               
version_compareTo(bundleVersion, version, &cmp);
-                                                               if ((symName != 
NULL) && (sym != NULL) && !strcmp(symName, sym) &&
-                                                                               
!cmp) {
-                                                                       char 
*versionString = NULL;
-                                                                       
version_toString(version, &versionString);
-                                                                       
printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, 
versionString);
-                                                                       
free(versionString);
-                                                                       status 
= CELIX_BUNDLE_EXCEPTION;
-                                                                       break;
-                                                               }
-                                                       }
-                                               }
-                                       }
-                                       arrayList_destroy(bundles);
-                               }
-                       }
-        }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to create module");
-
-       return status;
-}
-
-celix_status_t bundle_start(bundle_pt bundle) {
-       return bundle_startWithOptions(bundle, 0);
-}
-
-celix_status_t bundle_startWithOptions(bundle_pt bundle, int options) {
-       celix_status_t status = CELIX_SUCCESS;
-    if (bundle != NULL) {
-       bool systemBundle = false;
-       status = bundle_isSystemBundle(bundle, &systemBundle);
-       if (status == CELIX_SUCCESS) {
-               if (systemBundle) {
-                       framework_start(bundle->framework);
-               } else {
-                       status = fw_startBundle(bundle->framework, bundle, 
options);
-               }
-       }
-    }
-
-       framework_logIfError(logger, status, NULL, "Failed to start bundle");
-
-    return status;
-}
-
-celix_status_t bundle_update(bundle_pt bundle, const char *inputFile) {
-       celix_status_t status = CELIX_SUCCESS;
-       if (bundle != NULL) {
-               bool systemBundle = false;
-               status = bundle_isSystemBundle(bundle, &systemBundle);
-               if (status == CELIX_SUCCESS) {
-                       if (systemBundle) {
-                               // #TODO: Support framework update
-                               status = CELIX_BUNDLE_EXCEPTION;
-                       } else {
-                               status = 
framework_updateBundle(bundle->framework, bundle, inputFile);
-                       }
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to update bundle");
-
-       return status;
-}
-
-celix_status_t bundle_stop(bundle_pt bundle) {
-       return bundle_stopWithOptions(bundle, 0);
-}
-
-celix_status_t bundle_stopWithOptions(bundle_pt bundle, int options) {
-       celix_status_t status = CELIX_SUCCESS;
-       if (bundle != NULL) {
-               bool systemBundle = false;
-               status = bundle_isSystemBundle(bundle, &systemBundle);
-               if (status == CELIX_SUCCESS) {
-                       if (systemBundle) {
-                               framework_stop(bundle->framework);
-                       } else {
-                               status = fw_stopBundle(bundle->framework, 
bundle, options);
-                       }
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to stop bundle");
-
-       return status;
-}
-
-celix_status_t bundle_uninstall(bundle_pt bundle) {
-       celix_status_t status = CELIX_SUCCESS;
-       if (bundle != NULL) {
-               bool systemBundle = false;
-               status = bundle_isSystemBundle(bundle, &systemBundle);
-               if (status == CELIX_SUCCESS) {
-                       if (systemBundle) {
-                               status = CELIX_BUNDLE_EXCEPTION;
-                       } else {
-                               status = fw_uninstallBundle(bundle->framework, 
bundle);
-                       }
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to uninstall 
bundle");
-
-       return status;
-}
-
-celix_status_t bundle_setPersistentStateInactive(bundle_pt bundle) {
-       celix_status_t status;
-       bool systemBundle;
-
-       status = bundle_isSystemBundle(bundle, &systemBundle);
-       if (status == CELIX_SUCCESS) {
-               if (!systemBundle) {
-                       status = 
bundleArchive_setPersistentState(bundle->archive, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED);
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to set persistent 
state to inactive");
-
-       return status;
-}
-
-celix_status_t bundle_setPersistentStateUninstalled(bundle_pt bundle) {
-       celix_status_t status;
-       bool systemBundle;
-
-       status = bundle_isSystemBundle(bundle, &systemBundle);
-       if (status == CELIX_SUCCESS) {
-               if (!systemBundle) {
-                       status = 
bundleArchive_setPersistentState(bundle->archive, 
OSGI_FRAMEWORK_BUNDLE_UNINSTALLED);
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to set persistent 
state to uninstalled");
-
-    return status;
-}
-
-celix_status_t bundle_revise(bundle_pt bundle, const char * location, const 
char *inputFile) {
-       celix_status_t status;
-
-       bundle_archive_pt archive = NULL;
-       status = bundle_getArchive(bundle, &archive);
-       if (status == CELIX_SUCCESS) {
-               status = bundleArchive_revise(archive, location, inputFile);
-               if (status == CELIX_SUCCESS) {
-                       module_pt module;
-                       status = bundle_createModule(bundle, &module);
-                       if (status == CELIX_SUCCESS) {
-                               status = bundle_addModule(bundle, module);
-                       } else {
-                               bool rolledback;
-                               status = bundleArchive_rollbackRevise(archive, 
&rolledback);
-                               if (status == CELIX_SUCCESS) {
-                                       status = CELIX_BUNDLE_EXCEPTION;
-                               }
-                       }
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to revise bundle");
-
-       return status;
-}
-
-//bool bundle_rollbackRevise(bundle_pt bundle) {
-//     module_pt module = arrayList_remove(bundle->modules, 
arrayList_set(bundle->modules) - 1);
-//     return resolver_removeModule(module);
-//}
-
-celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) {
-       arrayList_add(bundle->modules, module);
-       resolver_addModule(module);
-       return CELIX_SUCCESS;
-}
-
-celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool *systemBundle) {
-       celix_status_t status;
-       long bundleId;
-       bundle_archive_pt archive = NULL;
-
-       status = bundle_getArchive(bundle, &archive);
-       if (status == CELIX_SUCCESS) {
-               status = bundleArchive_getId(archive, &bundleId);
-               if (status == CELIX_SUCCESS) {
-                       *systemBundle = (bundleId == 0);
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to check if bundle 
is the systembundle");
-
-       return status;
-}
-
-celix_status_t bundle_isLockable(bundle_pt bundle, bool *lockable) {
-       celix_status_t status;
-
-       status = celixThreadMutex_lock(&bundle->lock);
-       if (status != CELIX_SUCCESS) {
-               status = CELIX_BUNDLE_EXCEPTION;
-       } else {
-               bool equals;
-               status = thread_equalsSelf(bundle->lockThread, &equals);
-               if (status == CELIX_SUCCESS) {
-                       *lockable = (bundle->lockCount == 0) || (equals);
-               }
-
-               status = celixThreadMutex_unlock(&bundle->lock);
-               if (status != CELIX_SUCCESS) {
-                       status = CELIX_BUNDLE_EXCEPTION;
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to check if bundle 
is lockable");
-
-       return status;
-}
-
-celix_status_t bundle_getLockingThread(bundle_pt bundle, celix_thread_t 
*thread) {
-       celix_status_t status;
-
-       status = celixThreadMutex_lock(&bundle->lock);
-       if (status != CELIX_SUCCESS) {
-               status = CELIX_BUNDLE_EXCEPTION;
-       } else {
-               *thread = bundle->lockThread;
-
-               status = celixThreadMutex_unlock(&bundle->lock);
-               if (status != CELIX_SUCCESS) {
-                       status = CELIX_BUNDLE_EXCEPTION;
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to get locking 
thread");
-
-       return status;
-}
-
-celix_status_t bundle_lock(bundle_pt bundle, bool *locked) {
-       celix_status_t status;
-       bool equals;
-
-       celixThreadMutex_lock(&bundle->lock);
-
-       status = thread_equalsSelf(bundle->lockThread, &equals);
-       if (status == CELIX_SUCCESS) {
-               if ((bundle->lockCount > 0) && !equals) {
-                       *locked = false;
-               } else {
-                       bundle->lockCount++;
-                       bundle->lockThread = celixThread_self();
-                       *locked = true;
-               }
-       }
-
-       celixThreadMutex_unlock(&bundle->lock);
-
-       framework_logIfError(logger, status, NULL, "Failed to lock bundle");
-
-       return status;
-}
-
-celix_status_t bundle_unlock(bundle_pt bundle, bool *unlocked) {
-       celix_status_t status = CELIX_SUCCESS;
-
-       bool equals;
-
-       celixThreadMutex_lock(&bundle->lock);
-
-       if (bundle->lockCount == 0) {
-               *unlocked = false;
-       } else {
-               status = thread_equalsSelf(bundle->lockThread, &equals);
-               if (status == CELIX_SUCCESS) {
-                       if ((bundle->lockCount > 0) && !equals) {
-                               *unlocked = false;
-                       }
-                       else{
-                          bundle->lockCount--;
-                          if (bundle->lockCount == 0) {
-                               bundle->lockThread = celix_thread_default;
-                          }
-                          *unlocked = true;
-                  }
-          }
-       }
-
-       celixThreadMutex_unlock(&bundle->lock);
-
-       framework_logIfError(logger, status, NULL, "Failed to unlock bundle");
-
-       return status;
-}
-
-celix_status_t bundle_close(bundle_pt bundle) {
-       bundle_archive_pt archive = NULL;
-       
-       celix_status_t status;
-
-    bundle_closeModules(bundle);
-    bundle_closeRevisions(bundle);
-    status = bundle_getArchive(bundle, &archive);
-    if (status == CELIX_SUCCESS) {
-               bundleArchive_close(archive);
-    }
-
-       framework_logIfError(logger, status, NULL, "Failed to close bundle");
-
-    return status;
-}
-
-celix_status_t bundle_closeAndDelete(bundle_pt bundle) {
-       celix_status_t status;
-
-       bundle_archive_pt archive = NULL;
-
-    bundle_closeModules(bundle);
-    bundle_closeRevisions(bundle);
-    status = bundle_getArchive(bundle, &archive);
-    if (status == CELIX_SUCCESS) {
-       bundleArchive_closeAndDelete(archive);
-    }
-
-       framework_logIfError(logger, status, NULL, "Failed to close and delete 
bundle");
-
-    return status;
-}
-
-celix_status_t bundle_closeRevisions(bundle_pt bundle) {
-    celix_status_t status = CELIX_SUCCESS;
-
-    // TODO implement this
-    return status;
-}
-
-celix_status_t bundle_closeModules(bundle_pt bundle) {
-    celix_status_t status = CELIX_SUCCESS;
-
-    unsigned int i = 0;
-    for (i = 0; i < arrayList_size(bundle->modules); i++) {
-        module_pt module = (module_pt) arrayList_get(bundle->modules, i);
-        resolver_removeModule(module);
-        module_setWires(module, NULL);
-    }
-
-    return status;
-}
-
-celix_status_t bundle_refresh(bundle_pt bundle) {
-       celix_status_t status;
-       module_pt module;
-
-       status = bundle_closeModules(bundle);
-       if (status == CELIX_SUCCESS) {
-               arrayList_clear(bundle->modules);
-               status = bundle_createModule(bundle, &module);
-               if (status == CELIX_SUCCESS) {
-                       status = bundle_addModule(bundle, module);
-                       if (status == CELIX_SUCCESS) {
-                               bundle->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
-                       }
-               }
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to refresh bundle");
-
-    return status;
-}
-
-celix_status_t bundle_getBundleId(bundle_t *bundle, long *bndId) {
-       celix_status_t status = CELIX_SUCCESS;
-       long id = celix_bundle_getId(bundle);
-       if (id >= 0) {
-               *bndId = id;
-       } else {
-               status = CELIX_BUNDLE_EXCEPTION;
-               *bndId = -1;
-       }
-       return status;
-}
-
-celix_status_t bundle_getRegisteredServices(bundle_pt bundle, array_list_pt 
*list) {
-       celix_status_t status;
-
-       status = fw_getBundleRegisteredServices(bundle->framework, bundle, 
list);
-
-       framework_logIfError(bundle->framework->logger, status, NULL, "Failed 
to get registered services");
-
-       return status;
-}
-
-celix_status_t bundle_getServicesInUse(bundle_pt bundle, array_list_pt *list) {
-       celix_status_t status;
-
-       status = fw_getBundleServicesInUse(bundle->framework, bundle, list);
-
-       framework_logIfError(logger, status, NULL, "Failed to get in use 
services");
-
-       return status;
-}
-
-celix_status_t bundle_setFramework(bundle_pt bundle, framework_pt framework) {
-       celix_status_t status = CELIX_SUCCESS;
-
-       if (bundle != NULL && framework != NULL) {
-               bundle->framework = framework;
-       } else {
-               status = CELIX_ILLEGAL_ARGUMENT;
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to set framework");
-
-       return status;
-}
-
-celix_status_t bundle_getFramework(bundle_pt bundle, framework_pt *framework) {
-       celix_status_t status = CELIX_SUCCESS;
-
-       if (bundle != NULL && *framework == NULL) {
-               *framework = bundle->framework;
-       } else {
-               status = CELIX_ILLEGAL_ARGUMENT;
-       }
-
-       framework_logIfError(logger, status, NULL, "Failed to get framework");
-
-       return status;
-}
-
-celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char 
**location){
-
-       celix_status_t status;
-
-       bundle_archive_pt archive = NULL;
-
-       status = bundle_getArchive(bundle, &archive);
-       if (status != CELIX_SUCCESS){
-               printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchive) 
\n");
-               return status;
-       }
-
-       status =  bundleArchive_getLocation(archive, location);
-       if (status != CELIX_SUCCESS){
-               printf("[ ERROR ]:  Bundle - getBundleLocation 
(BundleArchiveLocation) \n");
-               return status;
-       }
-
-       return CELIX_SUCCESS;
-}
-
-
-
-
-
-
-/**********************************************************************************************************************
- 
**********************************************************************************************************************
- * Updated API
- 
**********************************************************************************************************************
- 
**********************************************************************************************************************/
-
-long celix_bundle_getId(const bundle_t* bnd) {
-       long bndId = -1;
-       bundle_archive_pt archive = NULL;
-       bundle_getArchive((bundle_t*)bnd, &archive);
-       if (archive != NULL) {
-               bundleArchive_getId(archive, &bndId);
-       }
-
-       if (bndId < 0) {
-               framework_logIfError(logger, CELIX_BUNDLE_EXCEPTION, NULL, 
"Failed to get bundle id");
-       }
-       return bndId;
-}
-
-celix_bundle_state_e celix_bundle_getState(const bundle_t *bnd) {
-       return bnd->state;
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/src/bundle_context.c
----------------------------------------------------------------------
diff --git a/framework/src/bundle_context.c b/framework/src/bundle_context.c
index b058d88..7e6b58f 100644
--- a/framework/src/bundle_context.c
+++ b/framework/src/bundle_context.c
@@ -583,12 +583,12 @@ void celix_bundleContext_useBundles(
     celix_framework_useBundles(ctx->framework, callbackHandle, use);
 }
 
-void celix_bundleContext_useBundle(
+bool celix_bundleContext_useBundle(
         bundle_context_t *ctx,
         long bundleId,
         void *callbackHandle,
         void (*use)(void *handle, const bundle_t *bundle)) {
-    celix_framework_useBundle(ctx->framework, bundleId, callbackHandle, use);
+    return celix_framework_useBundle(ctx->framework, bundleId, callbackHandle, 
use);
 }
 
 static void bundleContext_cleanupBundleTracker(bundle_context_t *ctx) {

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/src/framework.c b/framework/src/framework.c
index b6cb825..0566572 100644
--- a/framework/src/framework.c
+++ b/framework/src/framework.c
@@ -248,6 +248,10 @@ celix_status_t framework_create(framework_pt *framework, 
properties_pt config) {
             (*framework)->configurationMap = config;
             (*framework)->logger = logger;
 
+            //gen uuid
+            uuid_t uuid;
+            uuid_generate(uuid);
+            uuid_unparse(uuid, (*framework)->uuid);
 
             status = CELIX_DO_IF(status, bundle_create(&(*framework)->bundle));
             status = CELIX_DO_IF(status, 
arrayList_create(&(*framework)->globalLockWaitersList));
@@ -401,15 +405,7 @@ celix_status_t fw_init(framework_pt framework) {
        }
 
        if (status == CELIX_SUCCESS) {
-        /*create and store framework uuid*/
-        char uuid[37];
-
-           uuid_t uid;
-        uuid_generate(uid);
-        uuid_unparse(uid, uuid);
-
-        properties_set(framework->configurationMap, (char*) 
OSGI_FRAMEWORK_FRAMEWORK_UUID, uuid);
-
+        properties_set(framework->configurationMap, (char*) 
OSGI_FRAMEWORK_FRAMEWORK_UUID, framework->uuid);
         framework->installedBundleMap = hashMap_create(utils_stringHash, NULL, 
utils_stringEquals, NULL);
        }
 
@@ -507,6 +503,14 @@ celix_status_t fw_init(framework_pt framework) {
        return status;
 }
 
+FRAMEWORK_EXPORT const char* framework_getUUID(framework_t *framework) {
+    const char *uuid = NULL;
+    if (framework != NULL) {
+        uuid = framework->uuid;
+    }
+    return uuid;
+}
+
 celix_status_t framework_start(framework_pt framework) {
        celix_status_t status = CELIX_SUCCESS;
        bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
@@ -717,7 +721,7 @@ celix_status_t framework_getBundleEntry(framework_pt 
framework, bundle_pt bundle
         }
 
         if (access(e, F_OK) == 0) {
-            (*entry) = strndup(e, 1024*10);
+            (*entry) = strndup(e, 1024*1024*10);
         } else {
             (*entry) = NULL;
         }
@@ -2771,14 +2775,17 @@ void celix_framework_useBundles(framework_t *fw, void 
*callbackHandle, void(*use
     }
 }
 
-void celix_framework_useBundle(framework_t *fw, long bundleId, void 
*callbackHandle, void(*use)(void *handle, const bundle_t *bnd)) {
+bool celix_framework_useBundle(framework_t *fw, long bundleId, void 
*callbackHandle, void(*use)(void *handle, const bundle_t *bnd)) {
+    bool called = false;
     if (bundleId >= 0) {
         //TODO get bundle lock without throwing errors 
framework_acquireBundleLock() -> a more simple lock ??
         bundle_t *bnd = framework_getBundleById(fw, bundleId);
         celix_bundle_state_e bndState = celix_bundle_getState(bnd);
         if (bndState == OSGI_FRAMEWORK_BUNDLE_ACTIVE) {
             use(callbackHandle, bnd);
+            called = true;
         }
         //TODO unlock
     }
+    return called;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/framework/src/framework_private.h
----------------------------------------------------------------------
diff --git a/framework/src/framework_private.h 
b/framework/src/framework_private.h
index 66c1125..f10d024 100644
--- a/framework/src/framework_private.h
+++ b/framework/src/framework_private.h
@@ -48,9 +48,8 @@
 #include "celix_threads.h"
 
 struct framework {
-#ifdef WITH_APR
-    apr_pool_t *pool;
-#endif
+    char uuid[37];
+
     struct bundle * bundle;
     hash_map_pt installedBundleMap;
     hash_map_pt installRequestMap;
@@ -157,6 +156,6 @@ FRAMEWORK_EXPORT bundle_pt 
framework_getBundleById(framework_pt framework, long
  
**********************************************************************************************************************/
 
 void celix_framework_useBundles(framework_t *fw, void *callbackHandle, 
void(*use)(void *handle, const bundle_t *bnd));
-void celix_framework_useBundle(framework_t *fw, long bundleId, void 
*callbackHandle, void(*use)(void *handle, const bundle_t *bnd));
+bool celix_framework_useBundle(framework_t *fw, long bundleId, void 
*callbackHandle, void(*use)(void *handle, const bundle_t *bnd));
 
 #endif /* FRAMEWORK_PRIVATE_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt
index 622e0ee..c1afda7 100644
--- a/shell/CMakeLists.txt
+++ b/shell/CMakeLists.txt
@@ -23,7 +23,7 @@ if (SHELL)
                        $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
                        $<INSTALL_INTERFACE:include/celix/shell>
        )
-        install(TARGETS shell_api EXPORT celix COMPONENT shell)
+       install(TARGETS shell_api EXPORT celix COMPONENT shell)
        install(DIRECTORY include/ DESTINATION include/celix/shell COMPONENT 
shell)
 
     add_celix_bundle(shell

http://git-wip-us.apache.org/repos/asf/celix/blob/764bd7f7/utils/include/celix_exports.h
----------------------------------------------------------------------
diff --git a/utils/include/celix_exports.h b/utils/include/celix_exports.h
new file mode 100644
index 0000000..58b7abc
--- /dev/null
+++ b/utils/include/celix_exports.h
@@ -0,0 +1,25 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#ifndef CELIX_CELIX_EXPORTS_H
+#define CELIX_CELIX_EXPORTS_H
+
+#include "exports.h"
+
+#endif //CELIX_CELIX_EXPORTS_H

Reply via email to