Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5576)
+++ ChangeLog	(revision 5579)
@@ -9,4 +9,5 @@
 	  support them (Closes: #274)
 	* Support a common protocol interface (Closes: #257)
+	* Converted roard plugins to universal where possible (Closes: #256)
 
 v. 1.0beta3 - Sun Jul 15 2012 26:08 CEST
Index: plugins/roard/Makefile
===================================================================
--- plugins/roard/Makefile	(revision 5565)
+++ plugins/roard/Makefile	(revision 5579)
@@ -2,5 +2,5 @@
 include ../../Makefile.inc
 
-TARGETS=protocol-echo$(SHARED_SUFFIX) protocol-daytime$(SHARED_SUFFIX) protocol-discard$(SHARED_SUFFIX) protocol-irc$(SHARED_SUFFIX) tic-tac-toe$(SHARED_SUFFIX) listenpty$(SHARED_SUFFIX)
+TARGETS=protocol-irc$(SHARED_SUFFIX) listenpty$(SHARED_SUFFIX)
 
 #DEFINES        = -DDEBUG
Index: plugins/universal/Makefile
===================================================================
--- plugins/universal/Makefile	(revision 5478)
+++ plugins/universal/Makefile	(revision 5579)
@@ -2,5 +2,7 @@
 include ../../Makefile.inc
 
-TARGETS=plugin-info$(SHARED_SUFFIX) helloworld$(SHARED_SUFFIX)
+TARGETS_PROTO=protocol-echo$(SHARED_SUFFIX) protocol-daytime$(SHARED_SUFFIX) protocol-discard$(SHARED_SUFFIX) tic-tac-toe$(SHARED_SUFFIX)
+TARGETS_MISC=plugin-info$(SHARED_SUFFIX) helloworld$(SHARED_SUFFIX)
+TARGETS=$(TARGETS_MISC) $(TARGETS_PROTO)
 
 #DEFINES        = -DDEBUG
Index: plugins/universal/protocol-daytime.c
===================================================================
--- plugins/universal/protocol-daytime.c	(revision 5444)
+++ plugins/universal/protocol-daytime.c	(revision 5579)
@@ -24,7 +24,7 @@
  */
 
-#include <roard/include/roard.h>
+#include <roaraudio.h>
 
-int new_client(int client, struct roar_vio_calls * vio, struct roard_listen * lsock) {
+static int _set_proto(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
  struct roar_buffer * buf;
  void * data;
@@ -33,7 +33,5 @@
  char * date = asctime(gmtime(&now));
 
- (void)vio, (void)lsock;
-
- ROAR_DBG("new_client(client=%i, vio=%p, lsock=%p) = ?", client, vio, lsock);
+ (void)client, (void)vio, (void)userdata, (void)para, (void)paralen;
 
  len = roar_mm_strlen(date) + 1;
@@ -44,27 +42,40 @@
  memcpy(data, date, len);
 
- clients_add_output(client, &buf);
-
- ROAR_DBG("new_client(client=%i, vio=%p, lsock=%p) = 0", client, vio, lsock);
- return 0;
-}
-
-static int flushed_client(int client, struct roar_vio_calls * vio) {
- (void)vio;
-
- clients_delete(client);
+ if ( *obuffer == NULL ) {
+  *obuffer = buf;
+ } else {
+  if ( roar_buffer_moveinto(*obuffer, &buf) == -1 )
+   return -1;
+ }
 
  return 0;
 }
 
-static struct roard_proto proto[1] = {
- {ROAR_PROTO_DAYTIME, ROAR_SUBSYS_NONE, "The Internet daytime protocol", NULL, new_client, NULL, NULL, NULL, flushed_client}
+static int _flushed(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
+ (void)client, (void)vio, (void)obuffer, (void)userdata, (void)para, (void)paralen;
+
+ roar_err_set(ROAR_ERROR_NODATA);
+ return -1;
+}
+
+static const struct roar_dl_proto proto = {
+ .proto = ROAR_PROTO_DAYTIME,
+ .description = "The Internet daytime protocol",
+ .flags = ROAR_DL_PROTO_FLAGS_NONE,
+ .set_proto = _set_proto,
+ .unset_proto = NULL,
+ .handle = NULL,
+ .flush = NULL,
+ .flushed = _flushed,
+ .status = NULL
 };
 
-ROARD_DL_REG_PROTO(proto)
+static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) {
+ (void)para, (void)lib;
+ ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION);
+ return 0;
+}
 
 ROAR_DL_PLUGIN_START(protocol_daytime) {
- ROARD_DL_CHECK_VERSIONS();
-
  ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-daytime", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
  ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
@@ -73,5 +84,5 @@
  ROAR_DL_PLUGIN_META_DESC("Implementation of the Internet daytime protocol");
 
- ROARD_DL_REGFN_PROTO();
+ ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto);
 } ROAR_DL_PLUGIN_END
 
Index: plugins/universal/protocol-discard.c
===================================================================
--- plugins/universal/protocol-discard.c	(revision 5444)
+++ plugins/universal/protocol-discard.c	(revision 5579)
@@ -24,30 +24,37 @@
  */
 
-#include <roard/include/roard.h>
+#include <roaraudio.h>
 
-static int check_client(int client, struct roar_vio_calls * vio) {
+static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
  char buf[4096];
 
- ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio);
+ (void)client, (void)obuffer, (void)userdata, (void)para, (void)paralen;
 
  if ( roar_vio_read(vio, buf, sizeof(buf)) < 1 ) {
-  clients_delete(client);
   return -1;
  }
 
- ROAR_DBG("check_client(client=%i, vio=%p) = 0", client, vio);
  return 0;
 }
 
-
-static struct roard_proto proto[1] = {
- {ROAR_PROTO_DISCARD, ROAR_SUBSYS_NONE, "Discard all data send to the server", NULL, NULL, NULL, check_client, NULL, NULL}
+static const struct roar_dl_proto proto = {
+ .proto = ROAR_PROTO_DISCARD,
+ .description = "Discard all data send to the server",
+ .flags = ROAR_DL_PROTO_FLAGS_NONE,
+ .set_proto = NULL,
+ .unset_proto = NULL,
+ .handle = _handle,
+ .flush = NULL,
+ .flushed = NULL,
+ .status = NULL
 };
 
-ROARD_DL_REG_PROTO(proto)
+static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) {
+ (void)para, (void)lib;
+ ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION);
+ return 0;
+}
 
 ROAR_DL_PLUGIN_START(protocol_discard) {
- ROARD_DL_CHECK_VERSIONS();
-
  ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-discard", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
  ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
@@ -56,5 +63,5 @@
  ROAR_DL_PLUGIN_META_DESC("Implementation of a dummy protocol discarding all data");
 
- ROARD_DL_REGFN_PROTO();
+ ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto);
 } ROAR_DL_PLUGIN_END
 
Index: plugins/universal/protocol-echo.c
===================================================================
--- plugins/universal/protocol-echo.c	(revision 5444)
+++ plugins/universal/protocol-echo.c	(revision 5579)
@@ -24,12 +24,14 @@
  */
 
-#include <roard/include/roard.h>
+#include <roaraudio.h>
 
-static int check_client(int client, struct roar_vio_calls * vio) {
+static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
  struct roar_buffer * buf;
  void * data;
  ssize_t len;
 
- ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio);
+ (void)client, (void)userdata, (void)para, (void)paralen;
+
+ ROAR_DBG("_handle(client=%i, vio=%p) = ?", client, vio);
 
  if ( roar_buffer_new_data(&buf, 1024, &data) == -1 )
@@ -37,32 +39,48 @@
 
  len = roar_vio_read(vio, data, 1024);
-
  if ( len < 1 ) {
-  clients_delete(client);
+  ROAR_DBG("_handle(client=%i, vio=%p) = -1 // error=%s(%i)", client, vio, roar_errorstring, roar_error);
   return -1;
  }
 
  if ( roar_buffer_set_len(buf, len) == -1 ) {
+  ROAR_DBG("_handle(client=%i, vio=%p) = -1 // error=%s(%i)", client, vio, roar_errorstring, roar_error);
   roar_buffer_free(buf);
-  clients_delete(client);
   return -1;
  }
 
- clients_add_output(client, &buf);
+ if ( *obuffer == NULL ) {
+  *obuffer = buf;
+ } else {
+  if ( roar_buffer_moveinto(*obuffer, &buf) == -1 ) {
+   ROAR_DBG("_handle(client=%i, vio=%p) = -1 // error=%s(%i)", client, vio, roar_errorstring, roar_error);
+   return -1;
+  }
+ }
 
- ROAR_DBG("check_client(client=%i, vio=%p) = 0", client, vio);
+ ROAR_DBG("_handle(client=%i, vio=%p) = 0", client, vio);
  return 0;
 }
 
 
-static struct roard_proto proto[1] = {
- {ROAR_PROTO_ECHO, ROAR_SUBSYS_NONE, "Send all data send to the server back to the client", NULL, NULL, NULL, check_client, NULL, NULL}
+static const struct roar_dl_proto proto = {
+ .proto = ROAR_PROTO_ECHO,
+ .description = "Send all data send to the server back to the client",
+ .flags = ROAR_DL_PROTO_FLAGS_NONE,
+ .set_proto = NULL,
+ .unset_proto = NULL,
+ .handle = _handle,
+ .flush = NULL,
+ .flushed = NULL,
+ .status = NULL
 };
 
-ROARD_DL_REG_PROTO(proto)
+static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) {
+ (void)para, (void)lib;
+ ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION);
+ return 0;
+}
 
 ROAR_DL_PLUGIN_START(protocol_echo) {
- ROARD_DL_CHECK_VERSIONS();
-
  ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-echo", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
  ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
@@ -71,5 +89,5 @@
  ROAR_DL_PLUGIN_META_DESC("Implementation of a dummy protocol sending all data back to the sender");
 
- ROARD_DL_REGFN_PROTO();
+ ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto);
 } ROAR_DL_PLUGIN_END
 
Index: plugins/universal/tic-tac-toe.c
===================================================================
--- plugins/universal/tic-tac-toe.c	(revision 5569)
+++ plugins/universal/tic-tac-toe.c	(revision 5579)
@@ -24,5 +24,5 @@
  */
 
-#include <roard/include/roard.h>
+#include <roaraudio.h>
 
 #define _FREE     ' '
@@ -89,4 +89,14 @@
 };
 
+static inline int __movein(struct roar_buffer ** buf, struct roar_buffer ** next) {
+ if ( *buf == NULL ) {
+  *buf = *next;
+  *next = NULL;
+  return 0;
+ } else {
+  return roar_buffer_moveinto(*buf, next);
+ }
+}
+
 static void new_game(game_state * state) {
  memset(state, _FREE, sizeof(game_state));
@@ -211,5 +221,5 @@
 }
 
-static void draw_help(int client) {
+static void draw_help(struct roar_buffer ** obuffer) {
  struct roar_buffer * buf;
  ssize_t len = 0;
@@ -225,11 +235,10 @@
  if ( roar_buffer_set_len(buf, len) == -1 ) {
   roar_buffer_free(buf);
-  clients_delete(client);
- }
-
- clients_add_output(client, &buf);
-}
-
-static void draw_game(int client, game_state * state, const char * info) {
+ }
+
+ __movein(obuffer, &buf);
+}
+
+static void draw_game(game_state * state, const char * info, struct roar_buffer ** obuffer) {
  struct roar_buffer * buf;
  ssize_t len = 0;
@@ -249,18 +258,13 @@
  if ( roar_buffer_set_len(buf, len) == -1 ) {
   roar_buffer_free(buf);
-  clients_delete(client);
- }
-
- clients_add_output(client, &buf);
-}
-
-int new_client(int client, struct roar_vio_calls * vio, struct roard_listen * lsock) {
- struct roar_client_server * cs;
+ }
+
+ __movein(obuffer, &buf);
+}
+
+static int _set_proto(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
  game_state * state;
 
- (void)vio, (void)lsock;
-
- if ( clients_get_server(client, &cs) == -1 )
-  return -1;
+ (void)client, (void)vio, (void)obuffer, (void)para, (void)paralen;
 
  state = roar_mm_malloc(sizeof(game_state));
@@ -270,7 +274,7 @@
  new_game(state);
 
- cs->protoinst = state;
-
- draw_game(client, state, MSG__YOUR_TURN);
+ *userdata = state;
+
+ draw_game(state, MSG__YOUR_TURN, obuffer);
  return 0;
 }
@@ -307,6 +311,5 @@
 }
 
-static int check_client(int client, struct roar_vio_calls * vio) {
- struct roar_client_server * cs;
+static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
  char buf[32];
  ssize_t len;
@@ -317,24 +320,21 @@
  char c;
 
+ (void)client, (void)obuffer, (void)para, (void)paralen;
+
  ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio);
 
- if ( clients_get_server(client, &cs) == -1 )
+ len = roar_vio_read(vio, buf, sizeof(buf));
+
+ if ( len < 1 ) {
   return -1;
-
- len = roar_vio_read(vio, buf, sizeof(buf));
-
- if ( len < 1 ) {
-  clients_delete(client);
-  return -1;
- }
-
- if ( check_won(cs->protoinst) ) {
+ }
+
+ if ( check_won(*userdata) ) {
   for (i = 0; i < len; i++) {
    if ( map_input(buf[i]) == 'q' ) {
-    clients_delete(client);
     return -1;
    } else {
-    new_game(cs->protoinst);
-    draw_game(client, cs->protoinst, MSG__YOUR_TURN);
+    new_game(*userdata);
+    draw_game(*userdata, MSG__YOUR_TURN, obuffer);
     return 0;
    }
@@ -346,25 +346,24 @@
   switch (c) {
    case 'q':
-     clients_delete(client);
      return -1;
     break;
    case 'n':
-     new_game(cs->protoinst);
-     draw_game(client, cs->protoinst, MSG__YOUR_TURN);
+     new_game(*userdata);
+     draw_game(*userdata, MSG__YOUR_TURN, obuffer);
      return 0;
     break;
    case 'H':
-     draw_help(client);
+     draw_help(obuffer);
      return 0;
     break;
    case 'e':
-     draw_game(client, cs->protoinst, MSG__YOUR_TURN);
+     draw_game(*userdata, MSG__YOUR_TURN, obuffer);
      return 0;
     break;
    case '0': case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8':
-     if ( try_put(cs->protoinst, c - '0', _PLAYER) == -1 ) {
+     if ( try_put(*userdata, c - '0', _PLAYER) == -1 ) {
       msg = MSG__CANNOT_PUT_HERE;
-      draw_game(client, cs->protoinst, msg);
+      draw_game(*userdata, msg, obuffer);
       return 0;
      } else {
@@ -377,9 +376,9 @@
  }
 
- won = check_won(cs->protoinst);
+ won = check_won(*userdata);
 
  if ( !won && player_move != -1 ) {
-  auto_move(cs->protoinst, player_move);
-  won = check_won(cs->protoinst);
+  auto_move(*userdata, player_move);
+  won = check_won(*userdata);
  }
 
@@ -390,5 +389,5 @@
  }
 
- draw_game(client, cs->protoinst, msg);
+ draw_game(*userdata, msg, obuffer);
 
  ROAR_DBG("check_client(client=%i, vio=%p) = 0", client, vio);
@@ -397,13 +396,23 @@
 
 
-static struct roard_proto proto[1] = {
- {ROAR_PROTO_GAME, ROAR_SUBSYS_NONE, "Simple Tic-Tac-Toe game", NULL, new_client, NULL, check_client, NULL, NULL}
+static const struct roar_dl_proto proto = {
+ .proto = ROAR_PROTO_GAME,
+ .description = "Simple Tic-Tac-Toe game",
+ .flags = ROAR_DL_PROTO_FLAGS_NONE,
+ .set_proto = _set_proto,
+ .unset_proto = NULL,
+ .handle = _handle,
+ .flush = NULL,
+ .flushed = NULL,
+ .status = NULL
 };
 
-ROARD_DL_REG_PROTO(proto)
+static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) {
+ (void)para, (void)lib;
+ ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION);
+ return 0;
+}
 
 ROAR_DL_PLUGIN_START(protocol_tic_tac_toe) {
- ROARD_DL_CHECK_VERSIONS();
-
  ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-tic-tac-toe", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
  ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
@@ -412,5 +421,5 @@
  ROAR_DL_PLUGIN_META_DESC("Implementation of a the well known game Tic-Tac-Toe");
 
- ROARD_DL_REGFN_PROTO();
+ ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto);
 } ROAR_DL_PLUGIN_END
 
