2 * Copyright (c)2004 Cat's Eye Technologies. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * Neither the name of Cat's Eye Technologies nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
36 * $Id: fe_test.c,v 1.11 2005/04/05 20:39:22 cpressey Exp $
37 * This code was derived in part from:
38 * $_DragonFly: src/test/caps/server.c,v 1.4 2004/03/06 22:15:00 dillon Exp $
39 * and is therefore also subject to the license conditions on that file.
46 #include "dfui/dfui.h"
47 #include "dfui/dump.h"
49 volatile sig_atomic_t caught_signal;
52 signal_handler(int signo)
54 caught_signal = signo;
57 #define BAR "----------------------------------------------------------------------"
60 display_form(struct dfui_form *f)
62 struct dfui_field *fi;
63 struct dfui_action *a;
66 for (fi = dfui_form_field_get_first(f); fi != NULL;
67 fi = dfui_field_get_next(fi)) {
68 printf("| %30s %c[ %-30s ]\n",
69 dfui_info_get_name(dfui_field_get_info(fi)),
70 dfui_field_property_is(fi, "control", "checkbox") ? '+' : ' ',
75 printf("| Actions: ");
76 for (a = dfui_form_action_get_first(f); a != NULL;
77 a = dfui_action_get_next(a)) {
79 dfui_info_get_name(dfui_action_get_info(a))
87 present_form(struct dfui_form *f, char *action)
90 struct dfui_action *a;
94 printf("Select an action> ");
95 fgets(action, 80, stdin);
96 action[strlen(action) - 1] = '\0';
97 if ((a = dfui_form_action_find(f, action)) != NULL) {
100 printf("Invalid option.\n");
106 show_progress(struct dfui_progress *pr)
108 printf(" %d%c done...\n", dfui_progress_get_amount(pr), '%');
112 abort_frontend(struct dfui_connection *c)
114 printf("*** ABORTING.\n");
120 * dfui frontend example test thing
123 main(int argc __unused, char **argv __unused)
125 struct dfui_connection *c;
127 struct dfui_response *r;
128 struct dfui_progress *pr;
129 struct dfui_property *gp;
136 c = dfui_connection_new(DFUI_TRANSPORT_TCP, "9999");
138 printf("Connecting to backend.\n");
140 signal(SIGINT, signal_handler);
143 dfui_fe_receive(c, &msgtype, &payload);
145 case DFUI_BE_MSG_PRESENT:
146 printf("Got a form from the backend.\n");
147 f = (struct dfui_form *)payload;
148 present_form(f, action);
149 if (caught_signal) abort_frontend(c);
150 r = dfui_response_new(dfui_form_get_id(f), action);
151 printf("Sending our response to the backend.\n");
152 dfui_fe_submit(c, r);
154 dfui_response_free(r);
156 case DFUI_BE_MSG_PROG_BEGIN:
157 printf("Got a progress bar begin from the backend.\n");
158 pr = (struct dfui_progress *)payload;
161 dfui_fe_progress_continue(c);
162 dfui_progress_free(pr);
164 case DFUI_BE_MSG_PROG_UPDATE:
165 printf("Got a progress bar update from the backend.\n");
166 pr = (struct dfui_progress *)payload;
168 dfui_progress_free(pr);
170 printf("* Cancelling ...\n");
171 dfui_fe_progress_cancel(c);
174 dfui_fe_progress_continue(c);
177 case DFUI_BE_MSG_PROG_END:
178 printf("Got a progress bar end from the backend.\n");
179 dfui_fe_progress_continue(c);
181 case DFUI_BE_MSG_SET_GLOBAL:
182 gp = (struct dfui_property *)payload;
183 printf("Got a global setting change from the backend: %s = %s\n",
184 dfui_property_get_name(gp), dfui_property_get_value(gp));
185 dfui_fe_confirm_set_global(c);
186 dfui_property_free(gp);
188 case DFUI_BE_MSG_STOP:
189 printf("Got a STOP message from the backend.\n");
190 dfui_fe_confirm_stop(c);
195 printf("Frontend done.\n");
196 dfui_fe_disconnect(c);
198 signal(SIGINT, SIG_DFL);