celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [celix] pnoltes commented on a change in pull request #310: Adds initial impl for the C++ headers only wrappers
Date Sun, 21 Feb 2021 19:48:37 GMT

pnoltes commented on a change in pull request #310:
URL: https://github.com/apache/celix/pull/310#discussion_r579855867



##########
File path: libs/framework/include/celix/TrackerBuilders.h
##########
@@ -0,0 +1,358 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#include "Trackers.h"
+
+namespace celix {
+
+    /**
+     * @brief Fluent builder API to track services.
+     *
+     * @see celix::BundleContext::trackServices for more info.
+     * @tparam I The service type to track.
+     * @note Not thread safe.
+     */
+    template<typename I>
+    class ServiceTrackerBuilder {
+    private:
+        friend class BundleContext;
+
+        //NOTE private to prevent move so that a build() call cannot be forgotten
+        ServiceTrackerBuilder(ServiceTrackerBuilder&&) = default;
+    public:
+        explicit ServiceTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx,
std::string _name) :
+                cCtx{std::move(_cCtx)},
+                name{std::move(_name)} {}
+
+        ServiceTrackerBuilder& operator=(ServiceTrackerBuilder&&) = delete;
+        ServiceTrackerBuilder(const ServiceTrackerBuilder&) = delete;
+        ServiceTrackerBuilder operator=(const ServiceTrackerBuilder&) = delete;
+
+        /**
+         * @brief Set filter to be used to matching services.
+         *
+         * The filter must be LDAP filter.
+         * Example:
+         *      "(property_key=value)"
+         */
+        ServiceTrackerBuilder& setFilter(std::string f) { filter = celix::Filter{std::move(f)};
return *this; }
+
+        /**
+         * @brief Set filter to be used to matching services.
+         */
+        ServiceTrackerBuilder& setFilter(celix::Filter f) { filter = std::move(f); return
*this; }
+
+        /**
+         * @brief Adds a add callback function, which will be called - on the Celix event
thread -
+         * when a new service match is found.
+         *
+         * The add callback function has 1 argument: A shared ptr to the added service.
+         */
+        ServiceTrackerBuilder& addAddCallback(std::function<void(std::shared_ptr<I>)>
add) {
+            addCallbacks.emplace_back([add](std::shared_ptr<I> svc, std::shared_ptr<const
celix::Properties>, std::shared_ptr<const celix::Bundle>) {
+                add(svc);
+            });
+            return *this;
+        }
+
+        /**
+         * @brief Adds a add callback function, which will be called - on the Celix event
thread -
+         * when a new service match is found.
+         *
+         * The add callback function has 2 arguments:
+         *  - A shared ptr to the added service.
+         *  - A shared ptr to the added service properties.
+         */
+        ServiceTrackerBuilder& addAddWithPropertiesCallback(std::function<void(std::shared_ptr<I>,
std::shared_ptr<const celix::Properties>)> add) {
+            addCallbacks.emplace_back([add](std::shared_ptr<I> svc, std::shared_ptr<const
celix::Properties> props, std::shared_ptr<const celix::Bundle>) {
+                add(svc, props);
+            });
+            return *this;
+        }
+
+        /**
+         * @brief Adds a add callback function, which will be called - on the Celix event
thread -
+         * when a new service match is found.
+         *
+         * The add callback function has 3 arguments:
+         *  - A shared ptr to the added service.
+         *  - A shared ptr to the added service properties.
+         *  - A shared ptr to the bundle owning the added service.
+         */
+        ServiceTrackerBuilder& addAddWithOwnerCallback(std::function<void(std::shared_ptr<I>,
std::shared_ptr<const celix::Properties>, std::shared_ptr<const celix::Bundle>)>
add) {
+            addCallbacks.emplace_back(std::move(add));
+            return *this;
+        }
+
+        /**
+         * @brief Adds a remove callback function, which will be called - on the Celix event
thread -
+         * when a service match is being removed.
+         *
+         * The remove callback function has 1 arguments: A shared ptr to the removing service.
+         */
+        ServiceTrackerBuilder& addRemCallback(std::function<void(std::shared_ptr<I>)>
remove) {
+            remCallbacks.emplace_back([remove](std::shared_ptr<I> svc, std::shared_ptr<const
celix::Properties>, std::shared_ptr<const celix::Bundle>) {
+                remove(svc);
+            });
+            return *this;
+        }
+
+        /**
+         * @brief Adds a remove callback function, which will be called - on the Celix event
thread -
+         * when a service match is being removed.
+         *
+         * The remove callback function has 2 arguments:
+         *  - A shared ptr to the removing service.
+         *  - A shared ptr to the removing service properties.
+         */
+        ServiceTrackerBuilder& addRemWithPropertiesCallback(std::function<void(std::shared_ptr<I>,
std::shared_ptr<const celix::Properties>)> remove) {
+            remCallbacks.emplace_back([remove](std::shared_ptr<I> svc, std::shared_ptr<const
celix::Properties> props, std::shared_ptr<const celix::Bundle>) {
+                remove(svc, props);
+            });
+            return *this;
+        }
+
+        /**
+         * @brief Adds a remove callback function, which will be called - on the Celix event
thread -
+         * when a service match is being removed.
+         *
+         * The remove callback function has 3 arguments:
+         *  - A shared ptr to the removing service.
+         *  - A shared ptr to the removing service properties.
+         *  - A shared ptr to the bundle owning the removing service.
+         */
+        ServiceTrackerBuilder& addRemWithOwnerCallback(std::function<void(std::shared_ptr<I>,
std::shared_ptr<const celix::Properties>, std::shared_ptr<const celix::Bundle>)>
remove) {
+            remCallbacks.emplace_back(std::move(remove));
+            return *this;
+        }
+
+        /**
+         * @brief Adds a set callback function, which will be called - on the Celix event
thread -
+         * when there is a new highest ranking service match.
+         * This can can also be an empty match (nullptr).
+         *
+         * The set callback function has 2 arguments: A shared ptr to the highest

Review comment:
       updated. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message