bool provider_register(char *name, uint64_t channel_id) { Feature *f = find_feature(name); if (!f) { return false; } if (f->channel_id && channel_exists(f->channel_id)) { ILOG("Feature \"%s\" is already provided by another channel" "(will be replaced)", name); } DLOG("Registering provider for \"%s\"", name); f->channel_id = channel_id; // Associate all method names with the feature struct size_t i; char *method; for (method = f->methods[i = 0]; method; method = f->methods[++i]) { pmap_put(cstr_t)(registered_providers, method, f); DLOG("Channel \"%" PRIu64 "\" will be sent requests for \"%s\"", channel_id, method); } ILOG("Registered channel %" PRIu64 " as the provider for the \"%s\" feature", channel_id, name); return true; }
Object provider_call(char *method, Array args) { Feature *f = pmap_get(cstr_t)(registered_providers, method); if (!f || !channel_exists(f->channel_id)) { char buf[256]; snprintf(buf, sizeof(buf), "Provider for method \"%s\" is not available", method); vim_report_error(cstr_as_string(buf)); api_free_array(args); return NIL; } Error err = ERROR_INIT; Object result = NIL = channel_send_call(f->channel_id, method, args, &err); if (err.set) { vim_report_error(cstr_as_string(err.msg)); api_free_object(result); return NIL; } return result; }
/* * Enables or disables interactivity with the standard output handle on the channel */ DWORD process_channel_interact(Channel *channel, Packet *request, LPVOID context, BOOLEAN interact) { ProcessChannelContext *ctx = (ProcessChannelContext *)context; DWORD result = ERROR_SUCCESS; dprintf( "[PROCESS] process_channel_interact. channel=0x%08X, ctx=0x%08X, interact=%d", channel, ctx, interact ); if (!channel_exists(channel) || ctx == NULL) { return result; } // If the remote side wants to interact with us, schedule the stdout handle // as a waitable item if (interact) { // try to resume it first, if it's not there, we can create a new entry if( (result = scheduler_signal_waitable( ctx->pStdout, Resume )) == ERROR_NOT_FOUND ) { result = scheduler_insert_waitable( ctx->pStdout, channel, context, (WaitableNotifyRoutine)process_channel_interact_notify, (WaitableDestroyRoutine)process_channel_interact_destroy ); } } else { // Otherwise, pause it result = scheduler_signal_waitable( ctx->pStdout, Pause ); } return result; }
DWORD process_channel_interact_destroy( HANDLE waitable, LPVOID entryContext, LPVOID threadContext ) { ProcessChannelContext *ctx = (ProcessChannelContext *)threadContext; DWORD dwResult = ERROR_SUCCESS; Channel *channel = (Channel *)entryContext; dprintf( "[PROCESS] terminating context 0x%p", ctx ); if (ctx == NULL) { return dwResult; } CloseHandle( ctx->pStdin ); CloseHandle( ctx->pStdout ); if( ctx->pProcess ) { dprintf( "[PROCESS] terminating process 0x%x", ctx->pProcess ); TerminateProcess( ctx->pProcess, 0 ); } free( ctx ); if (channel_exists(channel)) { channel->ops.pool.native.context = NULL; } return dwResult; }
void join(t_client *cli, t_packet *pack) { char buff[LINE_SIZE]; memset(buff, 0, LINE_SIZE); if (!pack->arg[0]) { send_msg(cli->fd, "461 JOIN :Needs more params"); return ; } if (pack->arg[0][0] != '#' && pack->arg[0][0] != '&') { send_msg(cli->fd, CO(CO(CP(buff, "403 "), pack->arg[0]), NOCHAN)); return ; } add_cchannel(&cli->channel, pack->arg[0]); if (!channel_exists(pack->arg[0])) add_channel(pack->arg[0]); broadcast(CO(CO(CO(CO(buff, ":"), cli->login), JOIN), pack->arg[0]), pack->arg[0]); CP(buff, "332 "); CO(buff, pack->arg[0]); CO(buff, " : "); send_msg(cli->fd, buff); users(cli, pack); }
/* Sets up a callback function to be called whenever the transaction completes * on the given channel for asynchronous transfers. */ void axidma_set_callback(axidma_dev_t dev, int channel, axidma_cb_t callback, void *data) { struct dma_channel *chan; assert(channel_exists(dev, channel)); chan = &dev->channels[channel]; chan->callback = callback; chan->user_data = data; return; }
/* * Callback for when data is available on the standard output handle of * a process channel that is interactive mode */ DWORD process_channel_interact_notify(Remote *remote, LPVOID entryContext, LPVOID threadContext) { Channel *channel = (Channel*)entryContext; ProcessChannelContext *ctx = (ProcessChannelContext *)threadContext; DWORD bytesRead, bytesAvail = 0; CHAR buffer[16384]; DWORD result = ERROR_SUCCESS; if (!channel_exists(channel) || ctx == NULL) { return result; } if( PeekNamedPipe( ctx->pStdout, NULL, 0, NULL, &bytesAvail, NULL ) ) { if( bytesAvail ) { if( ReadFile( ctx->pStdout, buffer, sizeof(buffer) - 1, &bytesRead, NULL ) ) { return channel_write( channel, remote, NULL, 0, buffer, bytesRead, NULL ); } result = GetLastError(); } else { // sf: if no data is available on the pipe we sleep to avoid running a tight loop // in this thread, as anonymous pipes won't block for data to arrive. Sleep( 100 ); } } else { result = GetLastError(); } if( result != ERROR_SUCCESS ) { dprintf("Closing down socket: result: %d\n", result); process_channel_close( channel, NULL, ctx ); channel_close( channel, remote, NULL, 0, NULL ); } return result; }
// Checks that the given channel is a valid id, searching through the arrays static bool valid_channel(axidma_dev_t dev, int channel, enum axidma_dir dir) { struct dma_channel *dma_chan; // Check that the enumeration is sound if (!(dir == AXIDMA_WRITE || dir == AXIDMA_READ)) { return false; } // Check that the channel exists if (!channel_exists(dev, channel)) { return false; } // Verify that the given channel is the same direction dma_chan = &dev->channels[channel]; return dma_chan->dir == dir; }
bool supla_client_channels::set_device_channel_new_value(TCS_SuplaChannelNewValue_B *channel_new_value) { if ( channel_exists(channel_new_value->ChannelId) ) { safe_array_lock(arr); supla_client_channel *channel; int DeviceID = 0; if ( NULL != ( channel = find_channel(channel_new_value->ChannelId) ) ) { DeviceID = channel->getDeviceId(); } safe_array_unlock(arr); if ( DeviceID ) { client->getUser()->set_device_channel_value(client->getID(), DeviceID, channel_new_value->ChannelId, channel_new_value->value); } } return false; }
bool provider_has_feature(char *name) { Feature *f = find_feature(name); return f != NULL && channel_exists(f->channel_id); }