social: app connected callback
authorGabor X Toth <*@tg-x.net>
Thu, 5 May 2016 11:33:40 +0000 (11:33 +0000)
committerGabor X Toth <*@tg-x.net>
Thu, 5 May 2016 11:33:40 +0000 (11:33 +0000)
src/include/gnunet_protocols.h
src/include/gnunet_social_service.h
src/social/gnunet-service-social.c
src/social/social_api.c
src/social/test_social.c

index a492e4dd791029c517874e95db264c2a2b6b985f..8a429ba4169acdb9e5300e979e4440f83f894452 100644 (file)
@@ -2643,8 +2643,14 @@ extern "C"
 /** S->C: notify about an existing ego */
 #define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 853
 
+/** S->C: end of ego list */
+#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END 854
+
 /** S->C: notify about an existing place */
-#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 854
+#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 855
+
+/** S->C: end of place list */
+#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END 856
 
 /** C->S: set message processing flags */
 #define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 860
index 88ebc3dad0f2b7196da06da0896ce14d986682b3..e93436e9648b3cd046474703c87bd25e426116d4 100644 (file)
@@ -333,6 +333,13 @@ enum GNUNET_SOCIAL_AppPlaceState
 };
 
 
+/**
+ * Called after receiving initial list of egos and places.
+ */
+typedef void
+(*GNUNET_SOCIAL_AppConnectedCallback) (void *cls);
+
+
 /**
  * Notification about a home.
  *
@@ -402,6 +409,7 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
                            GNUNET_SOCIAL_AppEgoCallback ego_cb,
                            GNUNET_SOCIAL_AppHostPlaceCallback host_cb,
                            GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb,
+                           GNUNET_SOCIAL_AppConnectedCallback connected_cb,
                            void *cls);
 
 
index 03a113d7e768b2e2dfeb9c16fb16877c8a13ec62..e2d6544c114a5ff2d025c3185696524ca7a7ded9 100644 (file)
@@ -432,7 +432,7 @@ place_entry_cleanup (void *cls,
                      void *value)
 {
   struct Place *plc = value;
-  
+
   cleanup_place (plc);
   return GNUNET_YES;
 }
@@ -538,7 +538,7 @@ static void
 cleanup_place (void *cls)
 {
   struct Place *plc = cls;
-  
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "%p Cleaning up place %s\n",
               plc, GNUNET_h2s (&plc->pub_key_hash));
@@ -1944,6 +1944,21 @@ app_notify_place (struct GNUNET_MessageHeader *msg,
 }
 
 
+void
+app_notify_place_end (struct GNUNET_SERVER_Client *client)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "%p Sending end of place list notification to client\n",
+              client);
+
+  struct GNUNET_MessageHeader msg;
+  msg.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END);
+  msg.size = htons (sizeof (msg));
+
+  client_send_msg (client, &msg);
+}
+
+
 void
 app_notify_ego (struct Ego *ego, struct GNUNET_SERVER_Client *client)
 {
@@ -1964,6 +1979,21 @@ app_notify_ego (struct Ego *ego, struct GNUNET_SERVER_Client *client)
 }
 
 
+void
+app_notify_ego_end (struct GNUNET_SERVER_Client *client)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "%p Sending end of ego list notification to client\n",
+              client);
+
+  struct GNUNET_MessageHeader msg;
+  msg.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END);
+  msg.size = htons (sizeof (msg));
+
+  client_send_msg (client, &msg);
+}
+
+
 int
 app_place_entry_notify (void *cls, const struct GNUNET_HashCode *key, void *value)
 {
@@ -2008,11 +2038,13 @@ client_recv_app_connect (void *cls, struct GNUNET_SERVER_Client *client,
   GNUNET_CRYPTO_hash (app_id, app_id_size, &app_id_hash);
 
   GNUNET_CONTAINER_multihashmap_iterate (egos, ego_entry, client);
+  app_notify_ego_end (client);
 
   struct GNUNET_CONTAINER_MultiHashMap *
     app_places = GNUNET_CONTAINER_multihashmap_get (apps_places, &app_id_hash);
   if (NULL != app_places)
     GNUNET_CONTAINER_multihashmap_iterate (app_places, app_place_entry_notify, client);
+  app_notify_place_end (client);
 
   struct ClientListItem *cli = GNUNET_new (struct ClientListItem);
   cli->client = client;
index edda0203e9be0f8cf691d12edaa832778ddce65c..d2428893df680fbd261030ef9a81189a4a31a406 100644 (file)
@@ -102,6 +102,7 @@ struct GNUNET_SOCIAL_App
   GNUNET_SOCIAL_AppEgoCallback ego_cb;
   GNUNET_SOCIAL_AppHostPlaceCallback host_cb;
   GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb;
+  GNUNET_SOCIAL_AppConnectedCallback connected_cb;
   void *cb_cls;
 };
 
@@ -924,6 +925,16 @@ app_recv_ego (void *cls,
 }
 
 
+static void
+app_recv_ego_end (void *cls,
+                  struct GNUNET_CLIENT_MANAGER_Connection *client,
+                  const struct GNUNET_MessageHeader *msg)
+{
+  struct GNUNET_SOCIAL_App *
+    app = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*app));
+}
+
+
 static void
 app_recv_place (void *cls,
                 struct GNUNET_CLIENT_MANAGER_Connection *client,
@@ -955,18 +966,33 @@ app_recv_place (void *cls,
     struct GNUNET_SOCIAL_HostConnection *hconn = GNUNET_malloc (sizeof (*hconn));
     hconn->app = app;
     hconn->plc_msg = *pmsg;
-    app->host_cb (app->cb_cls, hconn, ego, &pmsg->place_pub_key, pmsg->place_state);
+    if (NULL != app->host_cb)
+      app->host_cb (app->cb_cls, hconn, ego, &pmsg->place_pub_key, pmsg->place_state);
   }
   else
   {
     struct GNUNET_SOCIAL_GuestConnection *gconn = GNUNET_malloc (sizeof (*gconn));
     gconn->app = app;
     gconn->plc_msg = *pmsg;
-    app->guest_cb (app->cb_cls, gconn, ego, &pmsg->place_pub_key, pmsg->place_state);
+    if (NULL != app->guest_cb)
+      app->guest_cb (app->cb_cls, gconn, ego, &pmsg->place_pub_key, pmsg->place_state);
   }
 }
 
 
+static void
+app_recv_place_end (void *cls,
+                  struct GNUNET_CLIENT_MANAGER_Connection *client,
+                  const struct GNUNET_MessageHeader *msg)
+{
+  struct GNUNET_SOCIAL_App *
+    app = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*app));
+
+  if (NULL != app->connected_cb)
+    app->connected_cb (app->cb_cls);
+}
+
+
 static struct GNUNET_CLIENT_MANAGER_MessageHandler host_handlers[] =
 {
   { host_recv_enter_ack, NULL,
@@ -1049,10 +1075,18 @@ static struct GNUNET_CLIENT_MANAGER_MessageHandler app_handlers[] =
     GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO,
     sizeof (struct AppEgoMessage), GNUNET_YES },
 
+  { app_recv_ego_end, NULL,
+    GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END,
+    sizeof (struct GNUNET_MessageHeader), GNUNET_NO },
+
   { app_recv_place, NULL,
     GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE,
     sizeof (struct AppPlaceMessage), GNUNET_NO },
 
+  { app_recv_place_end, NULL,
+    GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END,
+    sizeof (struct GNUNET_MessageHeader), GNUNET_NO },
+
   { app_recv_result, NULL,
     GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE,
     sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES },
@@ -2426,6 +2460,7 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
                            GNUNET_SOCIAL_AppEgoCallback ego_cb,
                            GNUNET_SOCIAL_AppHostPlaceCallback host_cb,
                            GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb,
+                           GNUNET_SOCIAL_AppConnectedCallback connected_cb,
                            void *cls)
 {
   uint16_t app_id_size = strnlen (id, GNUNET_SOCIAL_APP_MAX_ID_SIZE);
@@ -2438,6 +2473,7 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
   app->ego_cb = ego_cb;
   app->host_cb = host_cb;
   app->guest_cb = guest_cb;
+  app->connected_cb = connected_cb;
   app->cb_cls = cls;
   app->egos = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
   app->client = GNUNET_CLIENT_MANAGER_connect (cfg, "social",
index d781561e5d34866ef43ab5507817168eebad90d7..9c07a7be6b8651c865ae0660f1e46a956c9fd0d6 100644 (file)
@@ -50,7 +50,7 @@ const char *app_id = "test";
 /**
  * Handle for task for timeout termination.
  */
-struct GNUNET_SCHEDULER_Task * end_badly_task;
+struct GNUNET_SCHEDULER_Task *end_badly_task;
 
 const struct GNUNET_CONFIGURATION_Handle *cfg;
 
@@ -399,6 +399,14 @@ guest_reconnected (void *cls, int result,
 }
 
 
+static void
+app_connected (void *cls)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "App connected: %p\n", cls);
+}
+
+
 static void
 app_recv_host (void *cls,
                struct GNUNET_SOCIAL_HostConnection *hconn,
@@ -492,6 +500,7 @@ schedule_reconnect (void *cls)
                                    app_recv_ego,
                                    app_recv_host,
                                    app_recv_guest,
+                                   app_connected,
                                    NULL);
 }