[6d5e378] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Petr Koupy
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * 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 the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup vlaunch
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[3e6a98c5] | 35 | #include <stdbool.h>
|
---|
[6d5e378] | 36 | #include <errno.h>
|
---|
| 37 | #include <stdio.h>
|
---|
| 38 | #include <malloc.h>
|
---|
| 39 | #include <io/pixel.h>
|
---|
| 40 | #include <task.h>
|
---|
| 41 | #include <str.h>
|
---|
| 42 | #include <str_error.h>
|
---|
[b5674b2] | 43 | #include <loc.h>
|
---|
| 44 | #include <fibril_synch.h>
|
---|
| 45 | #include <io/pixel.h>
|
---|
| 46 | #include <device/led_dev.h>
|
---|
[6d5e378] | 47 |
|
---|
| 48 | #include <window.h>
|
---|
| 49 | #include <grid.h>
|
---|
| 50 | #include <button.h>
|
---|
| 51 | #include <label.h>
|
---|
[b8f1a349] | 52 | #include <canvas.h>
|
---|
[6d5e378] | 53 |
|
---|
[b8f1a349] | 54 | #include <surface.h>
|
---|
| 55 | #include <source.h>
|
---|
| 56 | #include <drawctx.h>
|
---|
| 57 | #include <codec/tga.h>
|
---|
| 58 |
|
---|
| 59 | #include "images.h"
|
---|
| 60 |
|
---|
| 61 | #define NAME "vlaunch"
|
---|
| 62 |
|
---|
[b4f43a1] | 63 | #define LOGO_WIDTH 196
|
---|
| 64 | #define LOGO_HEIGHT 66
|
---|
[6d5e378] | 65 |
|
---|
[b5674b2] | 66 | #define PERIOD 1000000
|
---|
| 67 | #define COLORS 7
|
---|
| 68 |
|
---|
[6d5e378] | 69 | static char *winreg = NULL;
|
---|
[b5674b2] | 70 | static fibril_timer_t *timer = NULL;
|
---|
| 71 | static list_t led_devs;
|
---|
| 72 |
|
---|
| 73 | static pixel_t colors[COLORS] = {
|
---|
| 74 | PIXEL(0xff, 0xff, 0x00, 0x00),
|
---|
| 75 | PIXEL(0xff, 0x00, 0xff, 0x00),
|
---|
| 76 | PIXEL(0xff, 0x00, 0x00, 0xff),
|
---|
| 77 | PIXEL(0xff, 0xff, 0xff, 0x00),
|
---|
| 78 | PIXEL(0xff, 0xff, 0x00, 0xff),
|
---|
| 79 | PIXEL(0xff, 0x00, 0xff, 0xff),
|
---|
| 80 | PIXEL(0xff, 0xff, 0xff, 0xff)
|
---|
| 81 | };
|
---|
| 82 |
|
---|
| 83 | static unsigned int color = 0;
|
---|
| 84 |
|
---|
| 85 | typedef struct {
|
---|
| 86 | link_t link;
|
---|
| 87 | service_id_t svc_id;
|
---|
| 88 | async_sess_t *sess;
|
---|
| 89 | } led_dev_t;
|
---|
[6d5e378] | 90 |
|
---|
| 91 | static int app_launch(const char *app)
|
---|
| 92 | {
|
---|
| 93 | printf("%s: Spawning %s %s \n", NAME, app, winreg);
|
---|
[b5674b2] | 94 |
|
---|
[6d5e378] | 95 | task_id_t id;
|
---|
[b5674b2] | 96 | int rc = task_spawnl(&id, app, app, winreg, NULL);
|
---|
[6d5e378] | 97 | if (rc != EOK) {
|
---|
| 98 | printf("%s: Error spawning %s %s (%s)\n", NAME, app,
|
---|
| 99 | winreg, str_error(rc));
|
---|
| 100 | return -1;
|
---|
| 101 | }
|
---|
[b5674b2] | 102 |
|
---|
| 103 | task_exit_t texit;
|
---|
| 104 | int retval;
|
---|
[6d5e378] | 105 | rc = task_wait(id, &texit, &retval);
|
---|
[b5674b2] | 106 | if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
|
---|
[6d5e378] | 107 | printf("%s: Error retrieving retval from %s (%s)\n", NAME,
|
---|
| 108 | app, str_error(rc));
|
---|
| 109 | return -1;
|
---|
| 110 | }
|
---|
[b5674b2] | 111 |
|
---|
[6d5e378] | 112 | return retval;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | static void on_vterm(widget_t *widget, void *data)
|
---|
| 116 | {
|
---|
| 117 | app_launch("/app/vterm");
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | static void on_vdemo(widget_t *widget, void *data)
|
---|
| 121 | {
|
---|
| 122 | app_launch("/app/vdemo");
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | static void on_vlaunch(widget_t *widget, void *data)
|
---|
| 126 | {
|
---|
| 127 | app_launch("/app/vlaunch");
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[b5674b2] | 130 | static void timer_callback(void *data)
|
---|
| 131 | {
|
---|
| 132 | pixel_t next_color = colors[color];
|
---|
| 133 |
|
---|
| 134 | color++;
|
---|
| 135 | if (color >= COLORS)
|
---|
| 136 | color = 0;
|
---|
| 137 |
|
---|
| 138 | list_foreach(led_devs, link, led_dev_t, dev) {
|
---|
| 139 | if (dev->sess)
|
---|
| 140 | led_dev_color_set(dev->sess, next_color);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | fibril_timer_set(timer, PERIOD, timer_callback, NULL);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | static void loc_callback(void)
|
---|
| 147 | {
|
---|
| 148 | category_id_t led_cat;
|
---|
| 149 | int rc = loc_category_get_id("led", &led_cat, IPC_FLAG_BLOCKING);
|
---|
| 150 | if (rc != EOK)
|
---|
| 151 | return;
|
---|
| 152 |
|
---|
| 153 | service_id_t *svcs;
|
---|
| 154 | size_t count;
|
---|
| 155 | rc = loc_category_get_svcs(led_cat, &svcs, &count);
|
---|
| 156 | if (rc != EOK)
|
---|
| 157 | return;
|
---|
| 158 |
|
---|
| 159 | for (size_t i = 0; i < count; i++) {
|
---|
| 160 | bool known = false;
|
---|
| 161 |
|
---|
| 162 | /* Determine whether we already know this device. */
|
---|
| 163 | list_foreach(led_devs, link, led_dev_t, dev) {
|
---|
| 164 | if (dev->svc_id == svcs[i]) {
|
---|
| 165 | known = true;
|
---|
| 166 | break;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | if (!known) {
|
---|
| 171 | led_dev_t *dev = (led_dev_t *) calloc(1, sizeof(led_dev_t));
|
---|
| 172 | if (!dev)
|
---|
| 173 | continue;
|
---|
| 174 |
|
---|
| 175 | link_initialize(&dev->link);
|
---|
| 176 | dev->svc_id = svcs[i];
|
---|
| 177 | dev->sess = loc_service_connect(EXCHANGE_SERIALIZE, svcs[i], 0);
|
---|
| 178 |
|
---|
| 179 | list_append(&dev->link, &led_devs);
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | // FIXME: Handle LED device removal
|
---|
| 184 |
|
---|
| 185 | free(svcs);
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[6d5e378] | 188 | int main(int argc, char *argv[])
|
---|
| 189 | {
|
---|
[87c0a45] | 190 | if (argc < 2) {
|
---|
[6d5e378] | 191 | printf("Compositor server not specified.\n");
|
---|
| 192 | return 1;
|
---|
| 193 | }
|
---|
[bdf3c0c] | 194 |
|
---|
[b5674b2] | 195 | list_initialize(&led_devs);
|
---|
| 196 | int rc = loc_register_cat_change_cb(loc_callback);
|
---|
| 197 | if (rc != EOK) {
|
---|
| 198 | printf("Unable to register callback for device discovery.\n");
|
---|
| 199 | return 1;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | timer = fibril_timer_create();
|
---|
| 203 | if (!timer) {
|
---|
| 204 | printf("Unable to create timer.\n");
|
---|
| 205 | return 1;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[b8f1a349] | 208 | surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size, 0);
|
---|
| 209 | if (!logo) {
|
---|
| 210 | printf("Unable to decode logo.\n");
|
---|
| 211 | return 1;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[bdf3c0c] | 214 | winreg = argv[1];
|
---|
[62fbb7e] | 215 | window_t *main_window = window_open(argv[1], true, true, "vlaunch");
|
---|
[bdf3c0c] | 216 | if (!main_window) {
|
---|
| 217 | printf("Cannot open main window.\n");
|
---|
| 218 | return 1;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[9e7898e] | 221 | pixel_t grd_bg = PIXEL(255, 255, 255, 255);
|
---|
[296e124e] | 222 |
|
---|
| 223 | pixel_t btn_bg = PIXEL(255, 255, 255, 255);
|
---|
| 224 | pixel_t btn_fg = PIXEL(255, 186, 186, 186);
|
---|
| 225 | pixel_t btn_text = PIXEL(255, 0, 0, 0);
|
---|
| 226 |
|
---|
[9e7898e] | 227 | pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
|
---|
[296e124e] | 228 | pixel_t lbl_text = PIXEL(255, 0, 0, 0);
|
---|
[bdf3c0c] | 229 |
|
---|
[b8f1a349] | 230 | canvas_t *logo_canvas = create_canvas(NULL, LOGO_WIDTH, LOGO_HEIGHT,
|
---|
| 231 | logo);
|
---|
[bdf3c0c] | 232 | label_t *lbl_caption = create_label(NULL, "Launch application:", 16,
|
---|
[296e124e] | 233 | lbl_bg, lbl_text);
|
---|
[bdf3c0c] | 234 | button_t *btn_vterm = create_button(NULL, "vterm", 16, btn_bg,
|
---|
[296e124e] | 235 | btn_fg, btn_text);
|
---|
[bdf3c0c] | 236 | button_t *btn_vdemo = create_button(NULL, "vdemo", 16, btn_bg,
|
---|
[296e124e] | 237 | btn_fg, btn_text);
|
---|
[bdf3c0c] | 238 | button_t *btn_vlaunch = create_button(NULL, "vlaunch", 16, btn_bg,
|
---|
[296e124e] | 239 | btn_fg, btn_text);
|
---|
[395ca2e] | 240 | grid_t *grid = create_grid(window_root(main_window), 1, 5, grd_bg);
|
---|
[bdf3c0c] | 241 |
|
---|
[b8f1a349] | 242 | if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) ||
|
---|
| 243 | (!btn_vdemo) || (!btn_vlaunch) || (!grid)) {
|
---|
[bdf3c0c] | 244 | window_close(main_window);
|
---|
| 245 | printf("Cannot create widgets.\n");
|
---|
| 246 | return 1;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | sig_connect(&btn_vterm->clicked, NULL, on_vterm);
|
---|
| 250 | sig_connect(&btn_vdemo->clicked, NULL, on_vdemo);
|
---|
| 251 | sig_connect(&btn_vlaunch->clicked, NULL, on_vlaunch);
|
---|
| 252 |
|
---|
[b8f1a349] | 253 | grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1);
|
---|
[395ca2e] | 254 | grid->add(grid, &lbl_caption->widget, 0, 1, 1, 1);
|
---|
| 255 | grid->add(grid, &btn_vterm->widget, 0, 2, 1, 1);
|
---|
| 256 | grid->add(grid, &btn_vdemo->widget, 0, 3, 1, 1);
|
---|
| 257 | grid->add(grid, &btn_vlaunch->widget, 0, 4, 1, 1);
|
---|
[bdf3c0c] | 258 |
|
---|
[62fbb7e] | 259 | window_resize(main_window, 0, 0, 210, 130 + LOGO_HEIGHT,
|
---|
| 260 | WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_TOP);
|
---|
[bdf3c0c] | 261 | window_exec(main_window);
|
---|
[b8f1a349] | 262 |
|
---|
[b5674b2] | 263 | fibril_timer_set(timer, PERIOD, timer_callback, NULL);
|
---|
| 264 |
|
---|
[bdf3c0c] | 265 | task_retval(0);
|
---|
| 266 | async_manager();
|
---|
| 267 |
|
---|
| 268 | return 0;
|
---|
[6d5e378] | 269 | }
|
---|
| 270 |
|
---|
| 271 | /** @}
|
---|
| 272 | */
|
---|