Changeset 5579:3887ff7af8e7 in roaraudio


Ignore:
Timestamp:
07/21/12 19:40:17 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Converted roard plugins to universal where possible (Closes: #256)

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5576 r5579  
    99          support them (Closes: #274) 
    1010        * Support a common protocol interface (Closes: #257) 
     11        * Converted roard plugins to universal where possible (Closes: #256) 
    1112 
    1213v. 1.0beta3 - Sun Jul 15 2012 26:08 CEST 
  • plugins/roard/Makefile

    r5565 r5579  
    22include ../../Makefile.inc 
    33 
    4 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) 
     4TARGETS=protocol-irc$(SHARED_SUFFIX) listenpty$(SHARED_SUFFIX) 
    55 
    66#DEFINES        = -DDEBUG 
  • plugins/universal/Makefile

    r5478 r5579  
    22include ../../Makefile.inc 
    33 
    4 TARGETS=plugin-info$(SHARED_SUFFIX) helloworld$(SHARED_SUFFIX) 
     4TARGETS_PROTO=protocol-echo$(SHARED_SUFFIX) protocol-daytime$(SHARED_SUFFIX) protocol-discard$(SHARED_SUFFIX) tic-tac-toe$(SHARED_SUFFIX) 
     5TARGETS_MISC=plugin-info$(SHARED_SUFFIX) helloworld$(SHARED_SUFFIX) 
     6TARGETS=$(TARGETS_MISC) $(TARGETS_PROTO) 
    57 
    68#DEFINES        = -DDEBUG 
  • plugins/universal/protocol-daytime.c

    r5444 r5579  
    2424 */ 
    2525 
    26 #include <roard/include/roard.h> 
     26#include <roaraudio.h> 
    2727 
    28 int new_client(int client, struct roar_vio_calls * vio, struct roard_listen * lsock) { 
     28static int _set_proto(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 
    2929 struct roar_buffer * buf; 
    3030 void * data; 
     
    3333 char * date = asctime(gmtime(&now)); 
    3434 
    35  (void)vio, (void)lsock; 
    36  
    37  ROAR_DBG("new_client(client=%i, vio=%p, lsock=%p) = ?", client, vio, lsock); 
     35 (void)client, (void)vio, (void)userdata, (void)para, (void)paralen; 
    3836 
    3937 len = roar_mm_strlen(date) + 1; 
     
    4442 memcpy(data, date, len); 
    4543 
    46  clients_add_output(client, &buf); 
    47  
    48  ROAR_DBG("new_client(client=%i, vio=%p, lsock=%p) = 0", client, vio, lsock); 
    49  return 0; 
    50 } 
    51  
    52 static int flushed_client(int client, struct roar_vio_calls * vio) { 
    53  (void)vio; 
    54  
    55  clients_delete(client); 
     44 if ( *obuffer == NULL ) { 
     45  *obuffer = buf; 
     46 } else { 
     47  if ( roar_buffer_moveinto(*obuffer, &buf) == -1 ) 
     48   return -1; 
     49 } 
    5650 
    5751 return 0; 
    5852} 
    5953 
    60 static struct roard_proto proto[1] = { 
    61  {ROAR_PROTO_DAYTIME, ROAR_SUBSYS_NONE, "The Internet daytime protocol", NULL, new_client, NULL, NULL, NULL, flushed_client} 
     54static int _flushed(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 
     55 (void)client, (void)vio, (void)obuffer, (void)userdata, (void)para, (void)paralen; 
     56 
     57 roar_err_set(ROAR_ERROR_NODATA); 
     58 return -1; 
     59} 
     60 
     61static const struct roar_dl_proto proto = { 
     62 .proto = ROAR_PROTO_DAYTIME, 
     63 .description = "The Internet daytime protocol", 
     64 .flags = ROAR_DL_PROTO_FLAGS_NONE, 
     65 .set_proto = _set_proto, 
     66 .unset_proto = NULL, 
     67 .handle = NULL, 
     68 .flush = NULL, 
     69 .flushed = _flushed, 
     70 .status = NULL 
    6271}; 
    6372 
    64 ROARD_DL_REG_PROTO(proto) 
     73static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) { 
     74 (void)para, (void)lib; 
     75 ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION); 
     76 return 0; 
     77} 
    6578 
    6679ROAR_DL_PLUGIN_START(protocol_daytime) { 
    67  ROARD_DL_CHECK_VERSIONS(); 
    68  
    6980 ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-daytime", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); 
    7081 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); 
     
    7384 ROAR_DL_PLUGIN_META_DESC("Implementation of the Internet daytime protocol"); 
    7485 
    75  ROARD_DL_REGFN_PROTO(); 
     86 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); 
    7687} ROAR_DL_PLUGIN_END 
    7788 
  • plugins/universal/protocol-discard.c

    r5444 r5579  
    2424 */ 
    2525 
    26 #include <roard/include/roard.h> 
     26#include <roaraudio.h> 
    2727 
    28 static int check_client(int client, struct roar_vio_calls * vio) { 
     28static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 
    2929 char buf[4096]; 
    3030 
    31  ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio); 
     31 (void)client, (void)obuffer, (void)userdata, (void)para, (void)paralen; 
    3232 
    3333 if ( roar_vio_read(vio, buf, sizeof(buf)) < 1 ) { 
    34   clients_delete(client); 
    3534  return -1; 
    3635 } 
    3736 
    38  ROAR_DBG("check_client(client=%i, vio=%p) = 0", client, vio); 
    3937 return 0; 
    4038} 
    4139 
    42  
    43 static struct roard_proto proto[1] = { 
    44  {ROAR_PROTO_DISCARD, ROAR_SUBSYS_NONE, "Discard all data send to the server", NULL, NULL, NULL, check_client, NULL, NULL} 
     40static const struct roar_dl_proto proto = { 
     41 .proto = ROAR_PROTO_DISCARD, 
     42 .description = "Discard all data send to the server", 
     43 .flags = ROAR_DL_PROTO_FLAGS_NONE, 
     44 .set_proto = NULL, 
     45 .unset_proto = NULL, 
     46 .handle = _handle, 
     47 .flush = NULL, 
     48 .flushed = NULL, 
     49 .status = NULL 
    4550}; 
    4651 
    47 ROARD_DL_REG_PROTO(proto) 
     52static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) { 
     53 (void)para, (void)lib; 
     54 ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION); 
     55 return 0; 
     56} 
    4857 
    4958ROAR_DL_PLUGIN_START(protocol_discard) { 
    50  ROARD_DL_CHECK_VERSIONS(); 
    51  
    5259 ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-discard", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); 
    5360 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); 
     
    5663 ROAR_DL_PLUGIN_META_DESC("Implementation of a dummy protocol discarding all data"); 
    5764 
    58  ROARD_DL_REGFN_PROTO(); 
     65 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); 
    5966} ROAR_DL_PLUGIN_END 
    6067 
  • plugins/universal/protocol-echo.c

    r5444 r5579  
    2424 */ 
    2525 
    26 #include <roard/include/roard.h> 
     26#include <roaraudio.h> 
    2727 
    28 static int check_client(int client, struct roar_vio_calls * vio) { 
     28static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 
    2929 struct roar_buffer * buf; 
    3030 void * data; 
    3131 ssize_t len; 
    3232 
    33  ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio); 
     33 (void)client, (void)userdata, (void)para, (void)paralen; 
     34 
     35 ROAR_DBG("_handle(client=%i, vio=%p) = ?", client, vio); 
    3436 
    3537 if ( roar_buffer_new_data(&buf, 1024, &data) == -1 ) 
     
    3739 
    3840 len = roar_vio_read(vio, data, 1024); 
    39  
    4041 if ( len < 1 ) { 
    41   clients_delete(client); 
     42  ROAR_DBG("_handle(client=%i, vio=%p) = -1 // error=%s(%i)", client, vio, roar_errorstring, roar_error); 
    4243  return -1; 
    4344 } 
    4445 
    4546 if ( roar_buffer_set_len(buf, len) == -1 ) { 
     47  ROAR_DBG("_handle(client=%i, vio=%p) = -1 // error=%s(%i)", client, vio, roar_errorstring, roar_error); 
    4648  roar_buffer_free(buf); 
    47   clients_delete(client); 
    4849  return -1; 
    4950 } 
    5051 
    51  clients_add_output(client, &buf); 
     52 if ( *obuffer == NULL ) { 
     53  *obuffer = buf; 
     54 } else { 
     55  if ( roar_buffer_moveinto(*obuffer, &buf) == -1 ) { 
     56   ROAR_DBG("_handle(client=%i, vio=%p) = -1 // error=%s(%i)", client, vio, roar_errorstring, roar_error); 
     57   return -1; 
     58  } 
     59 } 
    5260 
    53  ROAR_DBG("check_client(client=%i, vio=%p) = 0", client, vio); 
     61 ROAR_DBG("_handle(client=%i, vio=%p) = 0", client, vio); 
    5462 return 0; 
    5563} 
    5664 
    5765 
    58 static struct roard_proto proto[1] = { 
    59  {ROAR_PROTO_ECHO, ROAR_SUBSYS_NONE, "Send all data send to the server back to the client", NULL, NULL, NULL, check_client, NULL, NULL} 
     66static const struct roar_dl_proto proto = { 
     67 .proto = ROAR_PROTO_ECHO, 
     68 .description = "Send all data send to the server back to the client", 
     69 .flags = ROAR_DL_PROTO_FLAGS_NONE, 
     70 .set_proto = NULL, 
     71 .unset_proto = NULL, 
     72 .handle = _handle, 
     73 .flush = NULL, 
     74 .flushed = NULL, 
     75 .status = NULL 
    6076}; 
    6177 
    62 ROARD_DL_REG_PROTO(proto) 
     78static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) { 
     79 (void)para, (void)lib; 
     80 ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION); 
     81 return 0; 
     82} 
    6383 
    6484ROAR_DL_PLUGIN_START(protocol_echo) { 
    65  ROARD_DL_CHECK_VERSIONS(); 
    66  
    6785 ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-echo", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); 
    6886 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); 
     
    7189 ROAR_DL_PLUGIN_META_DESC("Implementation of a dummy protocol sending all data back to the sender"); 
    7290 
    73  ROARD_DL_REGFN_PROTO(); 
     91 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); 
    7492} ROAR_DL_PLUGIN_END 
    7593 
  • plugins/universal/tic-tac-toe.c

    r5569 r5579  
    2424 */ 
    2525 
    26 #include <roard/include/roard.h> 
     26#include <roaraudio.h> 
    2727 
    2828#define _FREE     ' ' 
     
    8989}; 
    9090 
     91static inline int __movein(struct roar_buffer ** buf, struct roar_buffer ** next) { 
     92 if ( *buf == NULL ) { 
     93  *buf = *next; 
     94  *next = NULL; 
     95  return 0; 
     96 } else { 
     97  return roar_buffer_moveinto(*buf, next); 
     98 } 
     99} 
     100 
    91101static void new_game(game_state * state) { 
    92102 memset(state, _FREE, sizeof(game_state)); 
     
    211221} 
    212222 
    213 static void draw_help(int client) { 
     223static void draw_help(struct roar_buffer ** obuffer) { 
    214224 struct roar_buffer * buf; 
    215225 ssize_t len = 0; 
     
    225235 if ( roar_buffer_set_len(buf, len) == -1 ) { 
    226236  roar_buffer_free(buf); 
    227   clients_delete(client); 
    228  } 
    229  
    230  clients_add_output(client, &buf); 
    231 } 
    232  
    233 static void draw_game(int client, game_state * state, const char * info) { 
     237 } 
     238 
     239 __movein(obuffer, &buf); 
     240} 
     241 
     242static void draw_game(game_state * state, const char * info, struct roar_buffer ** obuffer) { 
    234243 struct roar_buffer * buf; 
    235244 ssize_t len = 0; 
     
    249258 if ( roar_buffer_set_len(buf, len) == -1 ) { 
    250259  roar_buffer_free(buf); 
    251   clients_delete(client); 
    252  } 
    253  
    254  clients_add_output(client, &buf); 
    255 } 
    256  
    257 int new_client(int client, struct roar_vio_calls * vio, struct roard_listen * lsock) { 
    258  struct roar_client_server * cs; 
     260 } 
     261 
     262 __movein(obuffer, &buf); 
     263} 
     264 
     265static int _set_proto(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 
    259266 game_state * state; 
    260267 
    261  (void)vio, (void)lsock; 
    262  
    263  if ( clients_get_server(client, &cs) == -1 ) 
    264   return -1; 
     268 (void)client, (void)vio, (void)obuffer, (void)para, (void)paralen; 
    265269 
    266270 state = roar_mm_malloc(sizeof(game_state)); 
     
    270274 new_game(state); 
    271275 
    272  cs->protoinst = state; 
    273  
    274  draw_game(client, state, MSG__YOUR_TURN); 
     276 *userdata = state; 
     277 
     278 draw_game(state, MSG__YOUR_TURN, obuffer); 
    275279 return 0; 
    276280} 
     
    307311} 
    308312 
    309 static int check_client(int client, struct roar_vio_calls * vio) { 
    310  struct roar_client_server * cs; 
     313static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 
    311314 char buf[32]; 
    312315 ssize_t len; 
     
    317320 char c; 
    318321 
     322 (void)client, (void)obuffer, (void)para, (void)paralen; 
     323 
    319324 ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio); 
    320325 
    321  if ( clients_get_server(client, &cs) == -1 ) 
     326 len = roar_vio_read(vio, buf, sizeof(buf)); 
     327 
     328 if ( len < 1 ) { 
    322329  return -1; 
    323  
    324  len = roar_vio_read(vio, buf, sizeof(buf)); 
    325  
    326  if ( len < 1 ) { 
    327   clients_delete(client); 
    328   return -1; 
    329  } 
    330  
    331  if ( check_won(cs->protoinst) ) { 
     330 } 
     331 
     332 if ( check_won(*userdata) ) { 
    332333  for (i = 0; i < len; i++) { 
    333334   if ( map_input(buf[i]) == 'q' ) { 
    334     clients_delete(client); 
    335335    return -1; 
    336336   } else { 
    337     new_game(cs->protoinst); 
    338     draw_game(client, cs->protoinst, MSG__YOUR_TURN); 
     337    new_game(*userdata); 
     338    draw_game(*userdata, MSG__YOUR_TURN, obuffer); 
    339339    return 0; 
    340340   } 
     
    346346  switch (c) { 
    347347   case 'q': 
    348      clients_delete(client); 
    349348     return -1; 
    350349    break; 
    351350   case 'n': 
    352      new_game(cs->protoinst); 
    353      draw_game(client, cs->protoinst, MSG__YOUR_TURN); 
     351     new_game(*userdata); 
     352     draw_game(*userdata, MSG__YOUR_TURN, obuffer); 
    354353     return 0; 
    355354    break; 
    356355   case 'H': 
    357      draw_help(client); 
     356     draw_help(obuffer); 
    358357     return 0; 
    359358    break; 
    360359   case 'e': 
    361      draw_game(client, cs->protoinst, MSG__YOUR_TURN); 
     360     draw_game(*userdata, MSG__YOUR_TURN, obuffer); 
    362361     return 0; 
    363362    break; 
    364363   case '0': case '1': case '2': case '3': case '4': 
    365364   case '5': case '6': case '7': case '8': 
    366      if ( try_put(cs->protoinst, c - '0', _PLAYER) == -1 ) { 
     365     if ( try_put(*userdata, c - '0', _PLAYER) == -1 ) { 
    367366      msg = MSG__CANNOT_PUT_HERE; 
    368       draw_game(client, cs->protoinst, msg); 
     367      draw_game(*userdata, msg, obuffer); 
    369368      return 0; 
    370369     } else { 
     
    377376 } 
    378377 
    379  won = check_won(cs->protoinst); 
     378 won = check_won(*userdata); 
    380379 
    381380 if ( !won && player_move != -1 ) { 
    382   auto_move(cs->protoinst, player_move); 
    383   won = check_won(cs->protoinst); 
     381  auto_move(*userdata, player_move); 
     382  won = check_won(*userdata); 
    384383 } 
    385384 
     
    390389 } 
    391390 
    392  draw_game(client, cs->protoinst, msg); 
     391 draw_game(*userdata, msg, obuffer); 
    393392 
    394393 ROAR_DBG("check_client(client=%i, vio=%p) = 0", client, vio); 
     
    397396 
    398397 
    399 static struct roard_proto proto[1] = { 
    400  {ROAR_PROTO_GAME, ROAR_SUBSYS_NONE, "Simple Tic-Tac-Toe game", NULL, new_client, NULL, check_client, NULL, NULL} 
     398static const struct roar_dl_proto proto = { 
     399 .proto = ROAR_PROTO_GAME, 
     400 .description = "Simple Tic-Tac-Toe game", 
     401 .flags = ROAR_DL_PROTO_FLAGS_NONE, 
     402 .set_proto = _set_proto, 
     403 .unset_proto = NULL, 
     404 .handle = _handle, 
     405 .flush = NULL, 
     406 .flushed = NULL, 
     407 .status = NULL 
    401408}; 
    402409 
    403 ROARD_DL_REG_PROTO(proto) 
     410static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) { 
     411 (void)para, (void)lib; 
     412 ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION); 
     413 return 0; 
     414} 
    404415 
    405416ROAR_DL_PLUGIN_START(protocol_tic_tac_toe) { 
    406  ROARD_DL_CHECK_VERSIONS(); 
    407  
    408417 ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-tic-tac-toe", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); 
    409418 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); 
     
    412421 ROAR_DL_PLUGIN_META_DESC("Implementation of a the well known game Tic-Tac-Toe"); 
    413422 
    414  ROARD_DL_REGFN_PROTO(); 
     423 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); 
    415424} ROAR_DL_PLUGIN_END 
    416425 
Note: See TracChangeset for help on using the changeset viewer.