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 #223: Feature/pubsub custom serializers
Date Mon, 18 May 2020 07:45:41 GMT

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



##########
File path: bundles/pubsub/pubsub_utils/src/pubsub_serializer_handler.c
##########
@@ -0,0 +1,360 @@
+/**
+ *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.
+ */
+
+
+#include "pubsub_serializer_handler.h"
+
+#include <string.h>
+
+#include "celix_version.h"
+#include "pubsub_message_serialization_service.h"
+#include "celix_log_helper.h"
+
+#define L_DEBUG(...) \
+    celix_logHelper_debug(handler->logHelper, __VA_ARGS__)
+#define L_INFO(...) \
+    celix_logHelper_info(handler->logHelper, __VA_ARGS__)
+#define L_WARN(...) \
+    celix_logHelper_warning(handler->logHelper, __VA_ARGS__)
+#define L_ERROR(...) \
+    celix_logHelper_error(handler->logHelper, __VA_ARGS__)
+
+typedef struct pubsub_serialization_service_entry {
+    long svcId;
+    const celix_properties_t *properties;
+    uint32_t msgId;
+    celix_version_t* msgVersion;
+    char* msgFqn;
+    pubsub_message_serialization_service_t* svc;
+} pubsub_serialization_service_entry_t;
+
+struct pubsub_serializer_handler {
+    celix_bundle_context_t* ctx;
+    bool backwardCompatible;
+    long serializationSvcTrackerId;
+    celix_log_helper_t *logHelper;
+
+    celix_thread_rwlock_t lock;
+    hash_map_t *serializationServices; //key = msg id, value = sorted array list with pubsub_serialization_service_entry_t*
+};
+
+static void addSvc(void *handle, void* svc, const celix_properties_t *props) {
+    pubsub_serializer_handler_t* handler = handle;
+    pubsub_message_serialization_service_t* serSvc = svc;
+    pubsub_serializerHandler_addSerializationService(handler, serSvc, props);
+}
+
+static void remSvc(void *handle, void* svc, const celix_properties_t *props) {
+    pubsub_serializer_handler_t* handler = handle;
+    pubsub_message_serialization_service_t* serSvc = svc;
+    pubsub_serializerHandler_removeSerializationService(handler, serSvc, props);
+}
+
+int compareEntries(const void *a, const void *b) {
+    const pubsub_serialization_service_entry_t* aEntry = a;
+    const pubsub_serialization_service_entry_t* bEntry = b;
+
+    long servIdA = celix_properties_getAsLong(aEntry->properties, OSGI_FRAMEWORK_SERVICE_ID,
0);
+    long servIdB = celix_properties_getAsLong(bEntry->properties, OSGI_FRAMEWORK_SERVICE_ID,
0);
+
+    long servRankingA = celix_properties_getAsLong(aEntry->properties, OSGI_FRAMEWORK_SERVICE_RANKING,
0);
+    long servRankingB = celix_properties_getAsLong(bEntry->properties, OSGI_FRAMEWORK_SERVICE_RANKING,
0);
+
+    return utils_compareServiceIdsAndRanking(servIdA, servRankingA, servIdB, servRankingB);
+}
+
+static pubsub_serialization_service_entry_t* findEntry(pubsub_serializer_handler_t* handler,
uint32_t msgId) {
+    //NOTE assumes mutex is locked
+    celix_array_list_t* entries = hashMap_get(handler->serializationServices, (void*)(uintptr_t)msgId);
+    if (entries != NULL) {
+        return celix_arrayList_get(entries, 0); //NOTE if entries not null, always at least
1 entry
+    }
+    return NULL;
+}
+
+static bool isCompatible(pubsub_serializer_handler_t* handler, pubsub_serialization_service_entry_t*
entry, int serializedMajorVersion, int serializedMinorVersion) {
+    bool compatible = false;
+    if (handler->backwardCompatible) {
+        compatible = celix_version_isUserCompatible(entry->msgVersion, serializedMajorVersion,
serializedMinorVersion);
+    } else {
+        int major = celix_version_getMajor(entry->msgVersion);
+        int minor = celix_version_getMinor(entry->msgVersion);
+        compatible = major == serializedMajorVersion && minor == serializedMinorVersion;

Review comment:
       There is now :)




----------------------------------------------------------------
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