Update NTK.
[nondaw.git] / session-manager / src / nsm-proxy-gui.C
blobba49b5da351b76571a8345bf3e14f948d752aae4
2 /*******************************************************************************/
3 /* Copyright (C) 2012 Jonathan Moore Liles                                     */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 #pragma GCC diagnostic ignored "-Wunused-parameter"
23 #define _MODULE_ "nsm-proxy-gui"
25 #define APP_NAME "NSM Proxy"
26 #define APP_TITLE "NSM Proxy"
28 #include "NSM_Proxy_UI.H"
29 #include "FL/Fl_Theme.H"
30 #include "FL/themes.H"
31 #include <lo/lo.h>
32 #include <signal.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
37 lo_server losrv;
38 lo_address nsmp_addr;
40 static NSM_Proxy_UI *ui;
42 int
43 osc_update ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data )
45     printf( "Got update for %s\n", path );
47     Fl::lock();
49     if (!strcmp( path, "/nsm/proxy/label" ))
50         ui->label_input->value( &argv[0]->s );
51     else if (!strcmp( path, "/nsm/proxy/arguments" ))
52         ui->arguments_input->value( &argv[0]->s );
53     else if (!strcmp( path, "/nsm/proxy/executable" ))
54         ui->executable_input->value( &argv[0]->s );
55     else if (!strcmp( path, "/nsm/proxy/save_signal" ))
56     {
57         if ( argv[0]->i == SIGUSR1 )
58             ui->save_signal_choice->value( 1 );
59         else if ( argv[0]->i == SIGUSR2 )
60             ui->save_signal_choice->value( 2 );
61         else if ( argv[0]->i == SIGINT )
62             ui->save_signal_choice->value( 3 );
63         else
64             ui->save_signal_choice->value( 0 );
65     }
67     Fl::unlock();
69     return 0;
73 void
74 init_osc ( const char *osc_port )
77     lo_server_thread loth = lo_server_thread_new( osc_port, NULL );
78     losrv = lo_server_thread_get_server( loth );
80 //error_handler );
82     char *url = lo_server_get_url(losrv);
83     printf("OSC: %s\n",url);
84     free(url);
86     /* GUI */
88     lo_server_thread_add_method( loth, "/nsm/proxy/executable", "s", osc_update, NULL );
89     lo_server_thread_add_method( loth, "/nsm/proxy/arguments", "s", osc_update, NULL );
90     lo_server_thread_add_method( loth, "/nsm/proxy/label", "s", osc_update, NULL );
91     lo_server_thread_add_method( loth, "/nsm/proxy/save_signal", "i", osc_update, NULL );
93     lo_server_thread_start( loth );
96 /*****************/
97 /* GUI Callbacks */
98 /*****************/
100 void
101 handle_kill ( Fl_Widget *o, void *v )
103     lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/kill", "" );
106 void
107 handle_start ( Fl_Widget *o, void *v )
109     lo_send_from( nsmp_addr, losrv,  LO_TT_IMMEDIATE, "/nsm/proxy/start", "ss",
110                   ui->executable_input->value(),
111                   ui->arguments_input->value() );
114 void
115 handle_label ( Fl_Widget *o, void *v )
117     lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/label", "s",
118                   ui->label_input->value() );
121 void
122 handle_executable ( Fl_Widget *o, void *v )
124     ui->label_input->value( ui->executable_input->value() );
127 void
128 handle_save_signal ( Fl_Widget *o, void *v )
130     int sig = 0;
131     
132     const char* picked = ui->save_signal_choice->mvalue()->label();
133     
134     if ( !strcmp( picked, "SIGUSR1" ) )
135         sig = SIGUSR1;
136     else if ( !strcmp( picked, "SIGUSR2" ) )
137         sig = SIGUSR2;
138     else if ( !strcmp( picked, "SIGINT" ) )
139         sig = SIGINT;
141     lo_send_from( nsmp_addr, losrv,  LO_TT_IMMEDIATE,"/nsm/proxy/save_signal", "i",
142                   sig );
145 void
146 connect_ui ( void )
148     ui->executable_input->callback( handle_executable, NULL );
149     ui->kill_button->callback( handle_kill, NULL );
150     ui->start_button->callback( handle_start, NULL );
151     ui->save_signal_choice->callback( handle_save_signal, NULL );
152     ui->label_input->callback( handle_label, NULL );
158 main ( int argc, char **argv )
160     if ( argc != 3 )
161     {
162         fprintf( stderr, "Usage: %s --connect-to url\n", argv[0] );
163         return 1;
164     }
166     init_osc( NULL );
168     nsmp_addr = lo_address_new_from_url( argv[2] );
170     printf( "Connecting to nsm-proxy at: %s\n", argv[2] );
172     ui = new NSM_Proxy_UI;
174     Fl_Double_Window *w = ui->make_window();
176     connect_ui();
178     lo_send_from( nsmp_addr, losrv,  LO_TT_IMMEDIATE, "/nsm/proxy/update", "" );
179     
180     w->show();
182     fl_register_themes();
184     Fl_Theme::set();
185     
186     Fl::lock();
188     Fl::run();
190     return 0;