diff options
author | David Walter Seikel | 2016-01-01 04:32:00 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-01-01 04:32:00 +1000 |
commit | 6ce603a921ea1a6a2e78b9982a07e229d747108e (patch) | |
tree | 7a7cc16910ff837fdb0a5afda675c2e97097ce01 /src/love | |
parent | Slip an llDialog() into the simple test LSL script, so we can test llDialag e... (diff) | |
download | SledjHamr-6ce603a921ea1a6a2e78b9982a07e229d747108e.zip SledjHamr-6ce603a921ea1a6a2e78b9982a07e229d747108e.tar.gz SledjHamr-6ce603a921ea1a6a2e78b9982a07e229d747108e.tar.bz2 SledjHamr-6ce603a921ea1a6a2e78b9982a07e229d747108e.tar.xz |
Refactor the client / server stuff, though only partially converted so far.
This may not build or run well, it's late, I'm tired.
Diffstat (limited to '')
-rw-r--r-- | src/love/love.c | 121 |
1 files changed, 39 insertions, 82 deletions
diff --git a/src/love/love.c b/src/love/love.c index e90278a..0465ee5 100644 --- a/src/love/love.c +++ b/src/love/love.c | |||
@@ -53,7 +53,6 @@ typedef struct _Lscript | |||
53 | 53 | ||
54 | int logDom = -1; // Our logging domain. | 54 | int logDom = -1; // Our logging domain. |
55 | static Eina_Strbuf *LuaSLStream; | 55 | static Eina_Strbuf *LuaSLStream; |
56 | static Eina_Strbuf *clientStream; | ||
57 | static int scriptCount = 0; | 56 | static int scriptCount = 0; |
58 | static int compiledCount = 0; | 57 | static int compiledCount = 0; |
59 | static struct timeval startTime; | 58 | static struct timeval startTime; |
@@ -507,6 +506,10 @@ static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev) | |||
507 | sprintf(buf, "%s/LuaSL &", prefix_bin_get()); | 506 | sprintf(buf, "%s/LuaSL &", prefix_bin_get()); |
508 | system(buf); | 507 | system(buf); |
509 | count = 0; | 508 | count = 0; |
509 | // TODO - There's also the question of what to do if the connection failed. | ||
510 | // Did the server crash, or was it just the connection? | ||
511 | // Probably gonna need some smarts, for now we just restart all the scripts. | ||
512 | // Which I think gets done on server add. | ||
510 | } | 513 | } |
511 | 514 | ||
512 | // TODO - May want to renew even if it's not running the GUI, but then we still need some sort of "shut down" signal, which we don't need during testing. | 515 | // TODO - May want to renew even if it's not running the GUI, but then we still need some sort of "shut down" signal, which we don't need during testing. |
@@ -523,7 +526,6 @@ static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev | |||
523 | gameGlobals *ourGlobals = data; | 526 | gameGlobals *ourGlobals = data; |
524 | 527 | ||
525 | ourGlobals->client = ev->client; | 528 | ourGlobals->client = ev->client; |
526 | ecore_con_client_timeout_set(ev->client, 0); | ||
527 | 529 | ||
528 | if (ourGlobals->client) | 530 | if (ourGlobals->client) |
529 | { | 531 | { |
@@ -534,91 +536,54 @@ static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev | |||
534 | return ECORE_CALLBACK_RENEW; | 536 | return ECORE_CALLBACK_RENEW; |
535 | } | 537 | } |
536 | 538 | ||
537 | static Eina_Bool _dataClient(void *data, int type, Ecore_Con_Event_Client_Data *ev) | 539 | |
540 | Eina_Bool clientParser(void *data, Connection *connection, char *SID, char *command, char *arguments) | ||
538 | { | 541 | { |
539 | gameGlobals *ourGlobals = data; | 542 | gameGlobals *ourGlobals = data; |
540 | // char buf[PATH_MAX]; | ||
541 | char SID[PATH_MAX]; | ||
542 | const char *command; | ||
543 | char *ext; | ||
544 | 543 | ||
545 | eina_strbuf_append_length(clientStream, ev->data, ev->size); | 544 | if (0 == strncmp(command, "events.touch_start", 18)) |
546 | command = eina_strbuf_string_get(clientStream); | ||
547 | while ((ext = index(command, '\n'))) | ||
548 | { | 545 | { |
549 | int length = ext - command; | 546 | Eina_Iterator *scripts; |
547 | LoveScript *me; | ||
550 | 548 | ||
551 | strncpy(SID, command, length + 1); | 549 | // TODO - For now, just send it to everyone. |
552 | SID[length] = '\0'; | 550 | scripts = eina_hash_iterator_data_new(ourGlobals->scripts); |
553 | eina_strbuf_remove(clientStream, 0, length + 1); | 551 | while(eina_iterator_next(scripts, (void **) &me)) |
554 | ext = index(SID, '.'); | ||
555 | if (ext) | ||
556 | { | 552 | { |
557 | ext[0] = '\0'; | 553 | sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedKeys({\"%s\"})", ownerKey); |
558 | command = ext + 1; | 554 | sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedNames({\"%s\"})", ownerName); |
559 | 555 | sendForth(ourGlobals->serverLuaSL, me->SID, "events.touch_start(1)"); | |
560 | if (0 == strncmp(command, "events.touch_start(", 19)) | ||
561 | { | ||
562 | Eina_Iterator *scripts; | ||
563 | LoveScript *me; | ||
564 | |||
565 | // TODO - For now, just send it to everyone. | ||
566 | scripts = eina_hash_iterator_data_new(ourGlobals->scripts); | ||
567 | while(eina_iterator_next(scripts, (void **) &me)) | ||
568 | { | ||
569 | sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedKeys({\"%s\"})", ownerKey); | ||
570 | sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedNames({\"%s\"})", ownerName); | ||
571 | sendForth(ourGlobals->serverLuaSL, me->SID, "events.touch_start(1)"); | ||
572 | } | ||
573 | eina_iterator_free(scripts); | ||
574 | } | ||
575 | else if (0 == strncmp(command, "events.listen(", 14)) | ||
576 | { | ||
577 | Eina_Iterator *scripts; | ||
578 | LoveScript *me; | ||
579 | |||
580 | // TODO - For now, just send it to everyone. | ||
581 | scripts = eina_hash_iterator_data_new(ourGlobals->scripts); | ||
582 | while(eina_iterator_next(scripts, (void **) &me)) | ||
583 | { | ||
584 | sendForth(ourGlobals->serverLuaSL, me->SID, command); | ||
585 | } | ||
586 | eina_iterator_free(scripts); | ||
587 | } | ||
588 | else | ||
589 | PW("Unknown command from client - %s", command); | ||
590 | } | 556 | } |
591 | 557 | eina_iterator_free(scripts); | |
592 | // Get the next blob to check it. | ||
593 | command = eina_strbuf_string_get(clientStream); | ||
594 | } | 558 | } |
559 | else if (0 == strncmp(command, "events.listen", 13)) | ||
560 | { | ||
561 | Eina_Iterator *scripts; | ||
562 | LoveScript *me; | ||
563 | char buf[PATH_MAX]; | ||
564 | |||
565 | // TODO - For now, just send it to everyone. | ||
566 | sprintf(buf, "%s(%s", command, arguments); | ||
567 | scripts = eina_hash_iterator_data_new(ourGlobals->scripts); | ||
568 | while(eina_iterator_next(scripts, (void **) &me)) | ||
569 | { | ||
570 | sendForth(ourGlobals->serverLuaSL, me->SID, buf); | ||
571 | } | ||
572 | eina_iterator_free(scripts); | ||
573 | } | ||
574 | else | ||
575 | PW("Unknown command from client - %s(%s", command, arguments); | ||
595 | 576 | ||
596 | return ECORE_CALLBACK_RENEW; | 577 | return ECORE_CALLBACK_RENEW; |
597 | } | 578 | } |
598 | 579 | ||
599 | static Eina_Bool _delClient(void *data, int type, Ecore_Con_Event_Client_Del *ev) | 580 | static Eina_Bool _delClient(void *data, int type, Ecore_Con_Event_Client_Del *ev) |
600 | { | 581 | { |
601 | gameGlobals *ourGlobals = data; | 582 | gameGlobals *ourGlobals = data; |
602 | 583 | ||
603 | if (ev->client) | 584 | // TODO - I could coax this into something generic, maybe. |
604 | { | 585 | sendForth(ourGlobals->serverLuaSL, ownerKey, "exit()"); |
605 | Eina_List const *clients; | 586 | |
606 | |||
607 | // This is only really for testing, normally it just runs 24/7, or until told not to. | ||
608 | clients = ecore_con_server_clients_get(ourGlobals->server); | ||
609 | if (0 == eina_list_count(clients)) | ||
610 | { | ||
611 | PD("No more clients, exiting."); | ||
612 | sendForth(ourGlobals->serverLuaSL, ownerKey, "exit()"); | ||
613 | ecore_main_loop_quit(); | ||
614 | } | ||
615 | else | ||
616 | { | ||
617 | PD("Some %d more clients, exiting anyway.", eina_list_count(clients)); | ||
618 | sendForth(ourGlobals->serverLuaSL, ownerKey, "exit()"); | ||
619 | ecore_main_loop_quit(); | ||
620 | } | ||
621 | } | ||
622 | return ECORE_CALLBACK_RENEW; | 587 | return ECORE_CALLBACK_RENEW; |
623 | } | 588 | } |
624 | 589 | ||
@@ -641,18 +606,10 @@ int main(int argc, char **argv) | |||
641 | if (ecore_con_init()) | 606 | if (ecore_con_init()) |
642 | { | 607 | { |
643 | LuaSLStream = eina_strbuf_new(); | 608 | LuaSLStream = eina_strbuf_new(); |
644 | clientStream = eina_strbuf_new(); | ||
645 | reachOut("127.0.0.1", 8211, &ourGlobals, (Ecore_Event_Handler_Cb) _addLuaSL, (Ecore_Event_Handler_Cb) _dataLuaSL, (Ecore_Event_Handler_Cb) _delLuaSL); | 609 | reachOut("127.0.0.1", 8211, &ourGlobals, (Ecore_Event_Handler_Cb) _addLuaSL, (Ecore_Event_Handler_Cb) _dataLuaSL, (Ecore_Event_Handler_Cb) _delLuaSL); |
646 | 610 | ||
647 | if ((ourGlobals.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port + 1, &ourGlobals))) | 611 | if (openArms("love", ourGlobals.address, ourGlobals.port + 1, &ourGlobals, (Ecore_Event_Handler_Cb) _addClient, NULL, (Ecore_Event_Handler_Cb) _delClient, clientParser)) |
648 | { | 612 | { |
649 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) _addClient, &ourGlobals); | ||
650 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb) _dataClient, &ourGlobals); | ||
651 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _delClient, &ourGlobals); | ||
652 | ecore_con_server_timeout_set(ourGlobals.server, 0); | ||
653 | ecore_con_server_client_limit_set(ourGlobals.server, -1, 0); | ||
654 | |||
655 | |||
656 | if (ecore_evas_init()) | 613 | if (ecore_evas_init()) |
657 | { | 614 | { |
658 | if (edje_init()) | 615 | if (edje_init()) |