1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
/*****************************************************************
* gmerlin - a general purpose multimedia framework and applications
*
* Copyright (c) 2001 - 2024 Members of the Gmerlin project
* http://github.com/bplaum
*
* 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, see <http://www.gnu.org/licenses/>.
* *****************************************************************/
#include <string.h>
#include <signal.h>
#include <config.h>
#include <gavl/gavlsocket.h>
#include <gmerlin/translation.h>
#include <gmerlin/log.h>
#include <gmerlin/parameter.h>
#include <gmerlin/cfg_registry.h>
#include <gmerlin/cfgctx.h>
#include <gmerlin/cmdline.h>
#include <gmerlin/httpserver.h>
#include <gmerlin/application.h>
#include <gmerlin/websocket.h>
#include <gmerlin/utils.h>
#define LOG_DOMAIN "gmerlin-server"
bg_controllable_t ctrl;
const bg_parameter_info_t * s_params;
gavl_dictionary_t * s_section = NULL;
bg_websocket_context_t * ctx = NULL;
static bg_cmdline_arg_t global_options[] =
{
{ /* End */ }
};
const bg_cmdline_app_data_t app_data =
{
.package = PACKAGE,
.version = VERSION,
.synopsis = TRS("[options]\n"),
.help_before = TRS("Websocket tester\n"),
.args = (bg_cmdline_arg_array_t[]) { { TRS("Options"), global_options },
{ } },
.files = (bg_cmdline_ext_doc_t[])
{ { "~/.gmerlin/plugins.xml",
TRS("Cache of the plugin registry (shared by all applications)") },
{ "~/.gmerlin/generic/cfg.xml",
TRS("Default plugin parameters are read from there. Use gmerlin_plugincfg to change them.") },
{ /* End */ }
},
};
static int msg_callback(void * data, gavl_msg_t * msg)
{
fprintf(stderr, "Got message\n");
gavl_msg_dump(msg, 2);
/* Echo message */
bg_msg_sink_put_copy(ctrl.evt_sink, msg);
return 1;
}
gavl_time_t delay_time = GAVL_TIME_SCALE / 20; // 50 ms
int main(int argc, char ** argv)
{
const char * root_url;
bg_http_server_t * srv;
bg_app_init("websocket_test", TRS("Websocket tester"), NULL);
bg_handle_sigint();
bg_cmdline_init(&app_data);
bg_cmdline_parse(global_options, &argc, &argv, NULL);
/* Create server */
srv = bg_http_server_create();
bg_http_server_set_static_path(srv, "/static/");
bg_controllable_init(&ctrl,
bg_msg_sink_create(msg_callback, NULL, 1),
bg_msg_hub_create(1));
ctx = bg_websocket_context_create(GAVL_META_CLASS_BACKEND_RENDERER, NULL, &ctrl);
bg_http_server_start(srv);
root_url = bg_http_server_get_root_url(srv);
if(!strncmp(root_url, "http://0.0.0.0:", 15))
{
fprintf(stderr, "Go to http://127.0.0.1:%s/static/websocket.html\n",
root_url + 15);
}
else
fprintf(stderr, "Go to %s/static/websocket.html\n",
root_url);
while(1)
{
if(!bg_http_server_iteration(srv) &&
!bg_websocket_context_iteration(ctx))
{
gavl_time_delay(&delay_time);
}
if(bg_got_sigint())
break;
}
bg_http_server_destroy(srv);
bg_websocket_context_destroy(ctx);
return 0;
}
|