Index: trunk/src_plugins/hid_srv_ws/Plug.tmpasm =================================================================== --- trunk/src_plugins/hid_srv_ws/Plug.tmpasm (revision 10620) +++ trunk/src_plugins/hid_srv_ws/Plug.tmpasm (revision 10621) @@ -1,6 +1,7 @@ put /local/pcb/mod {hid_srv_ws} append /local/pcb/mod/OBJS_C99 [@ $(PLUGDIR)/hid_srv_ws/server.o + $(PLUGDIR)/hid_srv_ws/c2s.o @] switch /local/pcb/hid_srv_ws/controls Index: trunk/src_plugins/hid_srv_ws/c2s.c =================================================================== --- trunk/src_plugins/hid_srv_ws/c2s.c (nonexistent) +++ trunk/src_plugins/hid_srv_ws/c2s.c (revision 10621) @@ -0,0 +1,49 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2017 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/* Needed by libuv to compile in C99 */ +#define _POSIX_C_SOURCE 200112 + +#include "config.h" + +#include +#include + +#include "error.h" +#include "server.h" +#include "c2s.h" + +void hid_ws_recv_msg(hid_srv_ws_t *ctx) +{ + char msg[256]; + int len; + + *msg = 0; + len = recv(ctx->c2s[0], msg, sizeof(msg), MSG_DONTWAIT); + msg[len] = '\0'; + pcb_message(PCB_MSG_INFO, "SERVER MSG: %d/'%s'\n", len, msg); +} + +void hid_ws_send_msg(hid_srv_ws_t *ctx) +{ + send(ctx->c2s[1], "jajj", 4, 0); +} Index: trunk/src_plugins/hid_srv_ws/c2s.h =================================================================== --- trunk/src_plugins/hid_srv_ws/c2s.h (nonexistent) +++ trunk/src_plugins/hid_srv_ws/c2s.h (revision 10621) @@ -0,0 +1,25 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2017 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "server.h" +void hid_ws_recv_msg(hid_srv_ws_t *ctx); +void hid_ws_send_msg(hid_srv_ws_t *ctx); Index: trunk/src_plugins/hid_srv_ws/server.c =================================================================== --- trunk/src_plugins/hid_srv_ws/server.c (revision 10620) +++ trunk/src_plugins/hid_srv_ws/server.c (revision 10621) @@ -29,37 +29,22 @@ #include #include -#include #include -#include #include "plugins.h" #include "error.h" +#include "server.h" +#include "c2s.h" + int pplg_check_ver_hid_srv_ws(int ver_needed) { return 0; } extern int pplg_init_hid_remote(void); extern void pcb_set_hid_name(const char *new_hid_name); -/* Number of sockets to handle - need one listening socket and one accepted - because each client is forked; leave some room for retries and whatnot */ -#define WS_MAX_FDS 8 - #warning TODO: make this a configuration static int max_clients = 3; -typedef struct { - struct lws_context *context; - struct lws_pollfd pollfds[WS_MAX_FDS]; - int fd_lookup[1024]; - int count_pollfds; - int listen_fd; - pid_t pid; - int num_clients; - - int c2s[2]; /* Client to server communication; 0 is read by the server, 1 is written by clients */ -} hid_srv_ws_t; - static hid_srv_ws_t hid_srv_ws_ctx; static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) @@ -175,22 +160,6 @@ { NULL, NULL, 0, 0 } /* End of list */ }; -static void recv_server_msg(hid_srv_ws_t *ctx) -{ - char msg[256]; - int len; - - *msg = 0; - len = recv(ctx->c2s[0], msg, sizeof(msg), MSG_DONTWAIT); - msg[len] = '\0'; - printf("SERVER MSG: %d/'%s'\n", len, msg); -} - -static void send_server_msg(hid_srv_ws_t *ctx) -{ - send(ctx->c2s[1], "jajj", 4, 0); -} - static int src_ws_mainloop(hid_srv_ws_t *ctx) { unsigned int ms, ms_1sec = 0; @@ -212,7 +181,7 @@ if (ctx->pollfds[n].revents) { if (ctx->pollfds[n].fd == ctx->c2s[0]) { printf("SERVER MSG\n"); - recv_server_msg(ctx); + hid_ws_recv_msg(ctx); } else if (ctx->pollfds[n].fd == ctx->listen_fd) { /* listening socket: fork for each client */ @@ -236,7 +205,7 @@ } else pcb_message(PCB_MSG_INFO, "websocket [%d]: new client conn accepted\n", ctx->pid); - send_server_msg(ctx); + hid_ws_send_msg(ctx); } else { /* parent: announce the fork but don't do anything else */ Index: trunk/src_plugins/hid_srv_ws/server.h =================================================================== --- trunk/src_plugins/hid_srv_ws/server.h (nonexistent) +++ trunk/src_plugins/hid_srv_ws/server.h (revision 10621) @@ -0,0 +1,45 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2017 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef PCB_HID_SRV_WS_SERER_H +#define PCB_HID_SRV_WS_SERER_H + +#include +#include + +/* Number of sockets to handle - need one listening socket and one accepted + because each client is forked; leave some room for retries and whatnot */ +#define WS_MAX_FDS 8 + +typedef struct { + struct lws_context *context; + struct lws_pollfd pollfds[WS_MAX_FDS]; + int fd_lookup[1024]; + int count_pollfds; + int listen_fd; + pid_t pid; + int num_clients; + + int c2s[2]; /* Client to server communication; 0 is read by the server, 1 is written by clients */ +} hid_srv_ws_t; + +#endif