This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/cxx
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 23d6e67638e1ef87f1f62c82e0f29b90fd11689e
Author: Pepijn Noltes <pepijnnol...@gmail.com>
AuthorDate: Sun Jan 6 21:10:44 2019 +0100

    CELIX-438: Some refactoring
---
 .../shell/cxx_shell/include/celix/IShellCommand.h  |  2 +-
 bundles/shell/cxx_shell/src/HelpCommand.cc         | 17 ++++++++----
 bundles/shell/cxx_shell/src/ShellActivator.cc      | 32 ++++++++++++++--------
 libs/framework_cxx/include/celix/BundleContext.h   |  4 +--
 libs/framework_cxx/include/celix/Framework.h       |  1 -
 .../framework_cxx/include/celix/IBundleActivator.h |  8 ++----
 libs/framework_cxx/include/celix/api.h             |  1 +
 libs/registry/include/celix/Utils.h                |  2 +-
 libs/registry/src/ServiceRegistry.cc               |  6 ++++
 9 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/bundles/shell/cxx_shell/include/celix/IShellCommand.h 
b/bundles/shell/cxx_shell/include/celix/IShellCommand.h
index ec98c73..434fdfd 100644
--- a/bundles/shell/cxx_shell/include/celix/IShellCommand.h
+++ b/bundles/shell/cxx_shell/include/celix/IShellCommand.h
@@ -39,7 +39,7 @@ namespace celix {
         virtual void executeCommand(const std::string &cmdName, const 
std::vector<std::string> &cmdArgs, std::ostream &out, std::ostream &err) 
noexcept = 0;
     };
 
-    static constexpr const char * const SHELL_COMMAND_FUNCTION_SERVICE_FQN = 
"celix::ShellFunction [Version 1]";
+    static constexpr const char * const SHELL_COMMAND_FUNCTION_SERVICE_FQN = 
"celix::ShellCommandFunction [Version 1]";
     static constexpr const char * const SHELL_COMMAND_FUNCTION_COMMAND_NAME = 
"COMMAND_NAME";
     static constexpr const char * const SHELL_COMMAND_FUNCTION_COMMAND_USAGE = 
"COMMAND_USAGE";
     static constexpr const char * const 
SHELL_COMMAND_FUNCTION_COMMAND_DESCRIPTION = "COMMAND_DESCRIPTION";
diff --git a/bundles/shell/cxx_shell/src/HelpCommand.cc 
b/bundles/shell/cxx_shell/src/HelpCommand.cc
index 0ed5fea..9b7dc9e 100644
--- a/bundles/shell/cxx_shell/src/HelpCommand.cc
+++ b/bundles/shell/cxx_shell/src/HelpCommand.cc
@@ -22,9 +22,10 @@
 #include "celix/api.h"
 #include "celix/IShellCommand.h"
 
-celix::ServiceRegistration 
impl::registerHelp(std::shared_ptr<celix::BundleContext> ctx) {
 
-    celix::ShellCommandFunction help = [ctx](const std::string &, const 
std::vector<std::string> &commandArguments, std::ostream &out, std::ostream &) {
+namespace {
+
+    void help(std::shared_ptr<celix::BundleContext> ctx, const std::string &, 
const std::vector<std::string> &commandArguments, std::ostream &out, 
std::ostream &) {
 
         if (commandArguments.empty()) { //only command -> overview
 
@@ -59,8 +60,7 @@ celix::ServiceRegistration 
impl::registerHelp(std::shared_ptr<celix::BundleConte
                 }, commandNameFilter);
                 if (!found) {
                     commandNameFilter = std::string{"("} + 
celix::SHELL_COMMAND_FUNCTION_COMMAND_NAME + "=" + cmd + ")";
-                    std::function<void(celix::ShellCommandFunction &, const 
celix::Properties &)> use = [&](
-                            celix::ShellCommandFunction &, const 
celix::Properties &props) {
+                    std::function<void(celix::ShellCommandFunction &, const 
celix::Properties &)> use = [&](celix::ShellCommandFunction &, const 
celix::Properties &props) {
                         out << "Command Name       : " << 
celix::getProperty(props, celix::SHELL_COMMAND_FUNCTION_COMMAND_NAME, 
"!Error!") << std::endl;
                         out << "Command Usage      : " << 
celix::getProperty(props, celix::SHELL_COMMAND_FUNCTION_COMMAND_USAGE, 
"!Error!") << std::endl;
                         out << "Command Description: " << 
celix::getProperty(props, celix::SHELL_COMMAND_FUNCTION_COMMAND_DESCRIPTION, 
"!Error!") << std::endl;
@@ -76,11 +76,16 @@ celix::ServiceRegistration 
impl::registerHelp(std::shared_ptr<celix::BundleConte
                 out << std::endl;
             }
         }
-    };
+    }
+}
+
+celix::ServiceRegistration 
impl::registerHelp(std::shared_ptr<celix::BundleContext> ctx) {
+    using namespace std::placeholders;
+    celix::ShellCommandFunction cmd = std::bind(&help, ctx, _1, _2, _3, _4);
 
     celix::Properties props{};
     props[celix::SHELL_COMMAND_FUNCTION_COMMAND_NAME] = "help";
     props[celix::SHELL_COMMAND_FUNCTION_COMMAND_USAGE] = "help [command name]";
     props[celix::SHELL_COMMAND_FUNCTION_COMMAND_DESCRIPTION] = "display 
available commands and description.";
-    return 
ctx->registerFunctionService(celix::SHELL_COMMAND_FUNCTION_SERVICE_FQN, 
std::move(help), std::move(props));
+    return 
ctx->registerFunctionService(celix::SHELL_COMMAND_FUNCTION_SERVICE_FQN, 
std::move(cmd), std::move(props));
 }
\ No newline at end of file
diff --git a/bundles/shell/cxx_shell/src/ShellActivator.cc 
b/bundles/shell/cxx_shell/src/ShellActivator.cc
index 8d5d3fe..9d28070 100644
--- a/bundles/shell/cxx_shell/src/ShellActivator.cc
+++ b/bundles/shell/cxx_shell/src/ShellActivator.cc
@@ -46,7 +46,7 @@ namespace {
             std::vector<std::string> cmdArgs{};
 
             char *savePtr = nullptr;
-            char *cl = strndup(commandLine.c_str(), 1024*1024);
+            char *cl = strndup(commandLine.c_str(), 1024 * 1024);
             char *token = strtok_r(cl, " ", &savePtr);
             while (token != nullptr) {
                 if (cmdName.empty()) {
@@ -58,16 +58,24 @@ namespace {
             }
             free(cl);
 
+            if (cmdName.empty()) {
+                return true; /*nop, just enter and maybe some white spaces*/
+            } else {
+                return callShellCommands(cmdName, cmdArgs, out, err);
+            }
+        }
+
+    private:
+        bool callShellCommands(const std::string &cmdName, const 
std::vector<std::string> cmdArgs, std::ostream &out, std::ostream &err) {
             bool commandCalled = false;
 
-            if (!cmdName.empty()) {
-                //first try to call IShellCommand services.
-                std::string filter = std::string{"("} + 
celix::IShellCommand::COMMAND_NAME + "=" + cmdName + ")";
-                commandCalled = 
ctx->useService<celix::IShellCommand>([&](celix::IShellCommand &cmd) {
-                    cmd.executeCommand(cmdName, cmdArgs, out, err);
-                }, filter);
-            }
-            if (!cmdName.empty() && !commandCalled) {
+            //first try to call IShellCommand services.
+            std::string filter = std::string{"("} + 
celix::IShellCommand::COMMAND_NAME + "=" + cmdName + ")";
+            commandCalled = 
ctx->useService<celix::IShellCommand>([&](celix::IShellCommand &cmd) {
+                cmd.executeCommand(cmdName, cmdArgs, out, err);
+            }, filter);
+
+            if (!commandCalled) {
                 //if no IShellCommand service is found for the command name, 
try calling a ShellCommandFunction service.
                 std::string filter = std::string{"("} + 
celix::SHELL_COMMAND_FUNCTION_COMMAND_NAME + "=" + cmdName + ")";
                 std::function<void(celix::ShellCommandFunction&)> use = 
[&](celix::ShellCommandFunction &cmd) -> void {
@@ -76,12 +84,12 @@ namespace {
                 commandCalled = 
ctx->useFunctionService(celix::SHELL_COMMAND_FUNCTION_SERVICE_FQN, use, filter);
             }
 
-            //TODO C command service struct
-            if (!cmdName.empty() && !commandCalled) {
+            // TODO use C command service struct
+
+            if (!commandCalled) {
                 out << "Command '" << cmdName << "' not available. Type 'help' 
to see a list of available commands." << std::endl;
             }
 
-
             return commandCalled;
         }
     private:
diff --git a/libs/framework_cxx/include/celix/BundleContext.h 
b/libs/framework_cxx/include/celix/BundleContext.h
index 21a879e..2cdbf97 100644
--- a/libs/framework_cxx/include/celix/BundleContext.h
+++ b/libs/framework_cxx/include/celix/BundleContext.h
@@ -53,7 +53,7 @@ namespace celix {
             return registry().registerFunctionService(std::move(functionName), 
std::forward<F>(function), std::move(props), bundle());
         }
 
-        //TODO reg svc fatories
+        //TODO reg svc factories
 
         bool useBundle(long bndId, std::function<void(const celix::IBundle 
&bnd)> use) const {
             return bundle()->framework().useBundle(bndId, std::move(use));
@@ -71,7 +71,7 @@ namespace celix {
             return bundle()->framework().startBundle(bndId);
         }
 
-        //TODO install / uninstall bundles, trackb undles
+        //TODO install / uninstall bundles, use & track bundles
 
         template<typename I>
         bool useServiceWithId(long svcId, std::function<void(I& svc)> use) 
const {
diff --git a/libs/framework_cxx/include/celix/Framework.h 
b/libs/framework_cxx/include/celix/Framework.h
index 22d6aef..8689be7 100644
--- a/libs/framework_cxx/include/celix/Framework.h
+++ b/libs/framework_cxx/include/celix/Framework.h
@@ -31,7 +31,6 @@ namespace celix {
 
     class BundleContext; //forward declaration
 
-    //TODO resources. resolved from bundle specific symbols which is linked 
zip file to the library
     void registerStaticBundle(
             std::string symbolicName,
             
std::function<celix::IBundleActivator*(std::shared_ptr<celix::BundleContext>)> 
bundleActivatorFactory = {},
diff --git a/libs/framework_cxx/include/celix/IBundleActivator.h 
b/libs/framework_cxx/include/celix/IBundleActivator.h
index d2b05ec..b91978e 100644
--- a/libs/framework_cxx/include/celix/IBundleActivator.h
+++ b/libs/framework_cxx/include/celix/IBundleActivator.h
@@ -22,12 +22,10 @@
 
 namespace celix {
     /**
-     * The BundleActivator.
+     * The BundleActivator is a marker interface and contains no virtual 
methods.
      *
-     * This is a marker interface and contains no virtual methods.
-     *
-     * The Celix Framework will expect a constructor with a 
std::shared_ptr<celix::IBundleContext> argument on the
-     * contrete bundle activator. RAII will be used to start (on ctor) and 
stop (on dtor) a bundle.
+     * The Celix Framework will expect a constructor with a 
std::shared_ptr<celix:IBundleContext> argument for the
+     * concrete bundle activator. RAII will be used to start (on ctor) and 
stop (on dtor) a bundle.
      */
     class IBundleActivator {
     public:
diff --git a/libs/framework_cxx/include/celix/api.h 
b/libs/framework_cxx/include/celix/api.h
index fa0a8b9..606d165 100644
--- a/libs/framework_cxx/include/celix/api.h
+++ b/libs/framework_cxx/include/celix/api.h
@@ -24,6 +24,7 @@
 #include "celix/Filter.h"
 #include "celix/ServiceRegistry.h"
 #include "celix/IBundleActivator.h"
+#include "celix/IBundle.h"
 #include "celix/Framework.h"
 #include "celix/BundleContext.h"
 
diff --git a/libs/registry/include/celix/Utils.h 
b/libs/registry/include/celix/Utils.h
index 09d674d..ce72e4f 100644
--- a/libs/registry/include/celix/Utils.h
+++ b/libs/registry/include/celix/Utils.h
@@ -91,7 +91,7 @@ namespace celix {
     //NOTE C++17 typename std::enable_if<std::is_callable<I>::value, 
std::string>::type
     std::string functionServiceName(const std::string &fName) {
         std::string func = functionName<decltype(&F::operator())>();
-        return fName + "[" + func + "]";
+        return fName + " [" + func + "]";
     }
 }
 
diff --git a/libs/registry/src/ServiceRegistry.cc 
b/libs/registry/src/ServiceRegistry.cc
index 6ed83f7..b809e8f 100644
--- a/libs/registry/src/ServiceRegistry.cc
+++ b/libs/registry/src/ServiceRegistry.cc
@@ -25,6 +25,12 @@
 #include <utility>
 #include <future>
 
+#ifndef __APPLE__
+#include <linux/limits.h>
+#else
+#include <limits.h>
+#endif
+
 #include <glog/logging.h>
 #include <assert.h>
 

Reply via email to