Changeset 72d120e in mainline for uspace/app/vlaunch/vlaunch.c


Ignore:
Timestamp:
2014-06-16T20:17:44Z (10 years ago)
Author:
Agnieszka Tabaka <nufcia@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5a78e4e
Parents:
9d653e3 (diff), 334bf28 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Integrate from mainline.

File:
1 edited

Legend:

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

    r9d653e3 r72d120e  
    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>
     
    6064#define LOGO_HEIGHT  66
    6165
     66#define PERIOD  1000000
     67#define COLORS  7
     68
    6269static 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;
    6390
    6491static int app_launch(const char *app)
    6592{
    66         int rc;
    6793        printf("%s: Spawning %s %s \n", NAME, app, winreg);
    68 
     94       
    6995        task_id_t id;
    70         task_exit_t texit;
    71         int retval;
    72         rc = task_spawnl(&id, app, app, winreg, NULL);
     96        int rc = task_spawnl(&id, app, app, winreg, NULL);
    7397        if (rc != EOK) {
    7498                printf("%s: Error spawning %s %s (%s)\n", NAME, app,
     
    76100                return -1;
    77101        }
     102       
     103        task_exit_t texit;
     104        int retval;
    78105        rc = task_wait(id, &texit, &retval);
    79         if (rc != EOK || texit != TASK_EXIT_NORMAL) {
     106        if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
    80107                printf("%s: Error retrieving retval from %s (%s)\n", NAME,
    81108                    app, str_error(rc));
    82109                return -1;
    83110        }
    84 
     111       
    85112        return retval;
    86113}
     
    99126{
    100127        app_launch("/app/vlaunch");
     128}
     129
     130static 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
     146static 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);
    101186}
    102187
     
    105190        if (argc < 2) {
    106191                printf("Compositor server not specified.\n");
     192                return 1;
     193        }
     194       
     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");
    107205                return 1;
    108206        }
     
    163261        window_exec(main_window);
    164262       
     263        fibril_timer_set(timer, PERIOD, timer_callback, NULL);
     264       
    165265        task_retval(0);
    166266        async_manager();
Note: See TracChangeset for help on using the changeset viewer.