Index: ChangeLog
===================================================================
--- ChangeLog	(revision 4311)
+++ ChangeLog	(revision 4343)
@@ -7,4 +7,5 @@
 	* Added a lot const keywords
 	* Added notify framework (process internal signals)
+	* Added support for WAIT command
 
 v. 0.3 - Sun Aug 22 2010 26:14 CEST
Index: roard/clients.c
===================================================================
--- roard/clients.c	(revision 4326)
+++ roard/clients.c	(revision 4343)
@@ -84,4 +84,7 @@
     }
 
+    ns->blockc   = 0;
+    ns->waits    = NULL;
+
     g_clients[i] = ns;
 
@@ -277,4 +280,17 @@
  return 0;
 }
+
+int clients_block      (int id, int unblock) {
+ _CHECK_CID(id);
+
+ if ( unblock ) {
+  g_clients[id]->blockc--;
+ } else {
+  g_clients[id]->blockc++;
+ }
+
+ return 0;
+}
+
 
 #define MAX_STREAMLESS 8
@@ -491,5 +507,6 @@
     ROAR_DBG("clients_check(*): data=%p", data);
 
-    roar_send_message(&con, &m, flags[1] & COMMAND_FLAG_OUT_LONGDATA ? data : NULL);
+    if ( !(flags[1] & COMMAND_FLAG_OUT_NOSEND) )
+     roar_send_message(&con, &m, flags[1] & COMMAND_FLAG_OUT_LONGDATA ? data : NULL);
 
     if ( flags[1] & COMMAND_FLAG_OUT_CLOSECON )
@@ -727,3 +744,84 @@
 }
 
+
+// notify thingys
+int clients_wait    (int client, struct roar_event * events, size_t num) {
+ struct roar_client_server * cs;
+ size_t i, c;
+
+ ROAR_DBG("clients_wait(client=%i, events=%p, num=%llu) = ?", client, events, (long long unsigned int)num);
+
+ _CHECK_CID(client);
+
+ cs = g_clients[client];
+
+ if ( cs->waits != NULL )
+  return -1;
+
+ cs->waits = roar_mm_malloc((num+1) * sizeof(struct roar_subscriber *));
+
+ if ( cs->waits == NULL )
+  return -1;
+
+ if ( clients_block(client, 0) != 0 )
+  return -1;
+
+ for (i = 0; i < num; i++) {
+#if defined(DEBUG) && 0
+  dbg_notify_cb(NULL, &(events[i]), cs);
+#endif
+  cs->waits[i] = roar_notify_core_subscribe(NULL, &(events[i]), clients_ncb_wait, cs);
+  if ( cs->waits[i] == NULL ) {
+   for (c = 0; c < i; c++)
+    roar_notify_core_unsubscribe(NULL, cs->waits[c]);
+   roar_mm_free(cs->waits);
+   cs->waits = NULL;
+   clients_block(client, 1);
+   return -1;
+  }
+ }
+
+ cs->waits[num] = NULL;
+
+ ROAR_DBG("clients_wait(client=%i, events=%p, num=%llu) = 0", client, events, (long long unsigned int)num);
+ return 0;
+}
+
+void clients_ncb_wait(struct roar_notify_core * core, struct roar_event * event, void * userdata) {
+ struct roar_client_server * cs = userdata;
+ struct roar_message m;
+ struct roar_connection con;
+ uint16_t * u16 = (uint16_t *) m.data;
+ size_t tmp;
+ size_t i;
+
+ ROAR_DBG("clients_ncb_wait(core=%p, event=%p, userdata=%p) = ?", core, event, userdata);
+
+ for (i = 0; cs->waits[i] != NULL; i++)
+  roar_notify_core_unsubscribe(NULL, cs->waits[i]);
+
+ roar_mm_free(cs->waits);
+ cs->waits = NULL;
+
+ // protocol depended handling...
+ memset(&m, 0, sizeof(m));
+ m.cmd = ROAR_CMD_OK;
+ u16[0] = ROAR_HOST2NET16(0); // Version
+ u16[1] = ROAR_HOST2NET16(0); // flags
+
+ tmp = sizeof(m.data) - 4;
+
+ roar_event_to_blob(event, m.data + 4, &tmp);
+
+ m.datalen = tmp + 4;
+
+ roar_connect_fh(&con, ROAR_CLIENT(cs)->fh);
+ roar_send_message(&con, &m, NULL);
+ // ...end of protocol depended handling.
+
+// clients_block(, 1);
+ // TODO: FIXME: bad hack...
+ cs->blockc--;
+}
+
 //ll
Index: roard/commands.c
===================================================================
--- roard/commands.c	(revision 4298)
+++ roard/commands.c	(revision 4343)
@@ -73,4 +73,6 @@
   {ROAR_CMD_BEEP,         _NAME("BEEP"),         req_on_beep},
 
+  {ROAR_CMD_WAIT,         _NAME("WAIT"),         req_on_wait},
+
   {ROAR_CMD_EOL,          _NAME("END OF LIST"),  NULL}
  };
Index: roard/include/client.h
===================================================================
--- roard/include/client.h	(revision 4326)
+++ roard/include/client.h	(revision 4343)
@@ -47,11 +47,16 @@
 */
 
+struct roar_client_nsubscribe {
+ struct roar_subscriber * sub;
+};
+
 struct roar_client_server {
  struct roar_client _client;
+ size_t blockc;
+ struct roar_subscriber ** waits;
 } * g_clients[ROAR_CLIENTS_MAX];
 
 
 // basic functions
-
 int clients_init       (void);
 int clients_free       (void);
@@ -69,4 +74,6 @@
 int clients_get_fh     (int id);
 
+int clients_block      (int id, int unblock);
+
 // network functions
 int clients_check_all  (void);
@@ -76,6 +83,4 @@
 
 // stream functions
-
-
 int client_stream_exec   (int client, int stream);
 int client_stream_set_fh (int client, int stream, int fh);
@@ -84,4 +89,8 @@
 int client_stream_move   (int client, int stream);
 
+// notify thingys
+int  clients_wait    (int client, struct roar_event * events, size_t num);
+void clients_ncb_wait(struct roar_notify_core * core, struct roar_event * event, void * userdata);
+
 #endif
 
Index: roard/include/commands.h
===================================================================
--- roard/include/commands.h	(revision 4297)
+++ roard/include/commands.h	(revision 4343)
@@ -35,4 +35,5 @@
 #define COMMAND_FLAG_OUT_CLOSECON  0x00000001
 #define COMMAND_FLAG_OUT_LONGDATA  0x00000002
+#define COMMAND_FLAG_OUT_NOSEND    0x00000004
 
 struct roar_command {
Index: roard/include/req.h
===================================================================
--- roard/include/req.h	(revision 3926)
+++ roard/include/req.h	(revision 4343)
@@ -73,4 +73,6 @@
 int req_on_beep        (int client, struct roar_message * mes, char ** data, uint32_t flags[2]);
 
+int req_on_wait        (int client, struct roar_message * mes, char ** data, uint32_t flags[2]);
+
 //int req_on_ (int client, struct roar_message * mes, char ** data, uint32_t flags[2]);
 
Index: roard/req.c
===================================================================
--- roard/req.c	(revision 4333)
+++ roard/req.c	(revision 4343)
@@ -1351,3 +1351,45 @@
 }
 
+int req_on_wait        (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
+ uint16_t * u16 = (uint16_t*)mes->data;
+ struct roar_event events[4];
+ size_t left, tmp;
+ size_t num = 0;
+ void * vp = mes->data;
+
+ vp += 4;
+
+ // check for complet header...
+ if ( mes->datalen < 4 )
+  return -1;
+
+ u16[0] = ROAR_NET2HOST16(u16[0]);
+ u16[1] = ROAR_NET2HOST16(u16[1]);
+
+ // do we support version and flags?
+ if ( u16[0] != 0 || u16[1] != 0 )
+  return -1;
+
+ memset(events, 0, sizeof(events));
+
+ left = mes->datalen - 4;
+
+ while (left) {
+  tmp = left;
+  if ( roar_event_from_blob(&(events[num]), vp, &tmp) == -1 )
+   return -1;
+
+  vp   += tmp;
+  left -= tmp;
+  num++;
+ }
+
+ if ( clients_wait(client, events, num) == -1 )
+  return -1;
+
+ flags[1] |= COMMAND_FLAG_OUT_NOSEND;
+
+ return 0;
+}
+
 //ll
