/* issue a AXIOM command to the buffer associated with a page */ void issue_spadcommand(HyperDocPage *page, TextNode *command, int immediate, int type) { char *buf; int ret_val; ret_val = connect_spad(); if (ret_val == NotConnected || ret_val == SpadBusy) return; if (page->sock == NULL) start_user_buffer(page); ret_val = send_int(page->sock, TestLine); if (ret_val == -1) { page->sock = NULL; clear_execution_marks(page->depend_hash); issue_spadcommand(page, command, immediate, type); return; } issue_dependent_commands(page, command, type); ret_val = send_int(page->sock, ReceiveInputLine); buf = print_to_string(command); if (immediate) { buf[strlen(buf) + 1] = '\0'; buf[strlen(buf)] = '\n'; } if (type == Spadsrc) send_pile(page->sock, buf); else send_string(page->sock, buf); mark_as_executed(page, command, type); gIsEndOfOutput = 0; }
/* * Send execute messae. "conn" should at the point right after the message * kind was read. */ void process_execute(char *buf, PGconn *conn) { int len; char *portal; int maxrows; char *bufp; SKIP_TABS(buf); len = sizeof(int); portal = buffer_read_string(buf, &bufp); buf = bufp; len += strlen(portal) + 1; SKIP_TABS(buf); fprintf(stderr, "FE=> Execute(portal=\"%s\")\n", portal); SKIP_TABS(buf); maxrows = buffer_read_int(buf, &bufp); len += sizeof(int); send_char('E', conn); send_int(len, conn); send_string(portal, conn); send_int(maxrows, conn); }
Sock * connect_to_local_server(char *server_name, int purpose, int time_out) { int max_con=(time_out == 0 ? 1000000 : time_out), i, code=-1; Sock *sock; char name[256]; make_server_name(name, server_name); sock = (Sock *) calloc(sizeof(Sock), 1); if (sock == NULL) { perror("allocating socket space"); return NULL; } sock->purpose = purpose; /* create the socket */ sock->socket = fricas_communication_link(FRICAS_AF_LOCAL); if (is_invalid_socket(sock)) { perror("opening client socket"); free(sock); return NULL; } /* connect socket using name specified in command line */ memset(server[1].addr.u_addr.sa_data, 0, sizeof(server[1].addr.u_addr.sa_data)); sock->addr.u_addr.sa_family = FRICAS_AF_LOCAL; strcpy(sock->addr.u_addr.sa_data, name); for(i=0; i<max_con; i++) { code = connect(sock->socket, &sock->addr.u_addr, sizeof(sock->addr.u_addr)); if (code == -1) { if ( /* @@@ Why we need this */ errno != ENOENT && /* Needed on Cygwin, on Linux this should never happen. */ errno != EBADF && !fricas_connection_refused()) { perror("connecting server stream socket"); return NULL; } else { if (i != max_con - 1) fricas_sleep(40); continue; } } else break; } if (code == -1) { return NULL; } send_int(sock, getpid()); send_int(sock, sock->purpose); send_int(sock, sock->socket); sock->pid = get_int(sock); /* fprintf(stderr, "Got int form socket\n"); */ sock->remote = get_int(sock); return sock; }
/* Send EV_DATA and the integer value. Return 0 on error. */ static int send_data_int (const struct client *cli, const int data) { assert (cli->socket != -1); if (!send_int(cli->socket, EV_DATA) || !send_int(cli->socket, data)) return 0; return 1; }
void decimate_header() /* includefile */ { /* go no further here if not interested in header parameters */ if (headerless) return; /* broadcast the header parameters to the output stream */ send_string("HEADER_START"); if (!strings_equal(source_name,"")) { send_string("source_name"); send_string(source_name); } send_int("telescope_id",telescope_id); send_int("machine_id",machine_id); send_coords(src_raj,src_dej,az_start,za_start); if (nchans/naddc==1) { send_int("data_type",2); // send_double("refdm",0.0); send_double("refdm",refdm); /*== MKEITH: A hack to stop the dminfo being lost when decimating after dedisperse! ==*/ } else { send_int("data_type",1); } send_double("fch1",fch1); send_double("foff",foff*(double)naddc); send_int("nchans",nchans/naddc); send_int("nbits",obits); send_double ("tstart",tstart); send_double("tsamp",tsamp*(double)naddt); send_int("nifs",nifs); send_int("barycentric",barycentric); send_string("HEADER_END"); }
static void windows_kodi_load(Window *window){ // Create title TextLayer s_title_info_layer = text_layer_create(GRect(0, 10, 144, 25)); text_layer_set_background_color(s_title_info_layer, GColorClear); text_layer_set_text_color(s_title_info_layer, GColorRed); text_layer_set_text(s_title_info_layer, "Kodi"); // s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20)); // text_layer_set_font(s_title_info_layer, s_weather_font); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_title_info_layer)); // Create Movie TextLayer s_album_info_layer = text_layer_create(GRect(0, 60, 144, 25)); text_layer_set_background_color(s_album_info_layer, GColorClear); text_layer_set_text_color(s_album_info_layer, GColorRed); text_layer_set_text(s_album_info_layer, "Movie"); // s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20)); // text_layer_set_font(s_album_info_layer, s_weather_font); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_album_info_layer)); //Load action bar action_bar_nav_h_kodi(window); //Request info send_int("kodi", "init"); }
int vsend_int(int val, int nr_of_roles, ...) { int rc = 0; int i; role *r; va_list roles; #ifdef __DEBUG__ fprintf(stderr, " --> %s(%d)@%d ", __FUNCTION__, val, nr_of_roles); #endif va_start(roles, nr_of_roles); for (i=0; i<nr_of_roles; i++) { r = va_arg(roles, role *); #ifdef __DEBUG__ fprintf(stderr, " +"); #endif rc |= send_int(val, r, NULL); if (rc != 0) perror(__FUNCTION__); } va_end(roles); #ifdef __DEBUG__ fprintf(stderr, ".\n"); #endif return rc; }
void menu_select_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *data) { switch (cell_index->section) { case 0: switch (cell_index->row) { case 0: if (loading==0) carga_calendario(); break; case 1: if (loading==0) carga_fpp(); break; } break; case 1: switch (cell_index->row) { case 0: if (loading==0){ send_int(5,5); char version[20]; time_t now = time(NULL); struct tm *tick_time = localtime(&now); snprintf(version, 20, "Versión: %i-%i-%i",tick_time->tm_mday,(tick_time->tm_mon)+1,(tick_time->tm_year)-100); vibes_short_pulse(); loading = 0; layer_mark_dirty(menu_layer_get_layer(menu_layer)); } break; } break; } }
int sock_send_int(int purpose,int val) { if (accept_if_needed(purpose) != -1) return send_int(purpose_table[purpose], val); return -1; }
/* Handle CMD_GET_PLIST. Return 0 on error. */ static int get_client_plist (struct client *cli) { int first; debug ("Client with fd %d requests the playlist", cli->socket); /* Find the first connected client, and ask it to send the playlist. * Here, send 1 if there is a client with the playlist, or 0 if there * isn't. */ cli->requests_plist = 1; first = find_sending_plist (); if (first == -1) { debug ("No clients with the playlist"); cli->requests_plist = 0; if (!send_data_int(cli, 0)) return 0; return 1; } if (!send_data_int(cli, 1)) return 0; if (!send_int(clients[first].socket, EV_SEND_PLIST)) return 0; return 1; }
// send header long NetThread::sendHeader(SOCKET sock, const char *buf, long size) { // 0123456789ABCDEF char key[ENCRYPTION_KEY_LENGTH + 1] = {"@@@@@@@@@@@@@@@@"}; // copy encryption key #if 1 // simple description const char *encryption_key = qPrintable(settings->getPassword()); #else const char *encryption_key = settings->getPassword().toUtf8().constData(); #endif for (int i = 0;i < ENCRYPTION_KEY_LENGTH; i++){ if (encryption_key[i] == '\0') break; key[i] = encryption_key[i]; } COM_DATA *com_data = (COM_DATA*)buf; long data_long = com_data->data_type + (com_data->data_size & 0x0000ffff); com_data->encryption = ENCRYPTION_OFF; com_data->check_digit = ~data_long; for (int i = 0; i < ENCRYPTION_KEY_LENGTH; i++){ char key_char = ~key[i]; key_char += (char)((long)i * ~com_data->check_digit); com_data->check_digit_enc[i] = key_char; } //saveHeader("sentHeader.dat"); // send return send_int(sock, buf, size, 0); }
static int get_block(int conn, int fd, int max_size, int encrypt) { char *data; long len; int n_read, n, i, code; recv_string(conn, &data, &len); if (encrypt) { #ifdef HAVE_KRB4 char *unenc = malloc(len); if (!unenc) { send_int(conn, ENOMEM); return -1; } des_pcbc_encrypt((des_cblock *)data, (des_cblock *)unenc, len, sched, &ivec, 1); for (i = 0; i < 8; i++) ivec[i] = data[len - 8 + i] ^ unenc[len - 8 + i]; free(data); data = unenc; #endif } n_read = MIN(len, max_size); n = 0; while (n < n_read) { int n_wrote; n_wrote = write(fd, data + n, n_read - n); if (n_wrote == -1) { code = errno; com_err(whoami, errno, "writing file (get_file)"); send_int(conn, code); free(data); close(fd); return -1; } n += n_wrote; } free(data); return n; }
void tick_callback(struct tm *tick_time, TimeUnits units_changed) { //Every five minutes if(tick_time->tm_min % 1 == 0) { //Send an arbitrary message, the response will be handled by in_received_handler() send_int(1, 1); } }
/*** send_str ********************************************************* Send a character string through a socket. Input: socket - the socket to send on. str - the string to send Output: none. **********************************************************************/ void send_str( int socket, char str[] ) { int len; len = strlen( str ); send_int( socket, len ); send_data( socket, str, len ); }
void emergency_conf_select_click_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) { switch(cell_index->row) { case 0: send_int(0); init(); //remove this window frmo the stack window_stack_remove(window, false); break; case 1: send_int(4); emergency_init(); //remove this window frmo the stack window_stack_remove(window, false); break; } }
void down_click_handler(ClickRecognizerRef recognizer, void *context) { text_layer_set_text(incoming_text, "Declining Call"); vibes_cancel(); confirm_vibe(); send_int(KEY_BUTTON_EVENT, BUTTON_EVENT_DOWN); exit_counter = 2; tick_timer_service_subscribe(SECOND_UNIT, exit_timer); }
void up_click_handler(ClickRecognizerRef recognizer, void *context) { text_layer_set_text(incoming_text, "Call Accepted"); vibes_cancel(); confirm_vibe(); send_int(KEY_BUTTON_EVENT, BUTTON_EVENT_UP); call_counter = 10; tick_timer_service_subscribe(SECOND_UNIT, timer); }
void UARTWriteRes(unsigned int res_[2]) { while (!(IFG2&UCA0TXIFG)); // Check the buffer print("Current I = "); send_int(res_[0]); print(", Voltage V = "); send_intln(res_[1]); }
int send_ints(Sock *sock, int *vals, int num) { int i; for(i=0; i<num; i++) if (send_int(sock, *vals++) == -1) return -1; return 0; }
static void menu_select_callback(int index, void *ctx) { if(index == 0) { APP_LOG( APP_LOG_LEVEL_INFO, "Quick Reply" ); send_int(0, 0); // } else { APP_LOG( APP_LOG_LEVEL_INFO, "Text reply" ); tertiary_text_prompt( "What's your name?", callback, NULL ); } }
/////////////////////////////////////////// BUTTON BEHAVIOURS ////////////////////////////////////////// void reply_up_click_handler(ClickRecognizerRef recognizer, void *context) { text_layer_set_text(busy_text, "Sending Msg..."); text_layer_set_text(callback_text, " "); text_layer_set_text(lol_text, " "); confirm_vibe(); send_int(KEY_BUTTON_REPLY, REPLY_BUSY); call_counter = 2; tick_timer_service_subscribe(SECOND_UNIT, reply_timer); }
void select_click_handler(ClickRecognizerRef recognizer, void *context) { vibes_cancel(); send_int(KEY_BUTTON_EVENT, BUTTON_EVENT_SELECT); confirm_vibe(); reply_window = window_create(); window_set_window_handlers(reply_window, (WindowHandlers) { .load = replywindow_load, .unload = replywindow_unload, });
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { //Every five minutes if(tick_time->tm_min % 10 == 0) { //Send an arbitrary message, the response will be handled by in_received_handler() send_int(5, 5); } update_time(); }
/* Ping the server. * Return 1 if the server responds with EV_PONG, otherwise 0. */ static int ping_server (int sock) { int event; send_int(sock, CMD_PING); /* ignore errors - the server could have already closed the connection and sent EV_BUSY */ if (!get_int(sock, &event)) fatal ("Error when receiving pong response!"); return event == EV_PONG ? 1 : 0; }
int send_string(Sock *sock, char *str) { int val, len = strlen(str); send_int(sock, len+1); val = swrite(sock, str, len+1, NULL); if (val == -1) { return -1; } return 0; }
/* Close all client connections sending EV_EXIT. */ static void close_clients () { int i; for (i = 0; i < CLIENTS_MAX; i++) if (clients[i].socket != -1) { send_int (clients[i].socket, EV_EXIT); close (clients[i].socket); del_client (&clients[i]); } }
/* reads a the socket purpose declaration for classification */ void get_socket_type(Sock *sock) { sock->pid = get_int(sock); sock->purpose = get_int(sock); sock->remote = get_int(sock); send_int(sock, getpid()); send_int(sock, sock->socket); purpose_table[sock->purpose] = sock; switch (sock->purpose) { case SessionManager: break; case ViewportServer: break; case MenuServer: break; case SessionIO: /* redirect_stdio(sock); */ break; } }
static void windows_squeezebox_load(Window *window){ // layer_mark_dirty(simple_menu_layer_get_layer(s_simple_menu_layer)); // Initialize the action bar: action_bar = action_bar_layer_create(); action_bar_layer_set_background_color(action_bar, GColorRed); // Associate the action bar with the window: action_bar_layer_add_to_window(action_bar, window); // Set the click config provider: action_bar_layer_set_click_config_provider(action_bar, click_config_provider2); // Set the icons: s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_PLAY); // The loading of the icons is omitted for brevity... See gbitmap_create_with_resource() action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_SELECT, s_background_bitmap, true); s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_PREVIOUS); action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_UP, s_background_bitmap, true); s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_NEXT); action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_DOWN, s_background_bitmap, true); // Create title TextLayer s_title_info_layer = text_layer_create(GRect(0, 30, 144, 25)); text_layer_set_background_color(s_title_info_layer, GColorClear); text_layer_set_text_color(s_title_info_layer, GColorRed); text_layer_set_text(s_title_info_layer, "title"); // s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20)); // text_layer_set_font(s_title_info_layer, s_weather_font); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_title_info_layer)); // Create album TextLayer s_album_info_layer = text_layer_create(GRect(0, 60, 144, 25)); text_layer_set_background_color(s_album_info_layer, GColorClear); text_layer_set_text_color(s_album_info_layer, GColorRed); text_layer_set_text(s_album_info_layer, "album"); // s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20)); // text_layer_set_font(s_album_info_layer, s_weather_font); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_album_info_layer)); // Create artist TextLayer s_artist_info_layer = text_layer_create(GRect(0, 90, 144, 25)); text_layer_set_background_color(s_artist_info_layer, GColorClear); text_layer_set_text_color(s_artist_info_layer, GColorRed); text_layer_set_text(s_artist_info_layer, "artist"); // s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20)); // text_layer_set_font(s_artist_info_layer, s_weather_font); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_artist_info_layer)); //Request track info send_int("sb", "track_info"); }
// send data long NetThread::sendData(SOCKET sock, const char *buf, long size) { #if 1 // for TEST long sent_size = 0; while(sent_size < size){ long ret = send_int(sock, buf + sent_size, size - sent_size, 0); #if 0 // for TEST if (ret < 0) cout << "errno = " << errno << endl << flush; #endif if (ret > 0){ sent_size += ret; } else { return -1; } } return sent_size; #else // for TEST // send return send_int(sock, buf, size, 0); #endif // for TEST }
int send_string_len(Sock *sock,char *str,int len) { int val; if (len > 1023) { char *buf; buf = malloc(len+1); strncpy(buf,str,len); buf[len]='\0'; send_int(sock,len+1); val = swrite(sock, buf, len+1, NULL); free(buf); } else { static char buf[1024]; strncpy(buf, str, len); buf[len] = '\0'; send_int(sock, len+1); val = swrite(sock, buf, len+1, NULL); } if (val == -1) { return -1; } return 0; }