{"id":14988192,"url":"https://github.com/apache/celix","last_synced_at":"2025-05-16T13:08:20.059Z","repository":{"id":19533445,"uuid":"22781134","full_name":"apache/celix","owner":"apache","description":"Apache Celix is a framework for C and C++14 to develop dynamic modular software applications using component and in-process service-oriented programming.","archived":false,"fork":false,"pushed_at":"2025-05-08T01:17:11.000Z","size":21119,"stargazers_count":174,"open_issues_count":77,"forks_count":92,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-08T02:23:33.265Z","etag":null,"topics":["apache","c","celix","cplusplus","osgi"],"latest_commit_sha":null,"homepage":"https://celix.apache.org/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apache.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-08-09T07:00:07.000Z","updated_at":"2025-05-08T01:12:32.000Z","dependencies_parsed_at":"2023-09-26T01:12:36.855Z","dependency_job_id":"bcc4da53-fbd3-4302-8dcd-cb61d0d99514","html_url":"https://github.com/apache/celix","commit_stats":{"total_commits":3951,"total_committers":44,"mean_commits":89.79545454545455,"dds":0.6502151354087573,"last_synced_commit":"032438f23b64c33b9ea1f3d101d9f0bd75698c66"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcelix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcelix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcelix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcelix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/celix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535828,"owners_count":22087399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apache","c","celix","cplusplus","osgi"],"created_at":"2024-09-24T14:16:16.437Z","updated_at":"2025-05-16T13:08:20.040Z","avatar_url":"https://github.com/apache.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nLicensed to the Apache Software Foundation (ASF) under one or more\ncontributor license agreements.  See the NOTICE file distributed with\nthis work for additional information regarding copyright ownership.\nThe ASF licenses this file to You under the Apache License, Version 2.0\n(the \"License\"); you may not use this file except in compliance with\nthe License.  You may obtain a copy of the License at\n   \n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n--\u003e\n\n# Apache Celix\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n![Celix Ubuntu](https://github.com/apache/celix/workflows/Celix%20Ubuntu/badge.svg)\n![Celix MacOS](https://github.com/apache/celix/workflows/Celix%20MacOS/badge.svg)\n[![codecov](https://codecov.io/gh/apache/celix/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/celix)\n[![Coverity Scan Build Status](https://scan.coverity.com/projects/6685/badge.svg)](https://scan.coverity.com/projects/6685)\n[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers\u0026message=Open\u0026color=blue\u0026logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/apache/celix)\n\nApache Celix is a framework for C and C++14 to develop dynamic modular software applications using component \nand in-process service-oriented programming. \nApache Celix is inspired by the [OSGi specification](https://www.osgi.org/) adapted for C and C++.\n\n## Documentation\n- [Building Apache Celix](documents/building/README.md)\n- [Apache Celix Intro](documents/README.md)\n\n## C++ Usage\n\n### Hello World Bundle\n\nModularity in Celix is achieved by runtime installable bundles and dynamic - in process - services.  \nA Celix bundle is set of resources packed in a zip containing at least a manifest and almost always\nsome shared library containing the bundle functionality.\nA Celix bundle can be created using the Celix CMake function `add_celix_bundle`.\nA Celix bundle is activated by executing the bundle entry points. For C++ bundles these bundle entry points are generated using the `CELIX_GEN_CXX_BUNDLE_ACTIVATOR` macro. \n\nCelix applications (Celix containers) can be created with the Celix CMake function `add_celix_container`.\nThis function generates a C++ main function and is also used to configure default installed bundles. \nThis can be bundles provided by Celix, an other project or build by the project self. \n\n```C++\n//src/MyBundleActivator.cc\n#include \u003ciostream\u003e\n#include \"celix/BundleActivator.h\"\n\nclass MyBundleActivator {\npublic:\n    explicit MyBundleActivator(const std::shared_ptr\u003ccelix::BundleContext\u003e\u0026 ctx) {\n        std::cout \u003c\u003c \"Hello world from bundle with id \" \u003c\u003c ctx-\u003egetBundleId() \u003c\u003c std::endl;\n    }\n\n    ~MyBundleActivator() noexcept {\n        std::cout \u003c\u003c \"Goodbye world\" \u003c\u003c std::endl;\n    }\n};\n\nCELIX_GEN_CXX_BUNDLE_ACTIVATOR(MyBundleActivator)\n```\n\n```CMake\n#CMakeLists.txt\nfind_package(Celix REQUIRED)\n\nadd_celix_bundle(MyBundle\n    SOURCES src/MyBundleActivator.cc\n)\n\nadd_celix_container(MyContainer\n    BUNDLES\n        Celix::ShellCxx\n        Celix::shell_tui\n        MyBundle\n)\n```\n\n```sh\n#bash\n#goto project dir\ncd cmake-build-debug #assuming clion cmake-build-debug dir\ncd deploy/MyContainer\n./MyContainer\n#Celix shell\n-\u003e lb -a\n#list of all installed bundles\n-\u003e help\n#list of all available Celix shell commands\n-\u003e help celix::lb\n#Help info about the shell command `celix::lb`\n-\u003e stop 3\n#stops MyBundle\n-\u003e start 3\n#starts MyBundle\n-\u003e stop 0 \n#stops the Celix framework\n```\n\n### Register a service\n\nIn the Celix framework, a service is a C++ object or C struct registered in the Celix framework service registry under one interface together with properties (meta information). Services can be discovered and used by bundles.\n\n```C++\n//include/ICalc.h\n#pragma once\nclass ICalc {\npublic:\n    virtual ~ICalc() noexcept = default;\n    virtual int add(int a, int b) = 0;\n};\n```\n\n```C++\n//src/CalcProviderBundleActivator.cc\n#include \"ICalc.h\"\n#include \"celix/BundleActivator.h\"\n\nclass CalcProvider : public ICalc {\npublic:\n    ~CalcProvider() noexcept override = default;\n    int add(int a, int b) override { return a + b; }\n};\n\nclass CalcProviderBundleActivator {\npublic:\n    explicit CalcProviderBundleActivator(const std::shared_ptr\u003ccelix::BundleContext\u003e\u0026 ctx) {\n        reg = ctx-\u003eregisterService\u003cICalc\u003e(std::make_shared\u003cCalcProvider\u003e())\n                .build();\n    }\nprivate:\n    std::shared_ptr\u003ccelix::ServiceRegistration\u003e reg{};\n};\n\nCELIX_GEN_CXX_BUNDLE_ACTIVATOR(CalcProviderBundleActivator)\n```\n\n```CMake\n#CMakeLists.txt\nfind_package(Celix REQUIRED)\n\nadd_celix_bundle(CalcProviderBundle\n    SOURCES src/CalcProviderBundleActivator.cc\n)\ntarget_include_directories(CalcProviderBundle PRIVATE include)\n\nadd_celix_container(CalcProviderContainer\n    BUNDLES\n        Celix::ShellCxx\n        Celix::shell_tui\n        CalcProviderBundle\n)\n```\n\n```bash\n#bash\n#goto project dir\ncd cmake-build-debug #assuming clion cmake-build-debug dir\ncd deploy/CalcProviderBundle\n./CalcProviderBundle\n```\n\n### Use a service (ad hoc)\n\n```C++\n//include/ICalc.h\n#pragma once\nclass ICalc {\npublic:\n    virtual ~ICalc() noexcept = default;\n    virtual int add(int a, int b) = 0;\n};\n```\n\n\n```C++\n//src/CalcUserBundleActivator.cc\n#include \u003ciostream\u003e\n#include \"ICalc.h\"\n#include \"celix/BundleActivator.h\"\n\nclass CalcUserBundleActivator {\npublic:\n    explicit CalcUserBundleActivator(const std::shared_ptr\u003ccelix::BundleContext\u003e\u0026 ctx) {\n        ctx-\u003euseService\u003cICalc\u003e()\n            .addUseCallback([](ICalc\u0026 calc) {\n                std::cout \u003c\u003c \"result is \" \u003c\u003c calc.add(2, 3) \u003c\u003c std::endl;\n            })\n            .setTimeout(std::chrono::seconds{1}) //wait for 1 second if a service is not directly found\n            .build();\n    }\n};\n\nCELIX_GEN_CXX_BUNDLE_ACTIVATOR(CalcUserBundleActivator)\n```\n\n```CMake\n#CMakeLists.txt\nfind_package(Celix REQUIRED)\n\nadd_celix_bundle(CalcUserBundle\n    SOURCES src/CalcUserBundleActivator.cc\n)\ntarget_include_directories(CalcUserBundle PRIVATE include)\n\nadd_celix_container(CalcUserContainer\n    BUNDLES\n        Celix::ShellCxx\n        Celix::shell_tui\n        CalcProviderBundle\n        CalcUserBundle\n)\n```\n\n```bash\n#bash\n#goto project dir\ncd cmake-build-debug #assuming clion cmake-build-debug dir\ncd deploy/CalcUserContainer\n./CalcUserContainer\n```\n\n### Track services \n\n```C++\n//include/ICalc.h\n#pragma once\nclass ICalc {\npublic:\n    virtual ~ICalc() noexcept = default;\n    virtual int add(int a, int b) = 0;\n};\n```\n\n```C++\n//src/CalcTrackerBundleActivator.cc\n#include \u003cmutex\u003e\n#include \"ICalc.h\"\n#include \"celix/BundleActivator.h\"\n\nclass CalcTrackerBundleActivator {\npublic:\n    explicit CalcTrackerBundleActivator(const std::shared_ptr\u003ccelix::BundleContext\u003e\u0026 ctx) {\n        tracker = ctx-\u003etrackServices\u003cICalc\u003e()\n            .build();\n        for (auto\u0026 calc : tracker-\u003egetServices()) {\n            std::cout \u003c\u003c \"result is \" \u003c\u003c std::to_string(calc-\u003eadd(2, 3)) \u003c\u003c std::endl;\n        }\n    }\n    \nprivate:\n    std::shared_ptr\u003ccelix::ServiceTracker\u003cICalc\u003e\u003e tracker{};\n};\n\nCELIX_GEN_CXX_BUNDLE_ACTIVATOR(CalcTrackerBundleActivator)\n```\n```CMake\nfind_package(Celix REQUIRED)\n\nadd_celix_bundle(CalcTrackerBundle\n    SOURCES src/CalcTrackerBundleActivator.cc\n)\ntarget_include_directories(CalcTrackerBundle PRIVATE include)\n\nadd_celix_container(CalcTrackerContainer\n    BUNDLES\n        Celix::ShellCxx\n        Celix::shell_tui\n        CalcProviderBundle\n        CalcTrackerBundle\n)\n```\n\n```bash\n#bash\n#goto project dir\ncd cmake-build-debug #assuming clion cmake-build-debug dir\ncd deploy/CalcTrackerContainer\n./CalcTrackerContainer\n```\n\n### Service properties and filters\n\n```C++\n//src/FilterExampleBundleActivator.cc\n#include \u003ciostream\u003e\n#include \"celix/BundleActivator.h\"\n#include \"celix/IShellCommand.h\"\n\nclass HelloWorldShellCommand : public celix::IShellCommand {\npublic:\n    void executeCommand(const std::string\u0026 /*commandLine*/, const std::vector\u003cstd::string\u003e\u0026 /*commandArgs*/, FILE* outStream, FILE* /*errorStream*/) {\n        fprintf(outStream, \"Hello World\\n\");\n    }\n};\n\nclass FilterExampleBundleActivator {\npublic:\n    explicit FilterExampleBundleActivator(const std::shared_ptr\u003ccelix::BundleContext\u003e\u0026 ctx) {\n        auto reg1 = ctx-\u003eregisterService\u003ccelix::IShellCommand\u003e(std::make_shared\u003cHelloWorldShellCommand\u003e())\n                .addProperty(celix::IShellCommand::COMMAND_NAME, \"command1\")\n                .build();\n        auto reg2 = ctx-\u003eregisterService\u003ccelix::IShellCommand\u003e(std::make_shared\u003cHelloWorldShellCommand\u003e())\n                .addProperty(celix::IShellCommand::COMMAND_NAME, \"command2\")\n                .build();\n        regs.push_back(reg1);\n        regs.push_back(reg2);\n        \n        auto serviceIdsNoFilter  = ctx-\u003efindServices\u003ccelix::IShellCommand\u003e();\n        auto serviceIdsWithFilter = ctx-\u003efindServices\u003ccelix::IShellCommand\u003e(std::string{\"(\"} + celix::IShellCommand::COMMAND_NAME + \"=\" + \"command1)\");\n        std::cout \u003c\u003c \"Found \" \u003c\u003c std::to_string(serviceIdsNoFilter.size()) \u003c\u003c \" IShelLCommand services and found \";\n        std::cout \u003c\u003c std::to_string(serviceIdsWithFilter.size()) \u003c\u003c \" IShellCommand service with name command1\" \u003c\u003c std::endl;\n    }\nprivate:\n    std::vector\u003cstd::shared_ptr\u003ccelix::ServiceRegistration\u003e\u003e regs{};\n};\n\nCELIX_GEN_CXX_BUNDLE_ACTIVATOR(FilterExampleBundleActivator)\n```\n\n```CMake\n#CMakeLists.txt\nfind_package(Celix REQUIRED)\n\nadd_celix_bundle(FilterExampleBundle\n    SOURCES src/FilterExampleBundleActivator.cc\n)\ntarget_link_libraries(FilterExampleBundle PRIVATE Celix::shell_api) #adds celix/IShellCommand.h to the include path\n\nadd_celix_container(FilterExampleContainer\n    BUNDLES\n        Celix::ShellCxx\n        Celix::shell_tui\n        FilterExampleBundle\n)\n```\n\n```bash\n#bash\n#goto project dir\ncd cmake-build-debug #assuming clion cmake-build-debug dir\ncd deploy/FilterExampleContainer\n./FilterExampleContainer\n#Celix shell\n-\u003e command1\n-\u003e command2\n-\u003e help\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fcelix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fcelix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fcelix/lists"}