Apache Celix  2.3.0
An implementation of the OSGi specification adapted to C and C++
Bundle.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #pragma once
21 
22 #include <memory>
23 
24 #include "celix_bundle.h"
25 
26 namespace celix {
27 
28  enum class BundleState {
29  UNKNOWN,
31  INSTALLED,
32  RESOLVED,
33  STARTING,
34  STOPPING,
35  ACTIVE,
36  };
37 
47  class Bundle {
48  public:
49  explicit Bundle(celix_bundle_t* _cBnd) : cBnd{_cBnd, [](celix_bundle_t*){/*nop*/}} {}
50 
55  [[nodiscard]] long getId() const { return celix_bundle_getId(cBnd.get()); }
56 
67  [[nodiscard]] std::string getEntry(std::string_view path) const {
68  std::string result{};
69  char* entry = celix_bundle_getEntry(cBnd.get(), path.data());
70  if (entry != nullptr) {
71  result = std::string{entry};
72  free(entry);
73  }
74  return result;
75  }
76 
82  [[nodiscard]] std::string getManifestValue(std::string_view attribute) const {
83  const char* header = celix_bundle_getManifestValue(cBnd.get(), attribute.data());
84  return header == nullptr ? std::string{} : std::string{header};
85  }
86 
90  [[nodiscard]] std::string getSymbolicName() const {
91  return std::string{celix_bundle_getSymbolicName(cBnd.get())};
92  }
93 
97  [[nodiscard]] std::string getName() const {
98  return std::string{celix_bundle_getName(cBnd.get())};
99  }
100 
104  [[nodiscard]] std::string getGroup() const {
105  return std::string{celix_bundle_getGroup(cBnd.get())};
106  }
107 
111  [[nodiscard]] std::string getDescription() const {
112  return std::string{celix_bundle_getDescription(cBnd.get())};
113  }
114 
118  [[nodiscard]] celix::BundleState getState() const {
119  auto cState = celix_bundle_getState(cBnd.get());
120  switch (cState) {
121  case OSGI_FRAMEWORK_BUNDLE_UNINSTALLED:
123  case OSGI_FRAMEWORK_BUNDLE_INSTALLED:
124  return BundleState::INSTALLED;
125  case OSGI_FRAMEWORK_BUNDLE_RESOLVED:
126  return BundleState::RESOLVED;
127  case OSGI_FRAMEWORK_BUNDLE_STARTING:
128  return BundleState::STARTING;
129  case OSGI_FRAMEWORK_BUNDLE_STOPPING:
130  return BundleState::STOPPING;
131  case OSGI_FRAMEWORK_BUNDLE_ACTIVE:
132  return BundleState::ACTIVE;
133  default:
134  return BundleState::UNKNOWN;
135  }
136  }
137 
142  [[nodiscard]] bool isSystemBundle() const {
143  return celix_bundle_isSystemBundle(cBnd.get());
144  }
145  private:
146  const std::shared_ptr<celix_bundle_t> cBnd;
147  };
148 }
celix::BundleState::STOPPING
@ STOPPING
celix_bundle_getDescription
const char * celix_bundle_getDescription(const celix_bundle_t *bnd)
Returns the description of the bundle. Note the return value is valid as long as the bundle is instal...
celix::BundleState::UNINSTALLED
@ UNINSTALLED
celix::BundleState
BundleState
Definition: Bundle.h:28
celix
Definition: Bundle.h:26
celix::BundleState::ACTIVE
@ ACTIVE
celix::BundleState::RESOLVED
@ RESOLVED
celix::Bundle::getEntry
std::string getEntry(std::string_view path) const
Get a use-able entry path for the provided relative path to a bundle resource.
Definition: Bundle.h:67
celix::Bundle::Bundle
Bundle(celix_bundle_t *_cBnd)
Definition: Bundle.h:49
celix_bundle_getEntry
char * celix_bundle_getEntry(const celix_bundle_t *bnd, const char *path)
celix::BundleState::UNKNOWN
@ UNKNOWN
celix::Bundle::getDescription
std::string getDescription() const
The description of the bundle.
Definition: Bundle.h:111
celix::Bundle::getState
celix::BundleState getState() const
The current bundle state.
Definition: Bundle.h:118
celix::BundleState::INSTALLED
@ INSTALLED
celix::Bundle::isSystemBundle
bool isSystemBundle() const
whether the bundle is the system (framework) bundle
Definition: Bundle.h:142
celix::Bundle
An installed bundle in the Celix framework.
Definition: Bundle.h:47
celix_bundle_getState
celix_bundle_state_e celix_bundle_getState(const celix_bundle_t *bnd)
Returns the bundle state.
celix_bundle_isSystemBundle
bool celix_bundle_isSystemBundle(const celix_bundle_t *bnd)
Returns whether the bundle is the system bundle.
celix_bundle_getSymbolicName
const char * celix_bundle_getSymbolicName(const celix_bundle_t *bnd)
Returns the symbolic name of the bundle. Note the return value is valid as long as the bundle is inst...
celix::Bundle::getId
long getId() const
get the bundle id.
Definition: Bundle.h:55
celix::Bundle::getManifestValue
std::string getManifestValue(std::string_view attribute) const
Get a manifest attribute value from the bundle manifest.
Definition: Bundle.h:82
celix::Bundle::getGroup
std::string getGroup() const
The group of the bundle.
Definition: Bundle.h:104
celix_bundle_getGroup
const char * celix_bundle_getGroup(const celix_bundle_t *bnd)
Returns the group of the bundle. Groups are used to order bundles. Note the return value is valid as ...
celix_bundle.h
celix::Bundle::getSymbolicName
std::string getSymbolicName() const
the symbolic name of the bundle.
Definition: Bundle.h:90
celix_bundle_getId
long celix_bundle_getId(const celix_bundle_t *bnd)
Returns the bundle id.
celix_bundle_getName
const char * celix_bundle_getName(const celix_bundle_t *bnd)
Returns the name of the bundle. Note the return value is valid as long as the bundle is installed.
celix::Bundle::getName
std::string getName() const
The name of the bundle.
Definition: Bundle.h:97
celix::BundleState::STARTING
@ STARTING
celix_bundle_getManifestValue
const char * celix_bundle_getManifestValue(const celix_bundle_t *bnd, const char *attribute)
Get a manifest attribute value from the bundle manifest.