void EMSCRIPTEN_KEEPALIVE rig_pb_stream_websocket_ready_cb(int fd, void *user_data) { rig_pb_stream_t *stream = user_data; struct msghdr message; struct iovec buf; uint8_t page[PAGE_SIZE]; if (!stream->read_callback) return; memset(&message, 0, sizeof(message)); message.msg_iovlen = 1; message.msg_iov = &buf; buf.iov_base = page; buf.iov_len = PAGE_SIZE; c_debug("websocket ready callback\n"); for (;;) { int len = recvmsg(stream->websocket_client.socket, &message, 0 /* flags */); if (len > 0) { c_debug("websocket recieved %d bytes\n", len); stream->read_callback(stream, (uint8_t *)page, len, stream->read_data); } else break; } }
static void slave__test(Rig__Slave_Service *service, const Rig__Query *query, Rig__TestResult_Closure closure, void *closure_data) { Rig__TestResult result = RIG__TEST_RESULT__INIT; // rig_slave_t *slave = rig_pb_rpc_closure_get_connection_data // (closure_data); c_return_if_fail(query != NULL); c_debug("Test Query\n"); closure(&result, closure_data); }
static bool validate_statements(cg_device_t *dev, cg_blend_string_statement_t *statements, int n_statements, cg_error_t **error) { const char *error_string; if (n_statements == 1) { if (statements[0].mask == CG_BLEND_STRING_CHANNEL_MASK_ALPHA) { error_string = "You need to also give a blend statement for the RGB " "channels"; goto error; } else if (statements[0].mask == CG_BLEND_STRING_CHANNEL_MASK_RGB) { error_string = "You need to also give a blend statement for the " "Alpha channel"; goto error; } } return validate_blend_statements(dev, statements, n_statements, error); error: _cg_set_error(error, CG_BLEND_STRING_ERROR, CG_BLEND_STRING_ERROR_INVALID_ERROR, "Invalid blend string: %s", error_string); if (CG_DEBUG_ENABLED(CG_DEBUG_BLEND_STRINGS)) c_debug("Invalid blend string: %s", error_string); return false; }
bool _cg_blend_string_compile(cg_device_t *dev, const char *string, cg_blend_string_statement_t *statements, cg_error_t **error) { const char *p = string; const char *mark = NULL; const char *error_string; parser_state_t state = PARSER_STATE_EXPECT_DEST_CHANNELS; cg_blend_string_statement_t *statement = statements; int current_statement = 0; int current_arg = 0; int remaining_argc = 0; #if 0 CG_DEBUG_SET_FLAG (CG_DEBUG_BLEND_STRINGS); #endif if (CG_DEBUG_ENABLED(CG_DEBUG_BLEND_STRINGS)) { CG_NOTE(BLEND_STRINGS, "Compiling blend string:\n%s\n", string); } do { if (c_ascii_isspace(*p)) continue; if (*p == '\0') { switch (state) { case PARSER_STATE_EXPECT_DEST_CHANNELS: if (current_statement != 0) goto finished; error_string = "Empty statement"; goto error; case PARSER_STATE_SCRAPING_DEST_CHANNELS: error_string = "Expected an '=' following the destination " "channel mask"; goto error; case PARSER_STATE_EXPECT_FUNCTION_NAME: error_string = "Expected a function name"; goto error; case PARSER_STATE_SCRAPING_FUNCTION_NAME: error_string = "Expected parenthesis after the function name"; goto error; case PARSER_STATE_EXPECT_ARG_START: error_string = "Expected to find the start of an argument"; goto error; case PARSER_STATE_EXPECT_STATEMENT_END: error_string = "Expected closing parenthesis for statement"; goto error; } } switch (state) { case PARSER_STATE_EXPECT_DEST_CHANNELS: mark = p; state = PARSER_STATE_SCRAPING_DEST_CHANNELS; /* fall through */ case PARSER_STATE_SCRAPING_DEST_CHANNELS: if (*p != '=') continue; if (strncmp(mark, "RGBA", 4) == 0) statement->mask = CG_BLEND_STRING_CHANNEL_MASK_RGBA; else if (strncmp(mark, "RGB", 3) == 0) statement->mask = CG_BLEND_STRING_CHANNEL_MASK_RGB; else if (strncmp(mark, "A", 1) == 0) statement->mask = CG_BLEND_STRING_CHANNEL_MASK_ALPHA; else { error_string = "Unknown destination channel mask; " "expected RGBA=, RGB= or A="; goto error; } state = PARSER_STATE_EXPECT_FUNCTION_NAME; continue; case PARSER_STATE_EXPECT_FUNCTION_NAME: mark = p; state = PARSER_STATE_SCRAPING_FUNCTION_NAME; /* fall through */ case PARSER_STATE_SCRAPING_FUNCTION_NAME: if (*p != '(') { if (!is_alphanum_char(*p)) { error_string = "non alpha numeric character in function" "name"; goto error; } continue; } statement->function = get_function_info(mark, p); if (!statement->function) { error_string = "Unknown function name"; goto error; } remaining_argc = statement->function->argc; current_arg = 0; state = PARSER_STATE_EXPECT_ARG_START; /* fall through */ case PARSER_STATE_EXPECT_ARG_START: if (*p != '(' && *p != ',') continue; if (remaining_argc) { p++; /* parse_argument expects to see the first char of the arg */ if (!parse_argument(string, &p, statement, current_arg, &statement->args[current_arg], error)) return 0; current_arg++; remaining_argc--; } if (!remaining_argc) state = PARSER_STATE_EXPECT_STATEMENT_END; continue; case PARSER_STATE_EXPECT_STATEMENT_END: if (*p != ')') { error_string = "Expected end of statement"; goto error; } state = PARSER_STATE_EXPECT_DEST_CHANNELS; if (current_statement++ == 1) goto finished; statement = &statements[current_statement]; } } while (p++); finished: if (CG_DEBUG_ENABLED(CG_DEBUG_BLEND_STRINGS)) { if (current_statement > 0) print_statement(0, &statements[0]); if (current_statement > 1) print_statement(1, &statements[1]); } if (!validate_statements(dev, statements, current_statement, error)) return 0; return current_statement; error: { int offset = p - string; _cg_set_error(error, CG_BLEND_STRING_ERROR, CG_BLEND_STRING_ERROR_PARSE_ERROR, "Syntax error for string \"%s\" at offset %d: %s", string, offset, error_string); if (CG_DEBUG_ENABLED(CG_DEBUG_BLEND_STRINGS)) { c_debug("Syntax error at offset %d: %s", offset, error_string); } return 0; } }
static bool parse_argument(const char *string, /* original user string */ const char **ret_p, /* start of argument IN:OUT */ const cg_blend_string_statement_t *statement, int current_arg, cg_blend_string_argument_t *arg, /* OUT */ cg_error_t **error) { const char *p = *ret_p; const char *mark = NULL; const char *error_string = NULL; parser_arg_state_t state = PARSER_ARG_STATE_START; bool parsing_factor = false; bool implicit_factor_brace; arg->source.is_zero = false; arg->source.info = NULL; arg->source.texture = 0; arg->source.one_minus = false; arg->source.mask = statement->mask; arg->factor.is_one = false; arg->factor.is_color = false; arg->factor.is_src_alpha_saturate = false; arg->factor.source.is_zero = false; arg->factor.source.info = NULL; arg->factor.source.texture = 0; arg->factor.source.one_minus = false; arg->factor.source.mask = statement->mask; do { if (c_ascii_isspace(*p)) continue; if (*p == '\0') { error_string = "Unexpected end of string while parsing argument"; goto error; } switch (state) { case PARSER_ARG_STATE_START: if (*p == '1') state = PARSER_ARG_STATE_EXPECT_MINUS; else if (*p == '0') { arg->source.is_zero = true; state = PARSER_ARG_STATE_EXPECT_END; } else { p--; /* backtrack */ state = PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME; } continue; case PARSER_ARG_STATE_EXPECT_MINUS: if (*p != '-') { error_string = "expected a '-' following the 1"; goto error; } arg->source.one_minus = true; state = PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME; continue; case PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME: if (!is_symbol_char(*p)) { error_string = "expected a color source name"; goto error; } state = PARSER_ARG_STATE_SCRAPING_COLOR_SRC_NAME; mark = p; if (parsing_factor) arg->factor.is_color = true; /* fall through */ case PARSER_ARG_STATE_SCRAPING_COLOR_SRC_NAME: if (!is_symbol_char(*p)) { cg_blend_string_color_source_t *source = parsing_factor ? &arg->factor.source : &arg->source; source->info = get_color_src_info(mark, p); if (!source->info) { error_string = "Unknown color source name"; goto error; } state = PARSER_ARG_STATE_MAYBE_COLOR_MASK; } else continue; /* fall through */ case PARSER_ARG_STATE_MAYBE_COLOR_MASK: if (*p != '[') { p--; /* backtrack */ if (!parsing_factor) state = PARSER_ARG_STATE_MAYBE_MULT; else state = PARSER_ARG_STATE_EXPECT_END; continue; } state = PARSER_ARG_STATE_SCRAPING_MASK; mark = p; /* fall through */ case PARSER_ARG_STATE_SCRAPING_MASK: if (*p == ']') { size_t len = p - mark; cg_blend_string_color_source_t *source = parsing_factor ? &arg->factor.source : &arg->source; if (len == 5 && strncmp(mark, "[RGBA", len) == 0) { if (statement->mask != CG_BLEND_STRING_CHANNEL_MASK_RGBA) { error_string = "You can't use an RGBA color mask if the " "statement hasn't also got an RGBA= mask"; goto error; } source->mask = CG_BLEND_STRING_CHANNEL_MASK_RGBA; } else if (len == 4 && strncmp(mark, "[RGB", len) == 0) source->mask = CG_BLEND_STRING_CHANNEL_MASK_RGB; else if (len == 2 && strncmp(mark, "[A", len) == 0) source->mask = CG_BLEND_STRING_CHANNEL_MASK_ALPHA; else { error_string = "Expected a channel mask of [RGBA]" "[RGB] or [A]"; goto error; } if (parsing_factor) state = PARSER_ARG_STATE_EXPECT_CLOSE_PAREN; else state = PARSER_ARG_STATE_MAYBE_MULT; } continue; case PARSER_ARG_STATE_EXPECT_OPEN_PAREN: if (*p != '(') { if (is_alphanum_char(*p)) { p--; /* compensate for implicit brace and ensure this * char gets considered part of the blend factor */ implicit_factor_brace = true; } else { error_string = "Expected '(' around blend factor or alpha " "numeric character for blend factor name"; goto error; } } else implicit_factor_brace = false; parsing_factor = true; state = PARSER_ARG_STATE_EXPECT_FACTOR; continue; case PARSER_ARG_STATE_EXPECT_FACTOR: if (*p == '1') state = PARSER_ARG_STATE_MAYBE_MINUS; else if (*p == '0') { arg->source.is_zero = true; state = PARSER_ARG_STATE_EXPECT_CLOSE_PAREN; } else { state = PARSER_ARG_STATE_MAYBE_SRC_ALPHA_SATURATE; mark = p; } continue; case PARSER_ARG_STATE_MAYBE_SRC_ALPHA_SATURATE: if (!is_symbol_char(*p)) { size_t len = p - mark; if (len >= strlen("SRC_ALPHA_SATURATE") && strncmp(mark, "SRC_ALPHA_SATURATE", len) == 0) { arg->factor.is_src_alpha_saturate = true; state = PARSER_ARG_STATE_EXPECT_CLOSE_PAREN; } else { state = PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME; p = mark - 1; /* backtrack */ } } continue; case PARSER_ARG_STATE_MAYBE_MINUS: if (*p == '-') { if (implicit_factor_brace) { error_string = "Expected ( ) braces around blend factor with " "a subtraction"; goto error; } arg->factor.source.one_minus = true; state = PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME; } else { arg->factor.is_one = true; state = PARSER_ARG_STATE_EXPECT_CLOSE_PAREN; } continue; case PARSER_ARG_STATE_EXPECT_CLOSE_PAREN: if (implicit_factor_brace) { p--; state = PARSER_ARG_STATE_EXPECT_END; continue; } if (*p != ')') { error_string = "Expected closing parenthesis after blend factor"; goto error; } state = PARSER_ARG_STATE_EXPECT_END; continue; case PARSER_ARG_STATE_MAYBE_MULT: if (*p == '*') { state = PARSER_ARG_STATE_EXPECT_OPEN_PAREN; continue; } arg->factor.is_one = true; state = PARSER_ARG_STATE_EXPECT_END; /* fall through */ case PARSER_ARG_STATE_EXPECT_END: if (*p != ',' && *p != ')') { error_string = "expected , or )"; goto error; } *ret_p = p - 1; return true; } } while (p++); error: { int offset = p - string; _cg_set_error(error, CG_BLEND_STRING_ERROR, CG_BLEND_STRING_ERROR_ARGUMENT_PARSE_ERROR, "Syntax error for argument %d at offset %d: %s", current_arg, offset, error_string); if (CG_DEBUG_ENABLED(CG_DEBUG_BLEND_STRINGS)) { c_debug("Syntax error for argument %d at offset %d: %s", current_arg, offset, error_string); } return false; } }
void rig_pb_stream_write(rig_pb_stream_t *stream, rig_pb_stream_write_closure_t *closure) { c_return_if_fail(stream->type != STREAM_TYPE_DISCONNECTED); switch (stream->type) { case STREAM_TYPE_BUFFER: { c_return_if_fail(stream->buffer.other_end != NULL); c_return_if_fail(stream->buffer.other_end->type == STREAM_TYPE_BUFFER); c_array_append_val(stream->buffer.other_end->buffer.incoming_write_closures, closure); queue_data_buffer_stream_read(stream->buffer.other_end); break; } #ifdef USE_UV case STREAM_TYPE_FD: case STREAM_TYPE_TCP: { closure->write_req.data = closure; uv_write(&closure->write_req, (uv_stream_t *)&stream->fd.uv_fd_pipe, &closure->buf, 1, /* n buffers */ uv_write_done_cb); break; } case STREAM_TYPE_WEBSOCKET_SERVER: { struct wslay_event_fragmented_msg arg; memset(&arg, 0, sizeof(arg)); arg.opcode = WSLAY_BINARY_FRAME; arg.source.data = closure; arg.read_callback = fragmented_wslay_read_cb; closure->current_offset = 0; wslay_event_queue_fragmented_msg(stream->websocket_server.ctx, &arg); wslay_event_send(stream->websocket_server.ctx); break; } #endif #ifdef __EMSCRIPTEN__ case STREAM_TYPE_WORKER_IPC: if (stream->worker_ipc.in_worker) rig_emscripten_worker_post_to_main(closure->buf.base, closure->buf.len); else rig_emscripten_worker_post(stream->worker_ipc.worker, "rig_pb_stream_worker_onmessage", closure->buf.base, closure->buf.len); closure->done_callback(closure); break; case STREAM_TYPE_WEBSOCKET_CLIENT: c_debug("stream: websocket send() %d bytes", closure->buf.len); send(stream->websocket_client.socket, closure->buf.base, closure->buf.len, 0 /* flags */); closure->done_callback(closure); break; #endif case STREAM_TYPE_DISCONNECTED: c_warn_if_reached(); break; } }
void docmd(void) { int c; struct ww *w; char out = 0; while (!out && !quit) { if ((c = wwgetc()) < 0) { if (terse) wwsetcursor(0, 0); else { wwputs("Command: ", cmdwin); wwcurtowin(cmdwin); } do wwiomux(); while ((c = wwgetc()) < 0); } if (!terse) wwputc('\n', cmdwin); switch (c) { default: if (c != escapec) break; case 'h': case 'j': case 'k': case 'l': case 'y': case 'p': case ctrl('y'): case ctrl('e'): case ctrl('u'): case ctrl('d'): case ctrl('b'): case ctrl('f'): case ctrl('s'): case ctrl('q'): case ctrl('['): if (selwin == 0) { error("No window."); continue; } } switch (c) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if ((w = window[c - '1']) == 0) { error("%c: No such window.", c); break; } setselwin(w); if (checkproc(selwin) >= 0) out = 1; break; case '%': if ((w = getwin()) != 0) setselwin(w); break; case ctrl('^'): if (lastselwin != 0) { setselwin(lastselwin); if (checkproc(selwin) >= 0) out = 1; } else error("No previous window."); break; case 'c': if ((w = getwin()) != 0) closewin(w); break; case 'w': c_window(); break; case 'm': if ((w = getwin()) != 0) c_move(w); break; case 'M': if ((w = getwin()) != 0) movewin(w, w->ww_alt.t, w->ww_alt.l); break; case 's': if ((w = getwin()) != 0) c_size(w); break; case 'S': if ((w = getwin()) != 0) sizewin(w, w->ww_alt.nr, w->ww_alt.nc); break; case 'y': c_yank(); break; case 'p': c_put(); break; case ':': c_colon(); break; case 'h': (void) wwwrite(selwin, "\b", 1); break; case 'j': (void) wwwrite(selwin, "\n", 1); break; case 'k': (void) wwwrite(selwin, "\033A", 2); break; case 'l': (void) wwwrite(selwin, "\033C", 2); break; case ctrl('e'): wwscroll(selwin, 1); break; case ctrl('y'): wwscroll(selwin, -1); break; case ctrl('d'): wwscroll(selwin, selwin->ww_w.nr / 2); break; case ctrl('u'): wwscroll(selwin, - selwin->ww_w.nr / 2); break; case ctrl('f'): wwscroll(selwin, selwin->ww_w.nr); break; case ctrl('b'): wwscroll(selwin, - selwin->ww_w.nr); break; case ctrl('s'): stopwin(selwin); break; case ctrl('q'): startwin(selwin); break; case ctrl('l'): wwredraw(); break; case '?': c_help(); break; case ctrl('['): if (checkproc(selwin) >= 0) out = 1; break; case ctrl('z'): wwsuspend(); break; case 'q': c_quit(); break; /* debugging stuff */ case '&': if (debug) { c_debug(); break; } default: if (c == escapec) { if (checkproc(selwin) >= 0) { (void) write(selwin->ww_pty, &escapec, 1); out = 1; } } else { if (!terse) wwbell(); error("Type ? for help."); } } } if (!quit) setcmd(0); }