apache / celix

Apache Celix is a framework for C and C++14 to develop dynamic modular software applications using component and in-process service-oriented programming.
https://celix.apache.org/
Apache License 2.0
165 stars 86 forks source link

Shell command support as consumerbundle #687

Closed tonychen0924 closed 10 months ago

tonychen0924 commented 10 months ago

My project is C++ , Now I want to create a bundle as consumer to give interface to control bundle . For example , it has a interface to do "install bundle" function . But I can not find a suitable demo . Before , I only to do service provider and consumer are all C++ .

PengZheng commented 10 months ago

I found the issue description incomprehensible. You may try to translate it into your native language using AI tools like deepl.com to double-check that.

I suggest that you describe the issue in native language first and use AI tools to translate it into English before posing it. Please edit your question to make it comprehensible before reopening the issue.

Or if you happen to speak Chinese (I made the guess from your ID), you can raise an issue in Chinese: https://github.com/PengZheng/Celix_CN You will also find Chinese documentation there.

tonychen0924 commented 10 months ago

Thank you for your advice. I'm sorry for the inconvenience caused by my native language being Chinese

In Celix's existing example, after starting the container, bundles can be operated on the terminal through commands such as "lb" and "install". Now I need to expose an interface in the C++ project as a server, and the client sends instructions to remotely operate on the bundle, that is, remotely complete the "install bundle" operation.

However, before I used celix, I used the same language C++ to complete the service side and the consumer side (see "celix/examples/celix-examples/services_example_cxx/src/SimpleConsumer) Bundleactivater.cc "). In the current project of Celix, I have not seen an example of C++ as a server, so I would like to ask if there is a similar case that can be used as a reference to achieve my needs? In addition, although the official website describes that C can be used as a server and C++ can be used as a consumer, it is only a description

PengZheng commented 10 months ago

Celix::http_admin serves as a server, and Celix::shell_wui exposes the ability of bundle management via WEB, which I believe you already have tried in #592:

Run examples/celix-examples/http_example, open localhost:8080/shell in your browser.

Now you can install/uninstall/start/stop bundle using browser (remotely of course).

PengZheng commented 10 months ago

If you are C++ fans, I would recommend https://github.com/CppMicroServices/CppMicroServices or https://github.com/volt-software/Ichor.

tonychen0924 commented 10 months ago

The example you mentioned I have tried before, it can be used. However, my current requirement is to create a component in my project that controls the bundle as a service consumer and invokes the interface in the bundle on the server side to achieve Bundle management. The http example is essentially still entering terminal instructions on the web page, which is not what I need to lock. What I want is: provider bundle-> call function(std::string commandLine, std:string bundleName) -> consumer bunde std::string commandLine = "install"; std:string bundleName = "path/to/xx.zip" At present, I only find some scattered implementation parts written in C language, and I feel more difficult to use C++ to connect with him, because I only see the same language C or C++ to realize the server side and consumer side examples

PengZheng commented 10 months ago

provider bundle-> call function(std::string commandLine, std:string bundleName) -> consumer bunde

What service does the provider bundle provide? What service does the consumer bundle consume? What does the service do? It seems to me that the "provider" calls a function implemented (provided) by the "consumer". That makes me confused.

If you want to call some function to manage another framework instance running in another process/host, then what you need is expose celix_framework_installBundle/celix_framework_uninstallBundle via remote procedure call. We do support RPC (check remote services examples bundles/remote_services/examples), but then you need to design the remote services and hook it to celix_framework_installBundle/celix_framework_uninstallBundle. This should be straightforward.

tonychen0924 commented 10 months ago

What you said is very difficult for me, "celix/examples/celix - examples/readme_cxx_examples/SRC/MyShellCommandProviderBundleActivator. Cc" such as the file, The executeCommand inside I was hoping to implement specific operations on the bundle, but it doesn't. Then you can in the class MyShellCommandProviderBundleActivator "write executeCommand (" install", "XXX.zip"...) "I don't know what the other two parameters are. If you can provide such an example here, I can write the server side and the consumer side to achieve my functions

To summarize, to mention "MyShellCommandProviderBundleActivator. Cc"

  1. I want the executeCommand I call to have an interface that implements the actual operations of the bundle, not just a printf simulation
  2. The interface can be tested when the container is started
PengZheng commented 10 months ago

If you want to implement a shell command, which manages bundles in the same framework instance as the provider (rather than a simple printf), then you can check bundles/shell/shell/src/install_command.c for an example (Celix::shell and Celix::ShellCxx provide all the standard Celix commands). Most of such bundle management commands are already provided as standard ones. Normally you don't need to reinvent the wheel.

If you want to implement a shell command, which manages bundles installed in a different framework instance as the provider, then you must rely on remote services.

If you don't want to use remote services because it's hard, just install and start #592 bundles in the target framework instance. Remembering that Apache Celix Shell WUI just responds to normal HTTP requests, you can use libcurl to issue an HTTP request consisting of bundle management commands like lb, which Celix::shell_wui in the target framework will process.

To be honest, I still don't get you, and will stop here. Let's hope others can understand your question better. Or you could describe it in Chinese here: https://github.com/PengZheng/Celix_CN

To my current understanding, there is nothing flawed (and thus need to be fixed) . So I'll leave this closed.