Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/vlaunch/vlaunch.c

    r87c0a45 r1c635d6  
    3333 */
    3434
    35 #include <bool.h>
     35#include <stdbool.h>
    3636#include <errno.h>
    3737#include <stdio.h>
     
    4141#include <str.h>
    4242#include <str_error.h>
     43#include <loc.h>
     44#include <fibril_synch.h>
     45#include <io/pixel.h>
     46#include <device/led_dev.h>
    4347
    4448#include <window.h>
     
    4650#include <button.h>
    4751#include <label.h>
    48 
    49 #define NAME "vlaunch"
     52#include <canvas.h>
     53
     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
     63#define LOGO_WIDTH   196
     64#define LOGO_HEIGHT  66
     65
     66#define PERIOD  1000000
     67#define COLORS  7
    5068
    5169static char *winreg = NULL;
     70static fibril_timer_t *timer = NULL;
     71static list_t led_devs;
     72
     73static 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
     83static unsigned int color = 0;
     84
     85typedef struct {
     86        link_t link;
     87        service_id_t svc_id;
     88        async_sess_t *sess;
     89} led_dev_t;
    5290
    5391static int app_launch(const char *app)
    5492{
    55         int rc;
    5693        printf("%s: Spawning %s %s \n", NAME, app, winreg);
    57 
     94       
    5895        task_id_t id;
    59         task_exit_t texit;
    60         int retval;
    61         rc = task_spawnl(&id, app, app, winreg, NULL);
     96        task_wait_t wait;
     97        int rc = task_spawnl(&id, &wait, app, app, winreg, NULL);
    6298        if (rc != EOK) {
    6399                printf("%s: Error spawning %s %s (%s)\n", NAME, app,
     
    65101                return -1;
    66102        }
    67         rc = task_wait(id, &texit, &retval);
    68         if (rc != EOK || texit != TASK_EXIT_NORMAL) {
     103       
     104        task_exit_t texit;
     105        int retval;
     106        rc = task_wait(&wait, &texit, &retval);
     107        if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
    69108                printf("%s: Error retrieving retval from %s (%s)\n", NAME,
    70109                    app, str_error(rc));
    71110                return -1;
    72111        }
    73 
     112       
    74113        return retval;
    75114}
     
    88127{
    89128        app_launch("/app/vlaunch");
     129}
     130
     131static void timer_callback(void *data)
     132{
     133        pixel_t next_color = colors[color];
     134       
     135        color++;
     136        if (color >= COLORS)
     137                color = 0;
     138       
     139        list_foreach(led_devs, link, led_dev_t, dev) {
     140                if (dev->sess)
     141                        led_dev_color_set(dev->sess, next_color);
     142        }
     143       
     144        fibril_timer_set(timer, PERIOD, timer_callback, NULL);
     145}
     146
     147static void loc_callback(void)
     148{
     149        category_id_t led_cat;
     150        int rc = loc_category_get_id("led", &led_cat, IPC_FLAG_BLOCKING);
     151        if (rc != EOK)
     152                return;
     153       
     154        service_id_t *svcs;
     155        size_t count;
     156        rc = loc_category_get_svcs(led_cat, &svcs, &count);
     157        if (rc != EOK)
     158                return;
     159       
     160        for (size_t i = 0; i < count; i++) {
     161                bool known = false;
     162               
     163                /* Determine whether we already know this device. */
     164                list_foreach(led_devs, link, led_dev_t, dev) {
     165                        if (dev->svc_id == svcs[i]) {
     166                                known = true;
     167                                break;
     168                        }
     169                }
     170               
     171                if (!known) {
     172                        led_dev_t *dev = (led_dev_t *) calloc(1, sizeof(led_dev_t));
     173                        if (!dev)
     174                                continue;
     175                       
     176                        link_initialize(&dev->link);
     177                        dev->svc_id = svcs[i];
     178                        dev->sess = loc_service_connect(EXCHANGE_SERIALIZE, svcs[i], 0);
     179                       
     180                        list_append(&dev->link, &led_devs);
     181                }
     182        }
     183       
     184        // FIXME: Handle LED device removal
     185       
     186        free(svcs);
    90187}
    91188
     
    94191        if (argc < 2) {
    95192                printf("Compositor server not specified.\n");
     193                return 1;
     194        }
     195       
     196        list_initialize(&led_devs);
     197        int rc = loc_register_cat_change_cb(loc_callback);
     198        if (rc != EOK) {
     199                printf("Unable to register callback for device discovery.\n");
     200                return 1;
     201        }
     202       
     203        timer = fibril_timer_create(NULL);
     204        if (!timer) {
     205                printf("Unable to create timer.\n");
     206                return 1;
     207        }
     208       
     209        surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size, 0);
     210        if (!logo) {
     211                printf("Unable to decode logo.\n");
    96212                return 1;
    97213        }
     
    104220        }
    105221       
    106         pixel_t grd_bg = PIXEL(255, 240, 240, 240);
    107         pixel_t btn_bg = PIXEL(255, 0, 0, 0);
    108         pixel_t btn_fg = PIXEL(255, 240, 240, 240);
    109         pixel_t lbl_bg = PIXEL(255, 240, 240, 240);
    110         pixel_t lbl_fg = PIXEL(255, 0, 0, 0);
    111        
     222        pixel_t grd_bg = PIXEL(255, 255, 255, 255);
     223       
     224        pixel_t btn_bg = PIXEL(255, 255, 255, 255);
     225        pixel_t btn_fg = PIXEL(255, 186, 186, 186);
     226        pixel_t btn_text = PIXEL(255, 0, 0, 0);
     227       
     228        pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
     229        pixel_t lbl_text = PIXEL(255, 0, 0, 0);
     230       
     231        canvas_t *logo_canvas = create_canvas(NULL, LOGO_WIDTH, LOGO_HEIGHT,
     232            logo);
    112233        label_t *lbl_caption = create_label(NULL, "Launch application:", 16,
    113             lbl_bg, lbl_fg);
     234            lbl_bg, lbl_text);
    114235        button_t *btn_vterm = create_button(NULL, "vterm", 16, btn_bg,
    115             btn_fg);
     236            btn_fg, btn_text);
    116237        button_t *btn_vdemo = create_button(NULL, "vdemo", 16, btn_bg,
    117             btn_fg);
     238            btn_fg, btn_text);
    118239        button_t *btn_vlaunch = create_button(NULL, "vlaunch", 16, btn_bg,
    119             btn_fg);
    120         grid_t *grid = create_grid(window_root(main_window), 4, 1, grd_bg);
    121        
    122         if ((!lbl_caption) || (!btn_vterm) || (!btn_vdemo) ||
    123             (!btn_vlaunch) || (!grid)) {
     240            btn_fg, btn_text);
     241        grid_t *grid = create_grid(window_root(main_window), 1, 5, grd_bg);
     242       
     243        if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) ||
     244            (!btn_vdemo) || (!btn_vlaunch) || (!grid)) {
    124245                window_close(main_window);
    125246                printf("Cannot create widgets.\n");
     
    131252        sig_connect(&btn_vlaunch->clicked, NULL, on_vlaunch);
    132253       
    133         grid->add(grid, &lbl_caption->widget, 0, 0, 1, 1);
    134         grid->add(grid, &btn_vterm->widget, 1, 0, 1, 1);
    135         grid->add(grid, &btn_vdemo->widget, 2, 0, 1, 1);
    136         grid->add(grid, &btn_vlaunch->widget, 3, 0, 1, 1);
    137        
    138         window_resize(main_window, 180, 130);
     254        grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1);
     255        grid->add(grid, &lbl_caption->widget, 0, 1, 1, 1);
     256        grid->add(grid, &btn_vterm->widget, 0, 2, 1, 1);
     257        grid->add(grid, &btn_vdemo->widget, 0, 3, 1, 1);
     258        grid->add(grid, &btn_vlaunch->widget, 0, 4, 1, 1);
     259       
     260        window_resize(main_window, 0, 0, 210, 130 + LOGO_HEIGHT,
     261            WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_TOP);
    139262        window_exec(main_window);
     263       
     264        fibril_timer_set(timer, PERIOD, timer_callback, NULL);
     265       
    140266        task_retval(0);
    141267        async_manager();
Note: See TracChangeset for help on using the changeset viewer.