Exemplo n.º 1
0
int main(int argc, char **argv)
{
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);

    SDL_CreateWindowAndRenderer(SCREEN_WIDTH+232, SCREEN_HEIGHT+16, 0, &displayWindow, &displayRenderer);
    SDL_GetRendererInfo(displayRenderer, &displayRendererInfo);
    SDL_SetRenderDrawBlendMode(displayRenderer, SDL_BLENDMODE_BLEND);

    SCREEN_SHIFT_X = 8;
    SCREEN_SHIFT_Y = 8;

#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(null_loop_iter, 60, 1);
#endif

    srand(time(NULL));
    sound_init();
    resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT);
    load_resources();

    last_time = clock();

#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(loop_iter, 60, 1);
#else
    while (!done)
    {
        loop_iter();
    }
#endif

    sound_exit();
    Quit(0);
    return (0);
}
Exemplo n.º 2
0
int dbusrecv_getmsg(DBusMessage *message, char **pp_buf, int *p_length)
{

    DBusMessageIter iter;
#ifdef DBUSRECV_MSG_DEBUG
    int message_type = 0;
    const char *sender = NULL;
    const char *destination = NULL;
#endif
    int bytecount = 0;

    if (NULL == message)
    {
        printf("dbusrecv_getmsg: invalid parameters!\n");
        return -1;
    }

#ifdef DBUSRECV_MSG_DEBUG
    message_type = dbus_message_get_type (message);
    sender = dbus_message_get_sender (message);
    destination = dbus_message_get_destination (message);
#endif
    dbus_message_iter_init (message, &iter);
    bytecount = loop_iter(&iter, 1, pp_buf, p_length);
#ifdef DBUSRECV_MSG_DEBUG
    if (bytecount > 0)
    {
        int i=0;
        char *p = *pp_buf;
        printf("-------------start(len=%d)-----------\n", bytecount);
        for (i=0; i<bytecount; i++)
            printf("%02x ", p[i]);
        printf("\n-------------end----------------\n");
    }
#endif
    return bytecount;
}
Exemplo n.º 3
0
int loop_iter (DBusMessageIter *iter, int depth, char **pp_buf, int *p_length)
{
    int retval = 0;
    int type = 0;
    int max_buf_len = 0;
    char *p_buf = NULL;

    do
    {
        type = dbus_message_iter_get_arg_type (iter);
        if (type == DBUS_TYPE_INVALID)
            break;
        switch (type)
        {
        case DBUS_TYPE_ARRAY:
        {
            int current_type;
            DBusMessageIter subiter;

            dbus_message_iter_recurse (iter, &subiter);
            current_type = dbus_message_iter_get_arg_type (&subiter);
            //msg_len = dbus_message_iter_get_array_len(&subiter)
            if (current_type == DBUS_TYPE_BYTE)
            {
                unsigned int len = 0;
                int current_type_tmp;

                if (NULL == p_buf)
                {
                    p_buf = DBUS_MALLOC(DEFAULT_DBUSRECV_MSG_LEN + 1);
                    max_buf_len = DEFAULT_DBUSRECV_MSG_LEN;
                }
                if (NULL == p_buf)
                {
                    printf("loop_iter: malloc failed, p_buf!\n");
                    return -1;
                }
                while ((current_type_tmp = dbus_message_iter_get_arg_type (&subiter))
                        != DBUS_TYPE_INVALID)
                {
                    unsigned char val;
                    dbus_message_iter_get_basic (&subiter, &val);
                    p_buf[len] = val;
                    len++;
                    if (len == max_buf_len)
                    {
                        max_buf_len <<= 1;
                        p_buf = DBUS_REALLOC(p_buf, max_buf_len+1);
                        if (NULL == p_buf)
                        {
                            printf("loop_iter: DBUS_REALLOC failed, p_buf!\n");
                            return -1;
                        }
                    }
                    dbus_message_iter_next (&subiter);
                }
                p_buf[len] = '\0';
                *pp_buf = p_buf;
                *p_length = len;
                retval = len;
                break;
            }
            while (current_type != DBUS_TYPE_INVALID)
            {
                loop_iter (&subiter, depth+1, pp_buf, p_length);
                dbus_message_iter_next (&subiter);
            }
            break;
        }

        default:
            break;
        }
    } while(dbus_message_iter_next (iter));

    return retval;
}