Apache Celix  latest
Apache Celix is a framework for C, C++14 and C++17 to develop dynamic modular software applications using component and in-process service-oriented programming.
FrameworkFactory.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/Properties.h"
25 #include "celix/Framework.h"
26 #include "celix/BundleContext.h"
27 #include "celix_framework_factory.h"
28 
29 namespace celix {
34 inline std::shared_ptr<celix::Framework> createFramework(const celix::Properties& properties = {}) {
35  auto* copy = celix_properties_copy(properties.getCProperties());
36  if (!copy) {
37  throw celix::Exception{"Could not copy properties"};
38  }
39 
40  auto* cFw = celix_frameworkFactory_createFramework(copy);
41  if (!cFw) {
42  throw celix::Exception{"Could not create framework"};
43  }
44 
45  auto fwCtx = std::make_shared<celix::BundleContext>(celix_framework_getFrameworkContext(cFw));
46  return std::shared_ptr<celix::Framework>{new celix::Framework{std::move(fwCtx), cFw}, [](celix::Framework* fw) {
47  auto* cFw = fw->getCFramework();
48  delete fw;
49  celix_frameworkFactory_destroyFramework(cFw);
50  }};
51 }
52 } // namespace celix
celix
Definition: Bundle.h:28
celix::Framework::getCFramework
celix_framework_t * getCFramework() const
Get the C framework.
Definition: Framework.h:109
BundleContext.h
celix::createFramework
std::shared_ptr< celix::Framework > createFramework(const celix::Properties &properties={})
Create a new celix Framework instance.
Definition: FrameworkFactory.h:34
Framework.h
celix::Framework
A Celix framework instance. A framework is also known as a system bundle.
Definition: Framework.h:38
celix::dm::Properties
celix::Properties Properties
Definition: Properties.h:25
celix_framework_getFrameworkContext
CELIX_FRAMEWORK_EXPORT celix_bundle_context_t * celix_framework_getFrameworkContext(const celix_framework_t *fw)
Returns the framework bundle context. This is the same as a 'normal' bundle context and can be used t...