Changeset 5579:3887ff7af8e7 in roaraudio
- Timestamp:
- 07/21/12 19:40:17 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r5576 r5579 9 9 support them (Closes: #274) 10 10 * Support a common protocol interface (Closes: #257) 11 * Converted roard plugins to universal where possible (Closes: #256) 11 12 12 13 v. 1.0beta3 - Sun Jul 15 2012 26:08 CEST -
plugins/roard/Makefile
r5565 r5579 2 2 include ../../Makefile.inc 3 3 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)4 TARGETS=protocol-irc$(SHARED_SUFFIX) listenpty$(SHARED_SUFFIX) 5 5 6 6 #DEFINES = -DDEBUG -
plugins/universal/Makefile
r5478 r5579 2 2 include ../../Makefile.inc 3 3 4 TARGETS=plugin-info$(SHARED_SUFFIX) helloworld$(SHARED_SUFFIX) 4 TARGETS_PROTO=protocol-echo$(SHARED_SUFFIX) protocol-daytime$(SHARED_SUFFIX) protocol-discard$(SHARED_SUFFIX) tic-tac-toe$(SHARED_SUFFIX) 5 TARGETS_MISC=plugin-info$(SHARED_SUFFIX) helloworld$(SHARED_SUFFIX) 6 TARGETS=$(TARGETS_MISC) $(TARGETS_PROTO) 5 7 6 8 #DEFINES = -DDEBUG -
plugins/universal/protocol-daytime.c
r5444 r5579 24 24 */ 25 25 26 #include <roar d/include/roard.h>26 #include <roaraudio.h> 27 27 28 int new_client(int client, struct roar_vio_calls * vio, struct roard_listen * lsock) {28 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) { 29 29 struct roar_buffer * buf; 30 30 void * data; … … 33 33 char * date = asctime(gmtime(&now)); 34 34 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; 38 36 39 37 len = roar_mm_strlen(date) + 1; … … 44 42 memcpy(data, date, len); 45 43 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 } 56 50 57 51 return 0; 58 52 } 59 53 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} 54 static 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 61 static 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 62 71 }; 63 72 64 ROARD_DL_REG_PROTO(proto) 73 static 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 } 65 78 66 79 ROAR_DL_PLUGIN_START(protocol_daytime) { 67 ROARD_DL_CHECK_VERSIONS();68 69 80 ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-daytime", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); 70 81 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); … … 73 84 ROAR_DL_PLUGIN_META_DESC("Implementation of the Internet daytime protocol"); 74 85 75 ROAR D_DL_REGFN_PROTO();86 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); 76 87 } ROAR_DL_PLUGIN_END 77 88 -
plugins/universal/protocol-discard.c
r5444 r5579 24 24 */ 25 25 26 #include <roar d/include/roard.h>26 #include <roaraudio.h> 27 27 28 static int check_client(int client, struct roar_vio_calls * vio) {28 static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 29 29 char buf[4096]; 30 30 31 ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio);31 (void)client, (void)obuffer, (void)userdata, (void)para, (void)paralen; 32 32 33 33 if ( roar_vio_read(vio, buf, sizeof(buf)) < 1 ) { 34 clients_delete(client);35 34 return -1; 36 35 } 37 36 38 ROAR_DBG("check_client(client=%i, vio=%p) = 0", client, vio);39 37 return 0; 40 38 } 41 39 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} 40 static 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 45 50 }; 46 51 47 ROARD_DL_REG_PROTO(proto) 52 static 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 } 48 57 49 58 ROAR_DL_PLUGIN_START(protocol_discard) { 50 ROARD_DL_CHECK_VERSIONS();51 52 59 ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-discard", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); 53 60 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); … … 56 63 ROAR_DL_PLUGIN_META_DESC("Implementation of a dummy protocol discarding all data"); 57 64 58 ROAR D_DL_REGFN_PROTO();65 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); 59 66 } ROAR_DL_PLUGIN_END 60 67 -
plugins/universal/protocol-echo.c
r5444 r5579 24 24 */ 25 25 26 #include <roar d/include/roard.h>26 #include <roaraudio.h> 27 27 28 static int check_client(int client, struct roar_vio_calls * vio) {28 static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 29 29 struct roar_buffer * buf; 30 30 void * data; 31 31 ssize_t len; 32 32 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); 34 36 35 37 if ( roar_buffer_new_data(&buf, 1024, &data) == -1 ) … … 37 39 38 40 len = roar_vio_read(vio, data, 1024); 39 40 41 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); 42 43 return -1; 43 44 } 44 45 45 46 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); 46 48 roar_buffer_free(buf); 47 clients_delete(client);48 49 return -1; 49 50 } 50 51 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 } 52 60 53 ROAR_DBG(" check_client(client=%i, vio=%p) = 0", client, vio);61 ROAR_DBG("_handle(client=%i, vio=%p) = 0", client, vio); 54 62 return 0; 55 63 } 56 64 57 65 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} 66 static 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 60 76 }; 61 77 62 ROARD_DL_REG_PROTO(proto) 78 static 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 } 63 83 64 84 ROAR_DL_PLUGIN_START(protocol_echo) { 65 ROARD_DL_CHECK_VERSIONS();66 67 85 ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-echo", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); 68 86 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); … … 71 89 ROAR_DL_PLUGIN_META_DESC("Implementation of a dummy protocol sending all data back to the sender"); 72 90 73 ROAR D_DL_REGFN_PROTO();91 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); 74 92 } ROAR_DL_PLUGIN_END 75 93 -
plugins/universal/tic-tac-toe.c
r5569 r5579 24 24 */ 25 25 26 #include <roar d/include/roard.h>26 #include <roaraudio.h> 27 27 28 28 #define _FREE ' ' … … 89 89 }; 90 90 91 static 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 91 101 static void new_game(game_state * state) { 92 102 memset(state, _FREE, sizeof(game_state)); … … 211 221 } 212 222 213 static void draw_help( int client) {223 static void draw_help(struct roar_buffer ** obuffer) { 214 224 struct roar_buffer * buf; 215 225 ssize_t len = 0; … … 225 235 if ( roar_buffer_set_len(buf, len) == -1 ) { 226 236 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 242 static void draw_game(game_state * state, const char * info, struct roar_buffer ** obuffer) { 234 243 struct roar_buffer * buf; 235 244 ssize_t len = 0; … … 249 258 if ( roar_buffer_set_len(buf, len) == -1 ) { 250 259 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 265 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) { 259 266 game_state * state; 260 267 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; 265 269 266 270 state = roar_mm_malloc(sizeof(game_state)); … … 270 274 new_game(state); 271 275 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); 275 279 return 0; 276 280 } … … 307 311 } 308 312 309 static int check_client(int client, struct roar_vio_calls * vio) { 310 struct roar_client_server * cs; 313 static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) { 311 314 char buf[32]; 312 315 ssize_t len; … … 317 320 char c; 318 321 322 (void)client, (void)obuffer, (void)para, (void)paralen; 323 319 324 ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio); 320 325 321 if ( clients_get_server(client, &cs) == -1 ) 326 len = roar_vio_read(vio, buf, sizeof(buf)); 327 328 if ( len < 1 ) { 322 329 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) ) { 332 333 for (i = 0; i < len; i++) { 333 334 if ( map_input(buf[i]) == 'q' ) { 334 clients_delete(client);335 335 return -1; 336 336 } 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); 339 339 return 0; 340 340 } … … 346 346 switch (c) { 347 347 case 'q': 348 clients_delete(client);349 348 return -1; 350 349 break; 351 350 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); 354 353 return 0; 355 354 break; 356 355 case 'H': 357 draw_help( client);356 draw_help(obuffer); 358 357 return 0; 359 358 break; 360 359 case 'e': 361 draw_game( client, cs->protoinst, MSG__YOUR_TURN);360 draw_game(*userdata, MSG__YOUR_TURN, obuffer); 362 361 return 0; 363 362 break; 364 363 case '0': case '1': case '2': case '3': case '4': 365 364 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 ) { 367 366 msg = MSG__CANNOT_PUT_HERE; 368 draw_game( client, cs->protoinst, msg);367 draw_game(*userdata, msg, obuffer); 369 368 return 0; 370 369 } else { … … 377 376 } 378 377 379 won = check_won( cs->protoinst);378 won = check_won(*userdata); 380 379 381 380 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); 384 383 } 385 384 … … 390 389 } 391 390 392 draw_game( client, cs->protoinst, msg);391 draw_game(*userdata, msg, obuffer); 393 392 394 393 ROAR_DBG("check_client(client=%i, vio=%p) = 0", client, vio); … … 397 396 398 397 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} 398 static 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 401 408 }; 402 409 403 ROARD_DL_REG_PROTO(proto) 410 static 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 } 404 415 405 416 ROAR_DL_PLUGIN_START(protocol_tic_tac_toe) { 406 ROARD_DL_CHECK_VERSIONS();407 408 417 ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-tic-tac-toe", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); 409 418 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); … … 412 421 ROAR_DL_PLUGIN_META_DESC("Implementation of a the well known game Tic-Tac-Toe"); 413 422 414 ROAR D_DL_REGFN_PROTO();423 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); 415 424 } ROAR_DL_PLUGIN_END 416 425
Note: See TracChangeset
for help on using the changeset viewer.