Apache Celix  2.3.0
An implementation of the OSGi specification adapted to C and C++
Framework.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_framework.h"
25 
26 namespace celix {
27 
28  class BundleContext; //forward declaration
29 
37  class Framework {
38  public:
39  Framework(std::shared_ptr<celix::BundleContext> _fwCtx, celix_framework_t* _cFw) :
40  fwCtx{std::move(_fwCtx)},
41  cFw{std::shared_ptr<celix_framework_t >{_cFw, [](celix_framework_t*){/*nop*/}}}
42  {}
43 
47  [[nodiscard]] std::string getUUID() const {
48  return std::string{celix_framework_getUUID(cFw.get())};
49  }
50 
54  [[nodiscard]] std::shared_ptr<celix::BundleContext> getFrameworkBundleContext() const {
55  return fwCtx;
56  }
57 
70  long fireGenericEvent(long bndId, const char* eventName, std::function<void()> processEventCallback, long eventId = -1) {
71  auto* callbackOnHeap = new std::function<void()>{};
72  *callbackOnHeap = std::move(processEventCallback);
74  cFw.get(),
75  eventId,
76  bndId,
77  eventName,
78  static_cast<void*>(callbackOnHeap),
79  [](void *data) {
80  auto* callback = static_cast<std::function<void()>*>(data);
81  (*callback)();
82  delete callback;
83  },
84  nullptr,
85  nullptr);
86  }
87 
91  void waitForStop() {
92  celix_framework_waitForStop(cFw.get());
93  }
94 
98  void waitForEvent(long eventId) {
99  celix_framework_waitForGenericEvent(cFw.get(), eventId);
100  }
101 
108  [[nodiscard]] celix_framework_t * getCFramework() const {
109  return cFw.get();
110  }
111  private:
112  const std::shared_ptr<celix::BundleContext> fwCtx;
113  const std::shared_ptr<celix_framework_t> cFw;
114  };
115 }
celix_framework_waitForGenericEvent
void celix_framework_waitForGenericEvent(celix_framework_t *fw, long eventId)
Wait until a event with the provided event id is completely handled. This function will directly retu...
celix_framework_fireGenericEvent
long celix_framework_fireGenericEvent(celix_framework_t *fw, long eventId, long bndId, const char *eventName, void *processData, void(*processCallback)(void *data), void *doneData, void(*doneCallback)(void *doneData))
Fire a generic event. The event will be added to the event loop and handled on the event loop thread.
celix
Definition: Bundle.h:26
celix_framework_waitForStop
void celix_framework_waitForStop(celix_framework_t *framework)
Wait until the framework is stopped.
celix::Framework::fireGenericEvent
long fireGenericEvent(long bndId, const char *eventName, std::function< void()> processEventCallback, long eventId=-1)
Fire a generic Celix framework event.
Definition: Framework.h:70
celix::Framework::getCFramework
celix_framework_t * getCFramework() const
Get the C framework.
Definition: Framework.h:108
celix_framework_getUUID
const char * celix_framework_getUUID(const celix_framework_t *fw)
Returns the framework UUID. This is unique for every created framework and will not be the same if th...
celix_framework.h
celix::Framework::getUUID
std::string getUUID() const
Get the framework UUID.
Definition: Framework.h:47
celix::Framework::waitForStop
void waitForStop()
Block until the framework is stopped.
Definition: Framework.h:91
celix::Framework::getFrameworkBundleContext
std::shared_ptr< celix::BundleContext > getFrameworkBundleContext() const
Get the bundle context for the framework.
Definition: Framework.h:54
celix::Framework::waitForEvent
void waitForEvent(long eventId)
Wait until all Celix event for this framework are completed.
Definition: Framework.h:98
celix::Framework
A Celix framework instance. A framework is also known as a system bundle.
Definition: Framework.h:37
celix::Framework::Framework
Framework(std::shared_ptr< celix::BundleContext > _fwCtx, celix_framework_t *_cFw)
Definition: Framework.h:39