celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [celix] Oipo commented on a change in pull request #143: Feature/pubsub websocket full duplex communication
Date Sun, 26 Jan 2020 20:56:45 GMT
Oipo commented on a change in pull request #143: Feature/pubsub websocket full duplex communication
URL: https://github.com/apache/celix/pull/143#discussion_r371026726
 
 

 ##########
 File path: bundles/pubsub/examples/pubsub/pubsub_websocket/private/src/pubsub_websocket_example.c
 ##########
 @@ -0,0 +1,209 @@
+/*
+ * 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.
+ */
+/**
+ * pubsub_subscriber.c
+ *
+ *  \date       Sep 21, 2010
+ *  \author     <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright  Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include "poi.h"
+#include "poiCmd.h"
+#include "pubsub_websocket_private.h"
+
+#include "service_tracker.h"
+#include "celix_threads.h"
+
+
+static double randCoordinate(double min, double max) {
+    double ret = min + (((double)random()) / (((double)RAND_MAX)/(max-min)));
+    return ret;
+}
+
+static void* send_thread(void* arg) {
+    send_thread_struct_t *st_struct = (send_thread_struct_t *) arg;
+
+    pubsub_publisher_t *publish_svc = st_struct->service;
+    pubsub_info_t *pubsubInfo = st_struct->pubsub;
+    pubsub_sender_t *publisher = st_struct->pubsub->sender;
+
+    char fwUUID[9];
+    memset(fwUUID, 0, 9);
+    memcpy(fwUUID, publisher->ident, 8);
+
+    //poi_t point = calloc(1,sizeof(*point));
+    location_t place = calloc(1, sizeof(*place));
+
+    char *desc = calloc(64, sizeof(char));
+    snprintf(desc, 64, "fw-%s [TID=%lu]", fwUUID, (unsigned long)pthread_self());
+
+    char *name = calloc(64, sizeof(char));
+    snprintf(name, 64, "Bundle#%ld", publisher->bundleId);
+
+    place->name = name;
+    place->description = desc;
+    place->extra = "extra value";
+    printf("TOPIC : %s\n", st_struct->topic);
+
+    unsigned int msgId = 0;
+
+    while (publisher->stop == false) {
+        if(pubsubInfo->sending) {
+            if (msgId == 0) {
+                if (publish_svc->localMsgTypeIdForMsgType(publish_svc->handle, st_struct->topic,
&msgId) != 0) {
+                    printf("PUBLISHER: Cannot retrieve msgId for message '%s'\n", MSG_POI_NAME);
+                }
+            }
+
+            if (msgId > 0) {
+                place->position.lat = randCoordinate(MIN_LAT, MAX_LAT);
+                place->position.lon = randCoordinate(MIN_LON, MAX_LON);
+                int nr_char = (int) randCoordinate(5, 100000);
+                place->data = calloc(nr_char, 1);
+                for (int i = 0; i < (nr_char - 1); i++) {
+                    place->data[i] = i % 10 + '0';
+                }
+                place->data[nr_char - 1] = '\0';
+                if (publish_svc->send) {
+                    if (publish_svc->send(publish_svc->handle, msgId, place) == 0)
{
+                        printf("Sent %s [%f, %f] (%s, %s) data len = %d\n", st_struct->topic,
+                               place->position.lat, place->position.lon, place->name,
place->description, nr_char);
+                    }
+                } else {
+                    printf("No send for %s\n", st_struct->topic);
+                }
+
+                free(place->data);
+            }
+        }
+        sleep(2);
+    }
+
+    free(place->description);
+    free(place->name);
+    free(place);
+
+//    free(st_struct->pubsub);
 
 Review comment:
   Probably better to remove commented out code.

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


With regards,
Apache Git Services

Mime
View raw message