celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erjanalt...@apache.org
Subject [2/2] celix git commit: Replaced celix-map with std::map
Date Thu, 01 Nov 2018 20:40:44 GMT
Replaced celix-map with std::map


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/3009e647
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/3009e647
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/3009e647

Branch: refs/heads/nanomsg
Commit: 3009e64705e1be606ca308ffc7ec7c0633dfde77
Parents: 95892a8
Author: Erjan Altena <erjanaltena@gmail.com>
Authored: Thu Nov 1 21:40:24 2018 +0100
Committer: Erjan Altena <erjanaltena@gmail.com>
Committed: Thu Nov 1 21:40:24 2018 +0100

----------------------------------------------------------------------
 .../src/pubsub_nanomsg_admin.cc                 | 57 +++++++++++---------
 .../src/pubsub_nanomsg_admin.h                  | 11 +++-
 .../src/pubsub_nanomsg_topic_receiver.h         |  3 +-
 3 files changed, 44 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/3009e647/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.cc
----------------------------------------------------------------------
diff --git a/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.cc b/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.cc
index c10431f..9fe91d9 100644
--- a/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.cc
+++ b/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.cc
@@ -28,7 +28,6 @@
 #include <netdb.h>
 #include <ifaddrs.h>
 #include <pubsub_endpoint.h>
-#include <pubsub_serializer.h>
 
 #include "pubsub_utils.h"
 #include "pubsub_nanomsg_admin.h"
@@ -105,7 +104,7 @@ pubsub_nanomsg_admin::pubsub_nanomsg_admin(celix_bundle_context_t *_ctx,
log_hel
     qosSampleScore = celix_bundleContext_getPropertyAsDouble(ctx, PSA_NANOMSG_QOS_SAMPLE_SCORE_KEY,
PSA_NANOMSG_DEFAULT_QOS_SAMPLE_SCORE);
     qosControlScore = celix_bundleContext_getPropertyAsDouble(ctx, PSA_NANOMSG_QOS_CONTROL_SCORE_KEY,
PSA_NANOMSG_DEFAULT_QOS_CONTROL_SCORE);
 
-    serializers.map = hashMap_create(nullptr, nullptr, nullptr, nullptr);
+    //serializers.map = hashMap_create(nullptr, nullptr, nullptr, nullptr);
 
     topicSenders.map = hashMap_create(utils_stringHash, nullptr, utils_stringEquals, nullptr);
 
@@ -145,10 +144,9 @@ pubsub_nanomsg_admin::~pubsub_nanomsg_admin() {
 
     {
         std::lock_guard<std::mutex> lock(serializers.mutex);
-        hash_map_iterator_t iter = hashMapIterator_construct(serializers.map);
-        while (hashMapIterator_hasNext(&iter)) {
-            auto *entry = static_cast<psa_nanomsg_serializer_entry_t*>(hashMapIterator_nextValue(&iter));
-            free(entry);
+        // todo: do not use pointer but type in map
+        for(auto kv: serializers.map) {
+            free(kv.second);
         }
     }
 
@@ -158,8 +156,6 @@ pubsub_nanomsg_admin::~pubsub_nanomsg_admin() {
 
     hashMap_destroy(discoveredEndpoints.map, false, false);
 
-    hashMap_destroy(serializers.map, false, false);
-
     free(ipAddress);
 
 }
@@ -256,13 +252,13 @@ void pubsub_nanomsg_admin::addSerializerSvc(void *svc, const celix_properties_t
 
     {
         std::lock_guard<std::mutex> lock(serializers.mutex);
-        auto *entry = static_cast<psa_nanomsg_serializer_entry_t*>(hashMap_get(serializers.map,
(void*)svcId));
-        if (entry == nullptr) {
-            entry = static_cast<psa_nanomsg_serializer_entry_t*>(calloc(1, sizeof(*entry)));
+        auto it = serializers.map.find(svcId);
+        if (it == serializers.map.end()) {
+            auto entry = static_cast<psa_nanomsg_serializer_entry_t*>(calloc(1, sizeof(psa_nanomsg_serializer_entry_t)));
             entry->serType = serType;
             entry->svcId = svcId;
             entry->svc = static_cast<pubsub_serializer_service_t*>(svc);
-            hashMap_put(serializers.map, (void*)svcId, entry);
+            serializers.map[svcId] = entry;
         }
     }
 }
@@ -278,7 +274,13 @@ void pubsub_nanomsg_admin::removeSerializerSvc(void */*svc*/, const celix_proper
     // Note that it is the responsibility of the topology manager to create new topic senders/receivers
 
     std::lock_guard<std::mutex> lock(serializers.mutex);
-    auto *entry = static_cast<psa_nanomsg_serializer_entry_t*>(hashMap_remove(serializers.map,
(void*)svcId));
+
+    psa_nanomsg_serializer_entry_t* entry = nullptr;
+    auto kv = serializers.map.find(svcId);
+    if (kv != serializers.map.end()) {
+        entry = kv->second;
+    }
+    serializers.map.erase(svcId);
     if (entry != nullptr) {
         {
             std::lock_guard<std::mutex> senderLock(topicSenders.mutex);
@@ -365,8 +367,13 @@ celix_status_t pubsub_nanomsg_admin::setupTopicSender(const char *scope,
const c
     std::lock_guard<std::mutex> topicSenderLock(topicSenders.mutex);
     sender = static_cast<pubsub_nanomsg_topic_sender_t *>(hashMap_get(topicSenders.map,
key));
     if (sender == nullptr) {
-        auto *serEntry = static_cast<psa_nanomsg_serializer_entry_t *>(hashMap_get(serializers.map,
-                                                                                   (void
*) serializerSvcId));
+        //auto *serEntry = static_cast<psa_nanomsg_serializer_entry_t *>(hashMap_get(serializers.map,
+        //                                                                           (void
*) serializerSvcId));
+        psa_nanomsg_serializer_entry_t *serEntry = nullptr;
+        auto kv = serializers.map.find(serializerSvcId);
+        if (kv != serializers.map.end()) {
+            serEntry = kv->second;
+        }
         if (serEntry != nullptr) {
             sender = pubsub_nanoMsgTopicSender_create(ctx, log, scope, topic, serializerSvcId,
serEntry->svc, ipAddress,
                                                       basePort, maxPort);
@@ -437,16 +444,16 @@ celix_status_t pubsub_nanomsg_admin::setupTopicReceiver(const char *scope,
const
         std::lock_guard<std::mutex> topicReceiverLock(topicReceivers.mutex);
         receiver = static_cast<pubsub_nanomsg_topic_receiver_t *>(hashMap_get(topicReceivers.map,
key));
         if (receiver == nullptr) {
-            auto *serEntry = static_cast<psa_nanomsg_serializer_entry_t *>(hashMap_get(serializers.map,
-                                                                                       (void
*) serializerSvcId));
-            if (serEntry != nullptr) {
+            auto kv = serializers.map.find(serializerSvcId);
+            if (kv != serializers.map.end()) {
+                auto serEntry = kv->second;
                 receiver = pubsub_nanoMsgTopicReceiver_create(ctx, log, scope, topic, serializerSvcId,
serEntry->svc);
             } else {
                 L_ERROR("[PSA_NANOMSG] Cannot find serializer for TopicSender %s/%s", scope,
topic);
             }
             if (receiver != nullptr) {
                 const char *psaType = PUBSUB_NANOMSG_ADMIN_TYPE;
-                const char *serType = serEntry->serType;
+                const char *serType = kv->second->serType;
                 newEndpoint = pubsubEndpoint_create(fwUUID, scope, topic, PUBSUB_SUBSCRIBER_ENDPOINT_TYPE,
psaType,
                                                     serType, nullptr);
                 //if available also set container name
@@ -617,9 +624,10 @@ celix_status_t pubsub_nanomsg_admin::executeCommand(char *commandLine
__attribut
             pubsub_nanomsg_topic_sender_t *sender = static_cast<pubsub_nanomsg_topic_sender_t
*>(hashMapIterator_nextValue(
                     &iter));
             long serSvcId = pubsub_nanoMsgTopicSender_serializerSvcId(sender);
-            psa_nanomsg_serializer_entry_t *serEntry = static_cast<psa_nanomsg_serializer_entry_t
*>(hashMap_get(
-                    serializers.map, (void *) serSvcId));
-            const char *serType = serEntry == nullptr ? "!Error!" : serEntry->serType;
+            auto kv = serializers.map.find(serSvcId);
+            //psa_nanomsg_serializer_entry_t *serEntry = static_cast<psa_nanomsg_serializer_entry_t
*>(hashMap_get(
+            //        serializers.map, (void *) serSvcId));
+            const char *serType = kv->second == nullptr ? "!Error!" : kv->second->serType;
             const char *scope = pubsub_nanoMsgTopicSender_scope(sender);
             const char *topic = pubsub_nanoMsgTopicSender_topic(sender);
             const char *url = pubsub_nanoMsgTopicSender_url(sender);
@@ -639,9 +647,8 @@ celix_status_t pubsub_nanomsg_admin::executeCommand(char *commandLine
__attribut
             pubsub_nanomsg_topic_receiver_t *receiver = static_cast<pubsub_nanomsg_topic_receiver_t
*>(hashMapIterator_nextValue(
                     &iter));
             long serSvcId = pubsub_nanoMsgTopicReceiver_serializerSvcId(receiver);
-            psa_nanomsg_serializer_entry_t *serEntry = static_cast<psa_nanomsg_serializer_entry_t
*>(hashMap_get(
-                    serializers.map, (void *) serSvcId));
-            const char *serType = serEntry == nullptr ? "!Error!" : serEntry->serType;
+            auto kv =  serializers.map.find(serSvcId);
+            const char *serType = kv->second == nullptr ? "!Error!" : kv->second->serType;
             const char *scope = pubsub_nanoMsgTopicReceiver_scope(receiver);
             const char *topic = pubsub_nanoMsgTopicReceiver_topic(receiver);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/3009e647/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.h
----------------------------------------------------------------------
diff --git a/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.h b/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.h
index b06c887..98314b3 100644
--- a/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.h
+++ b/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_admin.h
@@ -21,10 +21,13 @@
 #define CELIX_PUBSUB_ZMQ_ADMIN_H
 
 #include <mutex>
+#include <map>
 #include <pubsub_admin.h>
 #include "celix_api.h"
 #include "log_helper.h"
 #include "pubsub_nanomsg_topic_receiver.h"
+#include <pubsub_serializer.h>
+
 #include "../../../shell/shell/include/command.h"
 
 #define PUBSUB_NANOMSG_ADMIN_TYPE       "zmq"
@@ -98,9 +101,15 @@ private:
 
     bool verbose{};
 
+    typedef struct psa_nanomsg_serializer_entry {
+        const char *serType;
+        long svcId;
+        pubsub_serializer_service_t *svc;
+    } psa_nanomsg_serializer_entry_t;
     struct {
         std::mutex mutex;
-        hash_map_t *map; //key = svcId, value = psa_nanomsg_serializer_entry_t*
+        std::map<long, psa_nanomsg_serializer_entry_t*> map;
+        //hash_map_t *map; //key = svcId, value = psa_nanomsg_serializer_entry_t*
     } serializers{};
 
     struct {

http://git-wip-us.apache.org/repos/asf/celix/blob/3009e647/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_topic_receiver.h
----------------------------------------------------------------------
diff --git a/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_topic_receiver.h b/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_topic_receiver.h
index 786fb90..d584db8 100644
--- a/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_topic_receiver.h
+++ b/bundles/pubsub/pubsub_admin_nanomsg/src/pubsub_nanomsg_topic_receiver.h
@@ -20,7 +20,8 @@
 #define CELIX_PUBSUB_NANOMSG_TOPIC_RECEIVER_H
 #include <string>
 #include <vector>
-
+#include "pubsub_serializer.h"
+#include "log_helper.h"
 #include "celix_bundle_context.h"
 
 typedef struct pubsub_nanomsg_topic_receiver pubsub_nanomsg_topic_receiver_t;


Mime
View raw message