static void ancs_chunk_parser_handle_byte(uint8_t data) { ancs_notification_buffer[ancs_bytes_received++] = data; if (ancs_bytes_received < ancs_bytes_needed) return; switch (chunk_parser_state) { case W4_ATTRIBUTE_ID: ancs_attribute_id = ancs_notification_buffer[ancs_bytes_received-1]; ancs_bytes_received = 0; ancs_bytes_needed = 2; chunk_parser_state = W4_ATTRIBUTE_LEN; break; case W4_ATTRIBUTE_LEN: ancs_attribute_len = READ_BT_16(ancs_notification_buffer, ancs_bytes_received-2); ancs_bytes_received = 0; ancs_bytes_needed = ancs_attribute_len; if (ancs_attribute_len == 0) { ancs_bytes_needed = 1; chunk_parser_state = W4_ATTRIBUTE_ID; break; } chunk_parser_state = W4_ATTRIBUTE_COMPLETE; break; case W4_ATTRIBUTE_COMPLETE: ancs_notification_buffer[ancs_bytes_received] = 0; notify_client(ANCS_CLIENT_NOTIFICATION); ancs_bytes_received = 0; ancs_bytes_needed = 1; chunk_parser_state = W4_ATTRIBUTE_ID; break; } }
static void break_ccpairs (struct ropa_client *c, Bool notify_clientp) { AFSCBFids fids; AFSCBs cbs; struct ropa_ccpair *cc; AFSCallBack callback; DIAGNOSTIC_CHECK_CLIENT(c); fids.val = NULL; fids.len = 0; cbs.val = NULL; cbs.len = 0; while ((cc = listdeltail (c->callbacks)) != NULL) { DIAGNOSTIC_CHECK_CCPAIR(cc); update_callback (cc, &callback, CBDROPPED); add_to_cb (&cc->cb->fid, &callback, &fids, &cbs); break_ccpair (cc, FALSE); } if (notify_clientp) notify_client (c, &fids, &cbs); }
/** * @function do_action * @brief It executes an action from a recently changed state */ void Test2_Server::do_action( int _action ) { if( _action == SEND_IMAGE_REQUEST ) { ach_status_t r; sns_msg_server_1 msg; sns_msg_set_time( &msg.header, NULL, 0.2*1e9 ); msg.task_type = TASK_PICK_UP; msg.msg_type = MSG_SEE_GRAB_IMG; r = ach_put( &mServer2See_chan, &msg, sizeof(msg) ); if( r == ACH_OK ) { notify_client( START_SEGMENTATION ); } else { this->showMsg( QString("Failed requesting image"), ERROR ); } } // End send image request else if( _action == SEND_INPUT_REQUEST ) { QBluetoothTransferRequest req( mService_OBB.device().address() ); mFile_OBB = new QFile( QString(mImage_fullname.c_str()) ); mReply_OBB = mMgr.put( req, mFile_OBB ); connect( mReply_OBB, SIGNAL(finished(QBluetoothTransferReply*)), this, SLOT(OB_finishedTransfer_slot(QBluetoothTransferReply*))); } // End sending client input request
void terminal_rvp_t::notify_on_abort() { // If DFlusher is enabled // Do the notification of the committed actions and // release the local locks here. // After we aborted the xct we need to notify the client and the partitions. // The notification of the commmitted xcts will be done by the DNotifier thread. notify_partitions(); notify_client(); TRACE( TRACE_TRX_FLOW, "Giving back aborted (%d)\n", _tid.get_lo()); giveback(); }
static void break_ccpair (struct ropa_ccpair *cc, Bool notify_clientp) { AFSCBFids fids; AFSCBs cbs; int ret; debug_print_callbacks(); cc->expire = 0; if (cc->li) listdel (lru_ccpair, cc->li); if (notify_clientp) { fids.len = 1; fids.val = &cc->cb->fid; cbs.len = 0; notify_client (cc->client, &fids, &cbs); } if (cc->cb_li) { listdel (cc->cb->ccpairs, cc->cb_li); cc->cb_li = NULL; } /* The reverse of these are in add_client */ ret = hashtabdel (ht_ccpairs, cc); assert (ret == 0); client_deref (cc->client); cc->client = NULL; callback_deref (cc->cb); cc->cb = NULL; heap_remove (heap_ccpairs, cc->heap); cc->li = listaddtail (lru_ccpair, cc); debug_print_callbacks(); }
static enum cmd_retval cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; const char *tflag = args_get(args, 't'); enum cmd_find_type type; int flags; struct client *c; struct session *s; struct winlink *wl; struct window_pane *wp; const char *tablename; struct key_table *table; if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL) return (CMD_RETURN_ERROR); if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') { type = CMD_FIND_PANE; flags = 0; } else { type = CMD_FIND_SESSION; flags = CMD_FIND_PREFER_UNATTACHED; } if (cmd_find_target(&item->target, item, tflag, type, flags) != 0) return (CMD_RETURN_ERROR); s = item->target.s; wl = item->target.wl; wp = item->target.wp; if (args_has(args, 'r')) c->flags ^= CLIENT_READONLY; tablename = args_get(args, 'T'); if (tablename != NULL) { table = key_bindings_get_table(tablename, 0); if (table == NULL) { cmdq_error(item, "table %s doesn't exist", tablename); return (CMD_RETURN_ERROR); } table->references++; key_bindings_unref_table(c->keytable); c->keytable = table; return (CMD_RETURN_NORMAL); } if (args_has(args, 'n')) { if ((s = session_next_session(c->session)) == NULL) { cmdq_error(item, "can't find next session"); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'p')) { if ((s = session_previous_session(c->session)) == NULL) { cmdq_error(item, "can't find previous session"); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'l')) { if (c->last_session != NULL && session_alive(c->last_session)) s = c->last_session; else s = NULL; if (s == NULL) { cmdq_error(item, "can't find last session"); return (CMD_RETURN_ERROR); } } else { if (item->client == NULL) return (CMD_RETURN_NORMAL); if (wl != NULL) { if (wp != NULL) window_set_active_pane(wp->window, wp); session_set_current(s, wl); cmd_find_from_session(&item->shared->current, s, 0); } } if (!args_has(args, 'E')) environ_update(s->options, c->environ, s->environ); if (c->session != NULL && c->session != s) c->last_session = c->session; c->session = s; if (~item->shared->flags & CMDQ_SHARED_REPEAT) server_client_set_key_table(c, NULL); tty_update_client_offset(c); status_timer_start(c); notify_client("client-session-changed", c); session_update_activity(s, NULL); gettimeofday(&s->last_attached_time, NULL); recalculate_sizes(); server_check_unattached(); server_redraw_client(c); s->curw->flags &= ~WINLINK_ALERTFLAGS; alerts_check_session(s); return (CMD_RETURN_NORMAL); }
static void handle_gatt_client_event(le_event_t * event) { uint8_t * packet = (uint8_t*) event; int connection_encrypted; // handle connect / disconncet events first switch (packet[0]) { case HCI_EVENT_LE_META: switch (packet[2]) { case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: gc_handle = READ_BT_16(packet, 4); printf("Connection handle 0x%04x, request encryption\n", gc_handle); // we need to be paired to enable notifications tc_state = TC_W4_ENCRYPTED_CONNECTION; sm_send_security_request(gc_handle); break; default: break; } return; case HCI_EVENT_ENCRYPTION_CHANGE: if (gc_handle != READ_BT_16(packet, 3)) return; connection_encrypted = packet[5]; log_info("Encryption state change: %u", connection_encrypted); if (!connection_encrypted) return; if (tc_state != TC_W4_ENCRYPTED_CONNECTION) return; // let's start printf("\nANCS Client - CONNECTED, discover ANCS service\n"); tc_state = TC_W4_SERVICE_RESULT; gatt_client_discover_primary_services_by_uuid128(gc_id, gc_handle, ancs_service_uuid); return; case HCI_EVENT_DISCONNECTION_COMPLETE: notify_client(ANCS_CLIENT_DISCONNECTED); return; default: break; } le_characteristic_t characteristic; le_characteristic_value_event_t * value_event; switch(tc_state) { case TC_W4_SERVICE_RESULT: switch(event->type) { case GATT_SERVICE_QUERY_RESULT: ancs_service = ((le_service_event_t *) event)->service; ancs_service_found = 1; break; case GATT_QUERY_COMPLETE: if (!ancs_service_found) { printf("ANCS Service not found"); tc_state = TC_IDLE; break; } tc_state = TC_W4_CHARACTERISTIC_RESULT; printf("ANCS Client - Discover characteristics for ANCS SERVICE \n"); gatt_client_discover_characteristics_for_service(gc_id, gc_handle, &ancs_service); break; default: break; } break; case TC_W4_CHARACTERISTIC_RESULT: switch(event->type) { case GATT_CHARACTERISTIC_QUERY_RESULT: characteristic = ((le_characteristic_event_t *) event)->characteristic; if (memcmp(characteristic.uuid128, ancs_notification_source_uuid, 16) == 0) { printf("ANCS Notification Source Characterisic found\n"); ancs_notification_source_characteristic = characteristic; ancs_characteristcs++; break; } if (memcmp(characteristic.uuid128, ancs_control_point_uuid, 16) == 0) { printf("ANCS Control Point found\n"); ancs_control_point_characteristic = characteristic; ancs_characteristcs++; break; } if (memcmp(characteristic.uuid128, ancs_data_source_uuid, 16) == 0) { printf("ANCS Data Source Characterisic found\n"); ancs_data_source_characteristic = characteristic; ancs_characteristcs++; break; } break; case GATT_QUERY_COMPLETE: printf("ANCS Characteristcs count %u\n", ancs_characteristcs); tc_state = TC_W4_NOTIFICATION_SOURCE_SUBSCRIBED; gatt_client_write_client_characteristic_configuration(gc_id, gc_handle, &ancs_notification_source_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION); break; default: break; } break; case TC_W4_NOTIFICATION_SOURCE_SUBSCRIBED: switch(event->type) { case GATT_QUERY_COMPLETE: printf("ANCS Notification Source subscribed\n"); tc_state = TC_W4_DATA_SOURCE_SUBSCRIBED; gatt_client_write_client_characteristic_configuration(gc_id, gc_handle, &ancs_data_source_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION); break; default: break; } break; case TC_W4_DATA_SOURCE_SUBSCRIBED: switch(event->type) { case GATT_QUERY_COMPLETE: printf("ANCS Data Source subscribed\n"); tc_state = TC_SUBSCRIBED; notify_client(ANCS_CLIENT_CONNECTED); break; default: break; } break; case TC_SUBSCRIBED: if ( event->type != GATT_NOTIFICATION && event->type != GATT_INDICATION ) break; value_event = (le_characteristic_value_event_t *) event; if (value_event->value_handle == ancs_data_source_characteristic.value_handle) { int i; for (i=0; i<value_event->blob_length; i++) { ancs_chunk_parser_handle_byte(value_event->blob[i]); } } else if (value_event->value_handle == ancs_notification_source_characteristic.value_handle) { ancs_notification_uid = READ_BT_32(value_event->blob, 4); printf("Notification received: EventID %02x, EventFlags %02x, CategoryID %02x, CategoryCount %u, UID %04x\n", value_event->blob[0], value_event->blob[1], value_event->blob[2], value_event->blob[3], (int) ancs_notification_uid); static uint8_t get_notification_attributes[] = {0, 0,0,0,0, 0, 1,32,0, 2,32,0, 3,32,0, 4, 5}; bt_store_32(get_notification_attributes, 1, ancs_notification_uid); ancs_notification_uid = 0; ancs_chunk_parser_init(); gatt_client_write_value_of_characteristic(gc_id, gc_handle, ancs_control_point_characteristic.value_handle, sizeof(get_notification_attributes), get_notification_attributes); } else { printf("Unknown Source: "); printf_hexdump(value_event->blob , value_event->blob_length); } break; default: break; } // app_run(); }
static enum cmd_retval cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct client *c = item->client; struct session *s, *as; struct session *groupwith = item->state.tflag.s; struct window *w; struct environ *env; struct termios tio, *tiop; const char *newname, *target, *update, *errstr, *template; const char *path, *cwd, *to_free = NULL; char **argv, *cmd, *cause, *cp; int detached, already_attached, idx, argc; u_int sx, sy; struct format_tree *ft; struct environ_entry *envent; struct cmd_find_state fs; if (self->entry == &cmd_has_session_entry) { /* * cmd_prepare() will fail if the session cannot be found, * hence always return success here. */ return (CMD_RETURN_NORMAL); } if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) { cmdq_error(item, "command or window name given with target"); return (CMD_RETURN_ERROR); } newname = args_get(args, 's'); if (newname != NULL) { if (!session_check_name(newname)) { cmdq_error(item, "bad session name: %s", newname); return (CMD_RETURN_ERROR); } if ((as = session_find(newname)) != NULL) { if (args_has(args, 'A')) { /* * This item is now destined for * attach-session. Because attach-session will * have already been prepared, copy this * session into its tflag so it can be used. */ cmd_find_from_session(&item->state.tflag, as); return (cmd_attach_session(item, args_has(args, 'D'), 0, NULL, args_has(args, 'E'))); } cmdq_error(item, "duplicate session: %s", newname); return (CMD_RETURN_ERROR); } } if ((target = args_get(args, 't')) != NULL) { if (groupwith == NULL) { cmdq_error(item, "no such session: %s", target); goto error; } } else groupwith = NULL; /* Set -d if no client. */ detached = args_has(args, 'd'); if (c == NULL) detached = 1; /* Is this client already attached? */ already_attached = 0; if (c != NULL && c->session != NULL) already_attached = 1; /* Get the new session working directory. */ if (args_has(args, 'c')) { ft = format_create(item, 0); format_defaults(ft, c, NULL, NULL, NULL); to_free = cwd = format_expand(ft, args_get(args, 'c')); format_free(ft); } else if (c != NULL && c->session == NULL && c->cwd != NULL) cwd = c->cwd; else cwd = "."; /* * If this is a new client, check for nesting and save the termios * settings (part of which is used for new windows in this session). * * tcgetattr() is used rather than using tty.tio since if the client is * detached, tty_open won't be called. It must be done before opening * the terminal as that calls tcsetattr() to prepare for tmux taking * over. */ if (!detached && !already_attached && c->tty.fd != -1) { if (server_client_check_nested(item->client)) { cmdq_error(item, "sessions should be nested with care, " "unset $TMUX to force"); return (CMD_RETURN_ERROR); } if (tcgetattr(c->tty.fd, &tio) != 0) fatal("tcgetattr failed"); tiop = &tio; } else tiop = NULL; /* Open the terminal if necessary. */ if (!detached && !already_attached) { if (server_client_open(c, &cause) != 0) { cmdq_error(item, "open terminal failed: %s", cause); free(cause); goto error; } } /* Find new session size. */ if (c != NULL) { sx = c->tty.sx; sy = c->tty.sy; } else { sx = 80; sy = 24; } if (detached && args_has(args, 'x')) { sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr); if (errstr != NULL) { cmdq_error(item, "width %s", errstr); goto error; } } if (detached && args_has(args, 'y')) { sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr); if (errstr != NULL) { cmdq_error(item, "height %s", errstr); goto error; } } if (sy > 0 && options_get_number(global_s_options, "status")) sy--; if (sx == 0) sx = 1; if (sy == 0) sy = 1; /* Figure out the command for the new window. */ argc = -1; argv = NULL; if (!args_has(args, 't') && args->argc != 0) { argc = args->argc; argv = args->argv; } else if (groupwith == NULL) { cmd = options_get_string(global_s_options, "default-command"); if (cmd != NULL && *cmd != '\0') { argc = 1; argv = &cmd; } else { argc = 0; argv = NULL; } } path = NULL; if (c != NULL && c->session == NULL) envent = environ_find(c->environ, "PATH"); else envent = environ_find(global_environ, "PATH"); if (envent != NULL) path = envent->value; /* Construct the environment. */ env = environ_create(); if (c != NULL && !args_has(args, 'E')) { update = options_get_string(global_s_options, "update-environment"); environ_update(update, c->environ, env); } /* Create the new session. */ idx = -1 - options_get_number(global_s_options, "base-index"); s = session_create(newname, argc, argv, path, cwd, env, tiop, idx, sx, sy, &cause); environ_free(env); if (s == NULL) { cmdq_error(item, "create session failed: %s", cause); free(cause); goto error; } /* Set the initial window name if one given. */ if (argc >= 0 && args_has(args, 'n')) { w = s->curw->window; window_set_name(w, args_get(args, 'n')); options_set_number(w->options, "automatic-rename", 0); } /* * If a target session is given, this is to be part of a session group, * so add it to the group and synchronize. */ if (groupwith != NULL) { session_group_add(groupwith, s); session_group_synchronize_to(s); session_select(s, RB_MIN(winlinks, &s->windows)->idx); } notify_session("session-created", s); /* * Set the client to the new session. If a command client exists, it is * taking this session and needs to get MSG_READY and stay around. */ if (!detached) { if (!already_attached) { if (~c->flags & CLIENT_CONTROL) proc_send(c->peer, MSG_READY, -1, NULL, 0); } else if (c->session != NULL) c->last_session = c->session; c->session = s; server_client_set_key_table(c, NULL); status_timer_start(c); notify_client("client-session-changed", c); session_update_activity(s, NULL); gettimeofday(&s->last_attached_time, NULL); server_redraw_client(c); } recalculate_sizes(); server_update_socket(); /* * If there are still configuration file errors to display, put the new * session's current window into more mode and display them now. */ if (cfg_finished) cfg_show_causes(s); /* Print if requested. */ if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL)
w_rc_t terminal_rvp_t::_run() { assert (_db); assert (_denv); // attach to this xct assert (_xct); smthread_t::me()->attach_xct(_xct); // try to commit w_rc_t rcdec; if (_decision == AD_ABORT) { // We cannot abort lazily because log rollback works on // disk-resident records rcdec = _db->abort_xct(); if (rcdec.is_error()) { TRACE( TRACE_ALWAYS, "Xct (%d) abort failed [0x%x]\n", _tid.get_lo(), rcdec.err_num()); } else { TRACE( TRACE_TRX_FLOW, "Xct (%d) aborted\n", _tid.get_lo()); upd_aborted_stats(); } } else { #ifdef CFG_FLUSHER // DF1. Commit lazily lsn_t xctLastLsn; rcdec = _db->commit_xct(true,&xctLastLsn); set_last_lsn(xctLastLsn); #else rcdec = _db->commit_xct(); #endif if (rcdec.is_error()) { TRACE( TRACE_ALWAYS, "Xct (%d) commit failed [0x%x]\n", _tid.get_lo(), rcdec.err_num()); upd_aborted_stats(); w_rc_t eabort = _db->abort_xct(); if (eabort.is_error()) { TRACE( TRACE_ALWAYS, "Xct (%d) abort failed [0x%x]\n", _tid.get_lo(), eabort.err_num()); } #ifdef CFG_FLUSHER notify_on_abort(); #endif } else { #ifdef CFG_FLUSHER // DF2. Enqueue to the "to flush" queue of DFlusher _denv->enqueue_toflush(this); #else (void)_denv; TRACE( TRACE_TRX_FLOW, "Xct (%d) committed\n", _tid.get_lo()); upd_committed_stats(); #endif } } #ifndef CFG_FLUSHER // If DFlusher is disabled, then the last thing to do is to notify the // client. Otherwise, we will not notify the client here, but only after we // know that the xct had been flushed notify_client(); #endif return (rcdec); }
/** * @function poll_chan * @brief Check the channels for communication from plan and see modules */ void Test2_Server::poll_chan() { ach_status_t r; size_t frame_size; sns_msg_process_1 see_msg; sns_msg_process_1 plan_msg; //--=============================================== //-- Poll perception channel (See2Server) //--=============================================== r = ach_get( &mSee2Server_chan, &see_msg, sizeof(see_msg), &frame_size, NULL, ACH_O_LAST ); if( r == ACH_OK && !sns_msg_is_expired( &see_msg.header, NULL ) ) { //--------------------------------------------// // If we received image from See process if( see_msg.msg_type == RCV_IMAGE_MSG ) { mImage_filename = std::string( see_msg.data_str ); char fullname[255]; sprintf( fullname, "%s/%s", gPicturesPath.c_str(), mImage_filename.c_str() ); mImage_fullname = std::string( fullname ); mMsg_received_flag = true; mMsg_source = SEE_MODULE; mMsg_type = see_msg.msg_type; // Notification notify_client(END_SEGMENTATION); } //--------------------------------------------// // If we received confirmation of sending object from See process else if( see_msg.msg_type == SENT_OBJ_MSG ) { this->showMsg( QString(" Confirmed object sent to planner"), DEBUG ); mMsg_received_flag = true; mMsg_source = SEE_MODULE; mMsg_type = see_msg.msg_type; // Notification notify_client(END_SQ_FITTING); } } // end See2Server //--=============================================== //-- Poll plan channel (Plan2Server) //--=============================================== r = ach_get( &mPlan2Server_chan, &plan_msg, sizeof(plan_msg), &frame_size, NULL, ACH_O_LAST ); if( r == ACH_OK && !sns_msg_is_expired( &plan_msg.header, NULL )) { if( plan_msg.msg_type == PLAN_PREP_DONE_MSG ) { this->showMsg( QString("Confirmed plan prep done"), DEBUG ); mMsg_received_flag = true; mMsg_source = PLAN_MODULE; mMsg_type = plan_msg.msg_type; } else if( plan_msg.msg_type == PLAN_DONE_MSG ) { this->showMsg( QString("Confirmed plan is done!"), DEBUG ); mMsg_received_flag = true; mMsg_source = PLAN_MODULE; mMsg_type = plan_msg.msg_type; // Notification notify_client( END_PLAN ); } } }