// init_connection status_t init_connection() { status_t error = B_OK; // create a port outputPort = create_port(10, "common test app port"); if (outputPort < 0) error = outputPort; // find the remote port port_id port = -1; if (error == B_OK) { port = find_port(kAppRunnerTeamPort); if (port < 0) error = port; } // send the port ID if (error == B_OK) { ssize_t written = write_port(port, outputPort, &be_app_messenger, sizeof(BMessenger)); if (written < 0) error = written; } connectionEstablished = (error == B_OK); return error; }
void HaikuRTSPClient::NotifyError() { fInterface->ShutdownLoop(); status_t status = B_ERROR; write_port(fInitPort, NULL, &status, sizeof(status)); }
int main() { port_id port = create_port(1, "test port"); printf("created port %ld\n", port); thread_id threads[THREAD_COUNT]; for (int32 i = 0; i < THREAD_COUNT; i++) { threads[i] = spawn_thread(read_thread, "read thread", B_NORMAL_PRIORITY, (void*)port); resume_thread(threads[i]); } printf("snooze for a bit, all threads should be waiting now.\n"); snooze(100000); for (int32 i = 0; i < THREAD_COUNT; i++) { size_t bytes = 20 + i; char buffer[bytes]; memset(buffer, 0x55, bytes); printf("send %ld bytes\n", bytes); write_port(port, 0x42, buffer, bytes); snooze(10000); } printf("waiting for threads to terminate\n"); for (int32 i = 0; i < THREAD_COUNT; i++) { wait_for_thread(threads[i], NULL); } return 0; }
int32 SLooper::FinderThread() { status_t ignored; BMessage msg; // add a BMessenger into msg BMessenger myMessenger(this,this, &ignored); msg.AddMessenger("messageTarget", myMessenger); //Flatten it ssize_t messengerBufferLength = msg.FlattenedSize(); char *messengerBuffer = new char[messengerBufferLength]; msg.Flatten(messengerBuffer, messengerBufferLength); // wait for requests to come in port_id toRespondTo; while (read_port(finder, &ignored, &toRespondTo, sizeof(toRespondTo))>=0) { // send requests back to the port ID we were given write_port(toRespondTo, 0, messengerBuffer, messengerBufferLength); } delete messengerBuffer; return 0; }
void BTimeSource::DirectRemoveMe(const media_node &node) { // XXX this code has race conditions and is pretty dumb, and it // XXX won't detect nodes that crash and don't remove themself. CALLED(); ASSERT(fSlaveNodes != NULL); BAutolock lock(fSlaveNodes->locker); if (fSlaveNodes->count == 0) { ERROR("BTimeSource::DirectRemoveMe no slots used\n"); return; } for (int i = 0; i < SLAVE_NODES_COUNT; i++) { if (fSlaveNodes->node_id[i] == node.node && fSlaveNodes->node_port[i] == node.port) { fSlaveNodes->node_id[i] = 0; fSlaveNodes->node_port[i] = 0; fSlaveNodes->count -= 1; if (fSlaveNodes->count == 0) { // stop the time source time_source_op_info msg; msg.op = B_TIMESOURCE_STOP_IMMEDIATELY; msg.real_time = RealTime(); TRACE_TIMESOURCE("stopping time source %" B_PRId32 "\n", ID()); write_port(fControlPort, TIMESOURCE_OP, &msg, sizeof(msg)); } return; } } ERROR("BTimeSource::DirectRemoveMe failed\n"); }
//////////// == // Function to find a remote BLooper BMessenger *SLooper::FindOtherEnd(char *unique_name) { BMessenger *rc = new BMessenger(); int32 ignored; FORMULATE_UNIQUE(unique_name); // find port by name port_id port = find_port(unique); if (port < 0) { return NULL; } // create a port for the reply port_id myPort = create_port(1, "temporary port for answer"); // send the request to the other end with the port of our end write_port(port, 0xdeadbeef, &myPort, sizeof(myPort)); // wait for an answer ssize_t messageSize = port_buffer_size(myPort); char *message = new char[messageSize]; read_port(myPort, &ignored, message, messageSize); // get the BMessenger out of it BMessage msg; msg.Unflatten(message); msg.FindMessenger("messageTarget", rc); return rc; }
void keyboard_handler_main(void) { unsigned char status; char keycode; write_port(0x20, 0x20); status = read_port(KEYBOARD_STATUS_PORT); if (status & 0x01) { keycode = read_port(KEYBOARD_DATA_PORT); if(keycode < 0) return; if(keycode == ENTER_KEY_CODE) { kprint_newline(); kprint(input); reset(input); kprint_newline(); return; } else { input[counter] = keyboard_map[(unsigned char) keycode]; counter++; } vidptr[current_loc++] = keyboard_map[(unsigned char) keycode]; vidptr[current_loc++] = 0x07; } }
/* * ec_query_seq * this function is used for ec command writing and the corresponding status query */ int ec_query_seq(unsigned char cmd) { int timeout; unsigned char status; unsigned long flags; int ret = 0; /* make chip goto reset mode */ udelay(EC_REG_DELAY); write_port(EC_CMD_PORT, cmd); udelay(EC_REG_DELAY); /* check if the command is received by ec */ timeout = EC_CMD_TIMEOUT; status = read_port(EC_STS_PORT); while(timeout--){ if(status & (1 << 1)){ status = read_port(EC_STS_PORT); udelay(EC_REG_DELAY); continue; } break; } if(timeout <= 0){ printf("EC QUERY SEQ : deadable error : timeout...\n"); ret = -1; } return ret; }
int main(){ int fd1,val; char msg[10]; while(1) { // Te set brightness msg[0] = 0x53; msg[1] = 0x00; msg[2] = 0x8A; msg[3] = 0x00; msg[4] = 0x00; msg[5] = (int)(val/256); msg[6] = val%256; val = msg[1] +msg[2] +msg[3] +msg[4] +msg[5] +msg[6]; val = val % 0xFF; msg[7] = val; msg[8] = 0x45; msg[9] = '\r'; fd1=open_port(); if(fd1 > 0) { write_port(msg,10); // delay(); close(fd1); } else { printf("Error in Open_port()\n"); } } return 0; }
void width_src(void){ unsigned char msg[10]; msg[0] = '\x1A'; msg[1] = (unsigned char)param_geti("width_src"); // funkce vraci nulu pokud nenalezne konstantu write_port((char *)msg); }
/*This function creates an OBD commad legible for the OBD and writes it into it. * * Arguments: * fd: file descriptor to write in. * buffer: pointer to the buffer where the command is. * Return value: * n: number of bytes written. * OBD_WRITE: error while writting. */ int write_obdmsg(int fd, char *msg) { char buffer[OBDMSGLEN] = ""; strncat(buffer, msg, OBDMSGLEN); strncat(buffer, LM327_EOLSTRING, OBDMSGLEN); return write_port(fd, buffer, strlen(buffer)); }
static void on_socket_event(void * socket, uint32 event, void * cookie) { connection_cookie * cc = (connection_cookie *) cookie; struct socket_event_data sed; status_t status; if (!cc) return; if (cc->socket != socket) { printf("on_socket_event(%p, %ld, %p): socket is higly suspect! Aborting.\n", socket, event, cookie); return; } printf("on_socket_event(%p, %ld, %p)\n", socket, event, cookie); sed.event = event; sed.cookie = cc->notify_cookie; // TODO: don't block here => write_port_etc() ? status = write_port(cc->socket_event_port, NET_STACK_SOCKET_EVENT_NOTIFICATION, &sed, sizeof(sed)); if (status != B_OK) printf("write_port(NET_STACK_SOCKET_EVENT_NOTIFICATION) failure: %s\n", strerror(status)); return; }
status_t MainLoop() { do { ssize_t size = port_buffer_size(gRequestPort); if (size < B_OK) return 0; void* buffer = malloc(size); if (buffer == NULL) return B_NO_MEMORY; MemoryDeleter _(buffer); int32 code; size = read_port(gRequestPort, &code, buffer, size); if (size < B_OK) return 0; status_t result; switch (code) { case MsgGetAddrInfo: result = GetAddrInfo(reinterpret_cast<char*>(buffer)); break; default: result = B_BAD_VALUE; write_port(gReplyPort, MsgError, &result, sizeof(result)); result = B_OK; } if (result != B_OK) return 0; } while (true); }
filter_result InputFilter::Filter(BMessage *message, BList *outList) { const int32 kControlKeys = B_COMMAND_KEY | B_SHIFT_KEY; if (message->what == B_KEY_DOWN ) { int32 raw; int32 mods; if ((message->FindInt32("raw_char", 0, (int32 *)&raw) == B_OK) && (message->FindInt32("modifiers", (int32 *)&mods) == B_OK) && (raw==118) // v && ((mods & kControlKeys) == kControlKeys) ) { port_id port = find_port("ClipUp input port"); if (port!=B_NAME_NOT_FOUND) { write_port( port, 'CtSV', NULL, 0 ); return B_SKIP_MESSAGE; } } } return B_DISPATCH_MESSAGE; }
/* **************************************************************** * Chamada ao sistema "mutime" * **************************************************************** */ int mutime (MUTM *tp) { register int ticks; register int PIT_val; MUTM mutm; /* * Falta pensar sobre as CPUs N */ disable_int (); write_port (0x00, 0x43); /* Latch */ PIT_val = read_port (0x40) + (read_port (0x40) << 8); mutm.mu_time = time; ticks = hz; enable_int (); /* * Agora faz o cálculo */ mutm.mu_utime = mul_div_64 (ticks, MILHAO, scb.y_hz) + mul_div_64 (PIT_init - PIT_val, MILHAO, PIT_FREQ); if (unimove (tp, &mutm, sizeof (MUTM), SU) < 0) u.u_error = EFAULT; return (UNDEF); } /* end mutime */
status_t NameToGID(void* buffer) { char* groupName = reinterpret_cast<char*>(buffer); struct group* groupInfo = NULL; if (MatchDomain(groupName) == B_OK) groupInfo = getgrnam(groupName); if (groupInfo == NULL) { return write_port(gReplyPort, MsgReply, &gNogroupId, sizeof(gNogroupId)); } return write_port(gReplyPort, MsgReply, &groupInfo->gr_gid, sizeof(gid_t)); }
/* This function creates an AT commad legible for the OBD and writes it into it. * Arguments: * fd: file descriptor to write in. * buffer: pointer to the buffer where the command is. * Return value: * n: number of bytes written. * OBD_WRITE: error while writting. */ int write_atmsg(int fd, char *msg) { char buffer[ATMSGLEN]; strncpy(buffer, "AT", ATMSGLEN); strncat(buffer, msg, ATMSGLEN); strncat(buffer, LM327_EOLSTRING, ATMSGLEN); return write_port(fd, buffer, strlen(buffer)); }
void turn_off_motor() { if(floppy_motor) { wait_for_FDC(); dor_status &= ~FLOPPY_MOTOR_A; write_port(FLOPPY_DOR_REG,dor_status); floppy_motor = 0; } }
void turn_on_motor() { if(floppy_motor == 0) { wait_for_FDC(); dor_status |= FLOPPY_MOTOR_A; write_port(FLOPPY_DOR_REG,dor_status); add_timer(9,floppy_motor_enabled,0); } }
// vreport void vreport(const char *format, va_list args) { char buffer[10240]; vsprintf(buffer, format, args); int32 length = strlen(buffer); write_port(outputPort, 0, buffer, length); }
void BMidiLocalProducer::SprayEvent(const void* data, size_t length, bool atomic, bigtime_t time, bool sysex) const { if (LockProducer()) { if (CountConsumers() > 0) { // We don't just send the MIDI event data to all connected // consumers, we also send a header. The header contains our // ID (4 bytes), the consumer's ID (4 bytes), the performance // time (8 bytes), whether the data is atomic (1 byte), and // padding (3 bytes). The MIDI event data follows the header. size_t buf_size = 20 + length; if (sysex) { // add 0xF0 and 0xF7 markers buf_size += 2; } uint8* buffer = (uint8*)malloc(buf_size); if (buffer != NULL) { *((uint32*) (buffer + 0)) = fId; *((bigtime_t*) (buffer + 8)) = time; *((uint32*) (buffer + 16)) = 0; *((bool*) (buffer + 16)) = atomic; if (sysex) { *((uint8*) (buffer + 20)) = B_SYS_EX_START; if (data != NULL) memcpy(buffer + 21, data, length); *((uint8*) (buffer + buf_size - 1)) = B_SYS_EX_END; } else if (data != NULL) { memcpy(buffer + 20, data, length); } for (int32 t = 0; t < CountConsumers(); ++t) { BMidiConsumer* cons = ConsumerAt(t); *((uint32*) (buffer + 4)) = cons->fId; #ifdef DEBUG printf("*** spraying: "); for (uint32 t = 0; t < buf_size; ++t) { printf("%02X, ", buffer[t]); } printf("\n"); #endif write_port(cons->fPort, 0, buffer, buf_size); } free(buffer); } } UnlockProducer(); } }
void check_positions(void) { if (current_loc >= SCREENSIZE) { unsigned int line_size = BYTES * COLUMNS; current_loc = SCREENSIZE - line_size; unsigned int j = 0; for (unsigned int i = line_size; i < SCREENSIZE; i++) { vidptr[j++] = vidptr[i]; } while (j < SCREENSIZE) { vidptr[j++] = ' '; vidptr[j++] = BASE_COLOR; } } write_port(0x3D4, 0x0F); write_port(0x3D5, (unsigned char)(current_loc / 2 & 0xFF)); write_port(0x3D4, 0x0E); write_port(0x3D5, (unsigned char )((current_loc / 2 >> 8) & 0xFF)); }
status_t LocalDebuggerInterface::UninstallBreakpoint(target_addr_t address) { debug_nub_clear_breakpoint message; message.address = (void*)(addr_t)address; return write_port(fNubPort, B_DEBUG_MESSAGE_CLEAR_BREAKPOINT, &message, sizeof(message)); }
/* flag ignored, for arg compatibility w/ xmit_data */ void _xmit_img_file(QSP_ARG_DECL Port *mpp,Image_File *ifp,int flag) /** send a file header */ { int32_t len; int32_t code; #ifdef SIGPIPE // We used to call a handler (if_pipe) that performed // a fatal error exit. Now we would like to recover // a little more gracefully. That means that put_port_int32 etc // can return after the port is closed. signal(SIGPIPE,SIG_IGN); #endif /* SIGPIPE */ code=P_IMG_FILE; if( put_port_int32(mpp,code) == (-1) ){ warn("xmit_file: error sending code"); return; } len=(int32_t)strlen(ifp->if_name)+1; /* we don't send the file data, just the header data */ /* We need to send: * * name * if_nfrms (frms written/read) * if_type (file format) * (file type specific header?) * if_flags * (dp ptr to obj with dimensions?) * (if_pathname) (don't really care since file is on remot sys) */ if( put_port_int32(mpp,len) == -1 ){ warn("xmit_file: error writing name length word"); return; } if( put_port_int32(mpp, ifp->if_nfrms) == -1 || put_port_int32(mpp, FT_CODE(IF_TYPE(ifp)) ) == -1 || put_port_int32(mpp, ifp->if_flags ) == -1 ){ warn("error sending image file header data"); return; } if( write_port(mpp,ifp->if_name,len) == (-1) ){ warn("xmit_file: error writing image file name"); return; } /* now send the associated data_obj header... */ assert( ifp->if_dp != NULL ); xmit_obj(mpp,ifp->if_dp,0); }
void BSBar::ValueChanged(float vv) { if (fLastValue!=vv) { write_port(fDrawPort,SCROLLBAR_MOVE,NULL,0); fLastValue=vv; } }
void write_all(void *arg, long period) { parport_t *port; int n; port = arg; for (n = 0; n < num_ports; n++) { write_port(&(port[n]), period); } }
status_t beos_dl_close(image_id im) { /* unload add-on */ int32 resu; write_port(beos_dl_port_in, 2, &im, 4); read_port(beos_dl_port_out, &resu, NULL, 0); return resu; }
void AskName::MessageReceived(BMessage *msg) { if (msg->what == ACCEPT_BUTTON) { text = strdup(Text->Text()); write_port(Port, 1, NULL, 0); } else BWindow::MessageReceived(msg); }
static int set_lcd_brightness(char *brightness) { struct stdio_dev *cop_port; char *env; char cmd_buf[20]; int val = 0; int cs = 0; int len, i; if (brightness) { val = simple_strtol(brightness, NULL, 10); } else { env = getenv("brightness"); if (env) val = simple_strtol(env, NULL, 10); } if (val < 0) val = 0; if (val > MAX_BRIGHTNESS) val = MAX_BRIGHTNESS; sprintf(cmd_buf, "$SB;%04d;", val); len = strlen(cmd_buf); for (i = 1; i <= len; i++) cs += cmd_buf[i]; cs = (~cs + 1) & 0xff; sprintf(cmd_buf + len, "%02X\n", cs); /* IO Coprocessor communication */ cop_port = open_port(4, CONFIG_SYS_PDM360NG_COPROC_BAUDRATE); if (!cop_port) { printf("Error: Can't open IO Coprocessor port.\n"); return -1; } debug("%s: cmd: %s", __func__, cmd_buf); write_port(cop_port, cmd_buf); /* * Wait for transmission and maybe response data * before closing the port. */ udelay(CONFIG_SYS_PDM360NG_COPROC_READ_DELAY); memset(cmd_buf, 0, sizeof(cmd_buf)); len = read_port(cop_port, cmd_buf, sizeof(cmd_buf)); if (len) printf("Error: %s\n", cmd_buf); close_port(4); return 0; }
/** * Log has reached the end of its journey. This class will render it to the user. * * @param buf A pointer to the buffer. * @param len How long the buffer is. * @param mm A declaration of memory-management responsibility. * @return A declaration of memory-management responsibility. */ int8_t STM32F7USB::toCounterparty(StringBuilder* buf, int8_t mm) { _accumulator.concatHandoff(buf); if (connected() && !_tx_in_progress) { char* working_chunk = _accumulator.position(0); if (write_port((uint8_t*) working_chunk, strlen(working_chunk))) { // TODO: Fail-over timer? Disconnection signal? _accumulator.drop_position(0); } } return MEM_MGMT_RESPONSIBLE_BEARER; // We took the buffer. }