int main(void) { if (!is_root()) { printf("Root privileges needed to get the hard disk info.\n"); return EXIT_SUCCESS; } char *df = which("df"); char *fdisk = which("fdisk"); char *cmd = NULL; char *path = NULL; cmd = calloc(55, sizeof(char)); sprintf(cmd, "%s -l | grep /dev/ | awk '{print $%d}'", fdisk, 2); path = get_cmd_output(cmd, 12); path = strip_end(path, ":"); hd = new_device(path); delete(&cmd); delete(&path); cmd = calloc(45, sizeof(char)); sprintf(cmd, "%s -P | awk '{print $%d}' | grep %s", df, 1, hd->name); path = get_cmd_output(cmd, 13); part = new_device(path); delete(&cmd); delete(&path); int fails = 0; Suite *s = hd_suite(); SRunner *sr = srunner_create(s); srunner_run_all(sr, CK_NORMAL); fails = srunner_ntests_failed(sr); srunner_free(sr); return (fails == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }
/* * Our first setup routine is the console. It's a fairly simple device, but * UNIX tty handling makes it uglier than it could be. */ static void setup_console(void) { struct device *dev; /* If we can save the initial standard input settings... */ if (tcgetattr(STDIN_FILENO, &orig_term) == 0) { struct termios term = orig_term; /* * Then we turn off echo, line buffering and ^C etc: We want a * raw input stream to the Guest. */ term.c_lflag &= ~(ISIG|ICANON|ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &term); } dev = new_device("console", VIRTIO_ID_CONSOLE); /* We store the console state in dev->priv, and initialize it. */ dev->priv = malloc(sizeof(struct console_abort)); ((struct console_abort *)dev->priv)->count = 0; /* * The console needs two virtqueues: the input then the output. When * they put something the input queue, we make sure we're listening to * stdin. When they put something in the output queue, we write it to * stdout. */ add_virtqueue(dev, VIRTQUEUE_NUM, console_input); add_virtqueue(dev, VIRTQUEUE_NUM, console_output); verbose("device %u: console\n", ++devices.device_num); }
enum HPMUD_RESULT hpmud_open_device(const char *uri, enum HPMUD_IO_MODE iomode, HPMUD_DEVICE *dd) { HPMUD_DEVICE index=0; enum HPMUD_RESULT stat = HPMUD_R_INVALID_URI; int result; DBG("[%d,%d,%d,%d,%d,%d] hpmud_device_open() uri=%s iomode=%d\n", getpid(), getppid(), getuid(), geteuid(), getgid(), getegid(), uri, iomode); if ((index = new_device(uri, iomode, &result)) == 0) { stat = result; goto bugout; } else { if ((stat = (msp->device[index].vf.open)(&msp->device[index])) != HPMUD_R_OK) { (msp->device[index].vf.close)(&msp->device[index]); /* Open failed perform device cleanup. */ del_device(index); goto bugout; } } *dd = index; stat = HPMUD_R_OK; bugout: return stat; }
/* HAL callback for property changes */ static void property_modified (LibHalContext *ctx, const char *udi, const char *key, dbus_bool_t is_removed, dbus_bool_t is_added) { WINE_TRACE( "udi %s key %s %s\n", wine_dbgstr_a(udi), wine_dbgstr_a(key), is_added ? "added" : is_removed ? "removed" : "modified" ); if (!strcmp( key, "volume.mount_point" )) new_device( ctx, udi ); }
int main(void) { struct device *dev = new_device("Plugin"); get_info(dev); print_device_list(dev); free_device(&dev); return 0; }
static DWORD WINAPI hal_thread( void *arg ) { DBusError error; DBusConnection *dbc; LibHalContext *ctx; int i, num; char **list; if (!(ctx = p_libhal_ctx_new())) return 1; p_dbus_error_init( &error ); if (!(dbc = p_dbus_bus_get( DBUS_BUS_SYSTEM, &error ))) { WINE_WARN( "failed to get system dbus connection: %s\n", error.message ); p_dbus_error_free( &error ); return 1; } p_libhal_ctx_set_dbus_connection( ctx, dbc ); p_libhal_ctx_set_device_added( ctx, new_device ); p_libhal_ctx_set_device_removed( ctx, removed_device ); p_libhal_ctx_set_device_property_modified( ctx, property_modified ); if (!p_libhal_ctx_init( ctx, &error )) { WINE_WARN( "HAL context init failed: %s\n", error.message ); p_dbus_error_free( &error ); return 1; } /* retrieve all existing devices */ if (!(list = p_libhal_get_all_devices( ctx, &num, &error ))) p_dbus_error_free( &error ); else { for (i = 0; i < num; i++) new_device( ctx, list[i] ); p_libhal_free_string_array( list ); } __TRY { while (p_dbus_connection_read_write_dispatch( dbc, -1 )) /* nothing */ ; } __EXCEPT( assert_fault ) { WINE_WARN( "dbus assertion failure, disabling HAL support\n" ); return 1; } __ENDTRY; p_libhal_ctx_shutdown( ctx, &error ); p_dbus_error_free( &error ); /* just in case */ p_dbus_connection_close( dbc ); p_libhal_ctx_free( ctx ); return 0; }
inline static void session_init_devices(session_t session) { native_index_t count; list_t devices; count = Pa_GetDeviceCount(); devices = fa_list_empty(); for (size_t i = 0; i < count; ++i) { device_t device = new_device(session, i); if (device) { devices = fa_list_dcons(device, devices); } } session->devices = fa_list_dreverse(devices); session->def_input = new_device(session, Pa_GetDefaultInputDevice()); session->def_output = new_device(session, Pa_GetDefaultOutputDevice()); }
void QuickVerifyTask::NewDiskDetected( void *param ) { if (DM::Disk * new_disk = static_cast<DM::Disk *> (param) ) { if ( auto disk_device = disk_master_->getDiskDevice( new_disk->Port() ) ) { disk_device->setDisk(new_disk); emit new_device(new_disk->Port()); } } }
METHOD Chardev_new(Ctx *ctx, knh_sfp_t *sfp) { printk("%s:%d\n",__func__,__LINE__); knh_device_t *dev = new_device(ctx, sfp[1].s); knh_RawPtr_init(ctx, sfp[0].glue, dev, device_gfree); // set ref for object. // but we do not set ref because it becomes cyclic refalence. dev->self = sfp[0].o; printk("%s:%d, cid=%d\n",__func__,__LINE__, knh_Object_cid(sfp[0].o)); KNH_RETURN(ctx, sfp, sfp[0].o); }
static void find_capture_device(OpenALInformation* info) { const char *user_device = os_config_read_string( "Sound", "CaptureDevice", NULL ); const char *default_device = info->default_capture_device.c_str(); // in case they are the same, we only want to test it once if ( (user_device && default_device) && !strcmp(user_device, default_device) ) { user_device = NULL; } for (auto& device : info->capture_devices) { OALdevice new_device(device.c_str()); if (user_device && !strcmp(device.c_str(), user_device)) { new_device.type = OAL_DEVICE_USER; } else if (default_device && !strcmp(device.c_str(), default_device)) { new_device.type = OAL_DEVICE_DEFAULT; } CaptureDevices.push_back( new_device ); } if ( CaptureDevices.empty() ) { return; } std::sort( CaptureDevices.begin(), CaptureDevices.end(), openal_device_sort_func ); // for each device that we have available, try and figure out which to use for (size_t idx = 0; idx < CaptureDevices.size(); idx++) { const ALCchar *device_name = CaptureDevices[idx].device_name.c_str(); ALCdevice *device = alcCaptureOpenDevice(device_name, 22050, AL_FORMAT_MONO8, 22050 * 2); if (device == NULL) { continue; } if (alcGetError(device) != ALC_NO_ERROR) { alcCaptureCloseDevice(device); continue; } // ok, we should be good with this one Capture_device = CaptureDevices[idx].device_name; alcCaptureCloseDevice(device); break; } }
END_TEST /****************************** * * * TESTES PARA GET_INFO * * * ******************************/ START_TEST(get_info_ok) { struct device *dev = new_device("get_info_hard_disks"); int o = get_info(dev); fail_unless(dev != NULL && o == SUCCESS, "get_info(device(\"get_info_hard_disks\")) failed"); }
static void setup_console(void) { struct device *dev; if (tcgetattr(STDIN_FILENO, &orig_term) == 0) { struct termios term = orig_term; term.c_lflag &= ~(ISIG|ICANON|ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &term); } dev = new_device("console", VIRTIO_ID_CONSOLE); dev->priv = malloc(sizeof(struct console_abort)); ((struct console_abort *)dev->priv)->count = 0; add_virtqueue(dev, VIRTQUEUE_NUM, console_input); add_virtqueue(dev, VIRTQUEUE_NUM, console_output); verbose("device %u: console\n", ++devices.device_num); }
void set_processor_device(struct device *device) { if (device == NULL) return; int processors_count = get_processors_count(); //returns at least 1; struct device *processors[processors_count]; int i; for (i = 0; i < processors_count; i++) { processors[i] = new_device("Processor"); add_info(processors[i], get_processor_family(i)); add_info(processors[i], get_processor_version(i)); add_info(processors[i], get_processor_socket_designation(i)); add_info(processors[i], get_processor_manufacturer(i)); add_info(processors[i], get_processor_id(i)); add_info(processors[i], get_processor_voltage(i)); add_info(processors[i], get_processor_external_clock(i)); set_child(device, processors[i]); } set_caches(processors, processors_count); set_cores(processors, processors_count); }
static void *probe_stream( void *ptr ) { obe_input_probe_t *probe_ctx = (obe_input_probe_t*)ptr; obe_t *h = probe_ctx->h; obe_input_t *user_opts = &probe_ctx->user_opts; obe_device_t *device; obe_int_input_stream_t *streams[MAX_STREAMS]; int cur_stream = 2; obe_sdi_non_display_data_t *non_display_parser; decklink_ctx_t *decklink_ctx; decklink_opts_t *decklink_opts = (decklink_opts_t*)calloc( 1, sizeof(*decklink_opts) ); if( !decklink_opts ) { fprintf( stderr, "Malloc failed\n" ); goto finish; } non_display_parser = &decklink_opts->decklink_ctx.non_display_parser; /* TODO: support multi-channel */ decklink_opts->num_channels = 16; decklink_opts->card_idx = user_opts->card_idx; decklink_opts->video_conn = user_opts->video_connection; decklink_opts->audio_conn = user_opts->audio_connection; decklink_opts->video_format = user_opts->video_format; decklink_opts->probe = non_display_parser->probe = 1; decklink_ctx = &decklink_opts->decklink_ctx; decklink_ctx->h = h; decklink_ctx->last_frame_time = -1; decklink_ctx = &decklink_opts->decklink_ctx; if( open_card( decklink_opts ) < 0 ) goto finish; sleep( 1 ); close_card( decklink_opts ); if( !decklink_opts->probe_success ) { fprintf( stderr, "[decklink] No valid frames received - check input format\n" ); goto finish; } /* TODO: probe for SMPTE 337M */ /* TODO: factor some of the code below out */ for( int i = 0; i < 2; i++ ) { streams[i] = (obe_int_input_stream_t*)calloc( 1, sizeof(*streams[i]) ); if( !streams[i] ) goto finish; /* TODO: make it take a continuous set of stream-ids */ pthread_mutex_lock( &h->device_list_mutex ); streams[i]->input_stream_id = h->cur_input_stream_id++; pthread_mutex_unlock( &h->device_list_mutex ); if( i == 0 ) { streams[i]->stream_type = STREAM_TYPE_VIDEO; streams[i]->stream_format = VIDEO_UNCOMPRESSED; streams[i]->width = decklink_opts->width; streams[i]->height = decklink_opts->height; streams[i]->timebase_num = decklink_opts->timebase_num; streams[i]->timebase_den = decklink_opts->timebase_den; streams[i]->csp = PIX_FMT_YUV422P10; streams[i]->interlaced = decklink_opts->interlaced; streams[i]->tff = decklink_opts->tff; streams[i]->sar_num = streams[i]->sar_den = 1; /* The user can choose this when encoding */ if( add_non_display_services( non_display_parser, streams[i], USER_DATA_LOCATION_FRAME ) < 0 ) goto finish; } else if( i == 1 ) { streams[i]->stream_type = STREAM_TYPE_AUDIO; streams[i]->stream_format = AUDIO_PCM; streams[i]->num_channels = 16; streams[i]->sample_format = AV_SAMPLE_FMT_S32P; /* TODO: support other sample rates */ streams[i]->sample_rate = 48000; } } if( non_display_parser->has_vbi_frame ) { streams[cur_stream] = (obe_int_input_stream_t*)calloc( 1, sizeof(*streams[cur_stream]) ); if( !streams[cur_stream] ) goto finish; pthread_mutex_lock( &h->device_list_mutex ); streams[cur_stream]->input_stream_id = h->cur_input_stream_id++; pthread_mutex_unlock( &h->device_list_mutex ); streams[cur_stream]->stream_type = STREAM_TYPE_MISC; streams[cur_stream]->stream_format = VBI_RAW; streams[cur_stream]->vbi_ntsc = decklink_opts->video_format == INPUT_VIDEO_FORMAT_NTSC; if( add_non_display_services( non_display_parser, streams[cur_stream], USER_DATA_LOCATION_DVB_STREAM ) < 0 ) goto finish; cur_stream++; } if( non_display_parser->has_ttx_frame ) { streams[cur_stream] = (obe_int_input_stream_t*)calloc( 1, sizeof(*streams[cur_stream]) ); if( !streams[cur_stream] ) goto finish; pthread_mutex_lock( &h->device_list_mutex ); streams[cur_stream]->input_stream_id = h->cur_input_stream_id++; pthread_mutex_unlock( &h->device_list_mutex ); streams[cur_stream]->stream_type = STREAM_TYPE_MISC; streams[cur_stream]->stream_format = MISC_TELETEXT; if( add_teletext_service( non_display_parser, streams[cur_stream] ) < 0 ) goto finish; cur_stream++; } if( non_display_parser->num_frame_data ) free( non_display_parser->frame_data ); device = new_device(); if( !device ) goto finish; device->num_input_streams = cur_stream; memcpy( device->streams, streams, device->num_input_streams * sizeof(obe_int_input_stream_t**) ); device->device_type = INPUT_DEVICE_DECKLINK; memcpy( &device->user_opts, user_opts, sizeof(*user_opts) ); /* add device */ add_device( h, device ); finish: if( decklink_opts ) free( decklink_opts ); free( probe_ctx ); return NULL; }
static void setup_tun_net(char *arg) { struct device *dev; struct net_info *net_info = malloc(sizeof(*net_info)); int ipfd; u32 ip = INADDR_ANY; bool bridging = false; char tapif[IFNAMSIZ], *p; struct virtio_net_config conf; net_info->tunfd = get_tun_device(tapif); dev = new_device("net", VIRTIO_ID_NET); dev->priv = net_info; add_virtqueue(dev, VIRTQUEUE_NUM, net_input); add_virtqueue(dev, VIRTQUEUE_NUM, net_output); ipfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (ipfd < 0) err(1, "opening IP socket"); if (!strncmp(BRIDGE_PFX, arg, strlen(BRIDGE_PFX))) { arg += strlen(BRIDGE_PFX); bridging = true; } p = strchr(arg, ':'); if (p) { str2mac(p+1, conf.mac); add_feature(dev, VIRTIO_NET_F_MAC); *p = '\0'; } if (bridging) add_to_bridge(ipfd, tapif, arg); else ip = str2ip(arg); configure_device(ipfd, tapif, ip); add_feature(dev, VIRTIO_NET_F_CSUM); add_feature(dev, VIRTIO_NET_F_GUEST_CSUM); add_feature(dev, VIRTIO_NET_F_GUEST_TSO4); add_feature(dev, VIRTIO_NET_F_GUEST_TSO6); add_feature(dev, VIRTIO_NET_F_GUEST_ECN); add_feature(dev, VIRTIO_NET_F_HOST_TSO4); add_feature(dev, VIRTIO_NET_F_HOST_TSO6); add_feature(dev, VIRTIO_NET_F_HOST_ECN); add_feature(dev, VIRTIO_RING_F_INDIRECT_DESC); set_config(dev, sizeof(conf), &conf); close(ipfd); devices.device_num++; if (bridging) verbose("device %u: tun %s attached to bridge: %s\n", devices.device_num, tapif, arg); else verbose("device %u: tun %s: %s\n", devices.device_num, tapif, arg); }
static void find_playback_device(OpenALInformation* info) { const char *user_device = os_config_read_string( "Sound", "PlaybackDevice", NULL ); const char *default_device = info->default_playback_device.c_str(); // in case they are the same, we only want to test it once if ( (user_device && default_device) && !strcmp(user_device, default_device) ) { user_device = NULL; } for (auto& device : info->playback_devices) { OALdevice new_device(device.c_str()); if (user_device && !strcmp(device.c_str(), user_device)) { new_device.type = OAL_DEVICE_USER; } else if (default_device && !strcmp(device.c_str(), default_device)) { new_device.type = OAL_DEVICE_DEFAULT; } PlaybackDevices.push_back( new_device ); } if ( PlaybackDevices.empty() ) { return; } std::sort( PlaybackDevices.begin(), PlaybackDevices.end(), openal_device_sort_func ); ALCdevice *device = NULL; ALCcontext *context = NULL; // for each device that we have available, try and figure out which to use for (size_t idx = 0; idx < PlaybackDevices.size(); idx++) { OALdevice *pdev = &PlaybackDevices[idx]; // open our specfic device device = alcOpenDevice( (const ALCchar*) pdev->device_name.c_str() ); if (device == NULL) { continue; } context = alcCreateContext(device, NULL); if (context == NULL) { alcCloseDevice(device); continue; } alcMakeContextCurrent(context); alcGetError(device); // check how many sources we can create static const int MIN_SOURCES = 48; // MAX_CHANNELS + 16 spare int si = 0; for (si = 0; si < MIN_SOURCES; si++) { ALuint source_id = 0; alGenSources(1, &source_id); if (alGetError() != AL_NO_ERROR) { break; } alDeleteSources(1, &source_id); } if (si == MIN_SOURCES) { // ok, it supports our minimum requirements pdev->usable = true; // need this for the future Playback_device = pdev->device_name; // done break; } else { // clean up for next pass alcMakeContextCurrent(NULL); alcDestroyContext(context); alcCloseDevice(device); context = NULL; device = NULL; } } alcMakeContextCurrent(NULL); if (context) { alcDestroyContext(context); } if (device) { alcCloseDevice(device); } }
static void find_playback_device() { const char *user_device = os_config_read_string( "Sound", "PlaybackDevice", NULL ); const char *default_device = (const char*) alcGetString( NULL, ALC_DEFAULT_DEVICE_SPECIFIER ); // in case they are the same, we only want to test it once if ( (user_device && default_device) && !strcmp(user_device, default_device) ) { user_device = NULL; } if ( alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT") == AL_TRUE ) { const char *all_devices = NULL; if ( alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATE_ALL_EXT") == AL_TRUE ) { all_devices = (const char*) alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); } else { all_devices = (const char*) alcGetString(NULL, ALC_DEVICE_SPECIFIER); } const char *str_list = all_devices; int ext_length = 0; if ( (str_list != NULL) && ((ext_length = strlen(str_list)) > 0) ) { while (ext_length) { OALdevice new_device(str_list); if (user_device && !strcmp(str_list, user_device)) { new_device.type = OAL_DEVICE_USER; } else if (default_device && !strcmp(str_list, default_device)) { new_device.type = OAL_DEVICE_DEFAULT; } PlaybackDevices.push_back( new_device ); str_list += (ext_length + 1); ext_length = strlen(str_list); } } } else { if (default_device) { OALdevice new_device(default_device); new_device.type = OAL_DEVICE_DEFAULT; PlaybackDevices.push_back( new_device ); } if (user_device) { OALdevice new_device(user_device); new_device.type = OAL_DEVICE_USER; PlaybackDevices.push_back( new_device ); } } if ( PlaybackDevices.empty() ) { return; } std::sort( PlaybackDevices.begin(), PlaybackDevices.end(), openal_device_sort_func ); ALCdevice *device = NULL; ALCcontext *context = NULL; // for each device that we have available, try and figure out which to use for (size_t idx = 0; idx < PlaybackDevices.size(); idx++) { OALdevice *pdev = &PlaybackDevices[idx]; // open our specfic device device = alcOpenDevice( (const ALCchar*) pdev->device_name.c_str() ); if (device == NULL) { continue; } context = alcCreateContext(device, NULL); if (context == NULL) { alcCloseDevice(device); continue; } alcMakeContextCurrent(context); alcGetError(device); // check how many sources we can create static const int MIN_SOURCES = 48; // MAX_CHANNELS + 16 spare int si = 0; for (si = 0; si < MIN_SOURCES; si++) { ALuint source_id = 0; alGenSources(1, &source_id); if (alGetError() != AL_NO_ERROR) { break; } alDeleteSources(1, &source_id); } if (si == MIN_SOURCES) { // ok, it supports our minimum requirements pdev->usable = true; // need this for the future Playback_device = pdev->device_name; // done break; } else { // clean up for next pass alcMakeContextCurrent(NULL); alcDestroyContext(context); alcCloseDevice(device); context = NULL; device = NULL; } } alcMakeContextCurrent(NULL); if (context) { alcDestroyContext(context); } if (device) { alcCloseDevice(device); } }
/*L:195 * Our network is a Host<->Guest network. This can either use bridging or * routing, but the principle is the same: it uses the "tun" device to inject * packets into the Host as if they came in from a normal network card. We * just shunt packets between the Guest and the tun device. */ static void setup_tun_net(char *arg) { struct device *dev; struct net_info *net_info = malloc(sizeof(*net_info)); int ipfd; u32 ip = INADDR_ANY; bool bridging = false; char tapif[IFNAMSIZ], *p; struct virtio_net_config conf; net_info->tunfd = get_tun_device(tapif); /* First we create a new network device. */ dev = new_device("net", VIRTIO_ID_NET); dev->priv = net_info; /* Network devices need a recv and a send queue, just like console. */ add_virtqueue(dev, VIRTQUEUE_NUM, net_input); add_virtqueue(dev, VIRTQUEUE_NUM, net_output); /* * We need a socket to perform the magic network ioctls to bring up the * tap interface, connect to the bridge etc. Any socket will do! */ ipfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (ipfd < 0) err(1, "opening IP socket"); /* If the command line was --tunnet=bridge:<name> do bridging. */ if (!strncmp(BRIDGE_PFX, arg, strlen(BRIDGE_PFX))) { arg += strlen(BRIDGE_PFX); bridging = true; } /* A mac address may follow the bridge name or IP address */ p = strchr(arg, ':'); if (p) { str2mac(p+1, conf.mac); add_feature(dev, VIRTIO_NET_F_MAC); *p = '\0'; } /* arg is now either an IP address or a bridge name */ if (bridging) add_to_bridge(ipfd, tapif, arg); else ip = str2ip(arg); /* Set up the tun device. */ configure_device(ipfd, tapif, ip); /* Expect Guest to handle everything except UFO */ add_feature(dev, VIRTIO_NET_F_CSUM); add_feature(dev, VIRTIO_NET_F_GUEST_CSUM); add_feature(dev, VIRTIO_NET_F_GUEST_TSO4); add_feature(dev, VIRTIO_NET_F_GUEST_TSO6); add_feature(dev, VIRTIO_NET_F_GUEST_ECN); add_feature(dev, VIRTIO_NET_F_HOST_TSO4); add_feature(dev, VIRTIO_NET_F_HOST_TSO6); add_feature(dev, VIRTIO_NET_F_HOST_ECN); /* We handle indirect ring entries */ add_feature(dev, VIRTIO_RING_F_INDIRECT_DESC); set_config(dev, sizeof(conf), &conf); /* We don't need the socket any more; setup is done. */ close(ipfd); devices.device_num++; if (bridging) verbose("device %u: tun %s attached to bridge: %s\n", devices.device_num, tapif, arg); else verbose("device %u: tun %s: %s\n", devices.device_num, tapif, arg); }
static void find_capture_device() { const char *user_device = os_config_read_string( "Sound", "CaptureDevice", NULL ); const char *default_device = (const char*) alcGetString( NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER ); // in case they are the same, we only want to test it once if ( (user_device && default_device) && !strcmp(user_device, default_device) ) { user_device = NULL; } if ( alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT") == AL_TRUE ) { const char *all_devices = (const char*) alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); const char *str_list = all_devices; int ext_length = 0; if ( (str_list != NULL) && ((ext_length = strlen(str_list)) > 0) ) { while (ext_length) { OALdevice new_device(str_list); if (user_device && !strcmp(str_list, user_device)) { new_device.type = OAL_DEVICE_USER; } else if (default_device && !strcmp(str_list, default_device)) { new_device.type = OAL_DEVICE_DEFAULT; } CaptureDevices.push_back( new_device ); str_list += (ext_length + 1); ext_length = strlen(str_list); } } } else { if (default_device) { OALdevice new_device(default_device); new_device.type = OAL_DEVICE_DEFAULT; CaptureDevices.push_back( new_device ); } if (user_device) { OALdevice new_device(user_device); new_device.type = OAL_DEVICE_USER; CaptureDevices.push_back( new_device ); } } if ( CaptureDevices.empty() ) { return; } std::sort( CaptureDevices.begin(), CaptureDevices.end(), openal_device_sort_func ); // for each device that we have available, try and figure out which to use for (size_t idx = 0; idx < CaptureDevices.size(); idx++) { const ALCchar *device_name = CaptureDevices[idx].device_name.c_str(); ALCdevice *device = alcCaptureOpenDevice(device_name, 22050, AL_FORMAT_MONO8, 22050 * 2); if (device == NULL) { continue; } if (alcGetError(device) != ALC_NO_ERROR) { alcCaptureCloseDevice(device); continue; } // ok, we should be good with this one Capture_device = CaptureDevices[idx].device_name; alcCaptureCloseDevice(device); break; } }
int main() { cl_device_id device = new_device(); cl_context context; cl_command_queue queue; cl_program program; cl_kernel kernel; cl_int i, j, err; float matrix_1[80], matrix_2[80], matrix_3[80]; const size_t buffer_origin[3] = { 5 * sizeof(float), 3, 0 }; const size_t host_origin[3] = { 1 * sizeof(float), 1, 0 }; const size_t region[3] = { 4 * sizeof(float), 4, 1 }; cl_mem matrix_buffer_1, matrix_buffer_2, matrix_buffer_3; for (i = 0; i < 80; i++) { matrix_1[i] = i * 1.0f; matrix_2[i] = 3.0; matrix_3[i] = 0; } context = clCreateContext(NULL, 1, &device, NULL, NULL, &err); if (err < 0) { perror("Couldn't create a context\n"); exit(1); } program = build_program(context, device, FILE_NAME); kernel = clCreateKernel(program, "add", &err); if (err < 0) { perror("Couldn't create a kernel\n"); exit(1); } matrix_buffer_1 = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(matrix_1), matrix_1, &err); if (err < 0) { perror("Couldn't create a buffer\n"); exit(1); } matrix_buffer_2 = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(matrix_2), matrix_2, &err); if (err < 0) { perror("Couldn't create a buffer\n"); exit(1); } matrix_buffer_3 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(matrix_3), matrix_3, &err); if (err < 0) { perror("Couldn't create a buffer\n"); exit(1); } int row = 8; int col = 10; err = clSetKernelArg(kernel, 0, sizeof(int), &row); err = clSetKernelArg(kernel, 1, sizeof(int), &col); err = clSetKernelArg(kernel, 2, sizeof(cl_mem), &matrix_buffer_1); err = clSetKernelArg(kernel, 3, sizeof(cl_mem), &matrix_buffer_2); err = clSetKernelArg(kernel, 4, sizeof(cl_mem), &matrix_buffer_3); queue = clCreateCommandQueue(context, device, 0, &err); if (err < 0) { perror("Couldn't create a command queue\n"); exit(1); } err = clEnqueueTask(queue, kernel, 0, NULL, NULL); if (err < 0) { perror("Couldn't enque task\n"); exit(1); } err = clEnqueueReadBuffer(queue, matrix_buffer_3, CL_TRUE, 0, sizeof(matrix_3), &matrix_3, 0, NULL, NULL); for (i = 0; i < 8; i++) { for (j = 0; j < 10; j++) { printf("%6.1f ", matrix_3[j + i * 10]); } printf("\n"); } clReleaseMemObject(matrix_buffer_1); clReleaseMemObject(matrix_buffer_2); clReleaseMemObject(matrix_buffer_3); clReleaseKernel(kernel); clReleaseCommandQueue(queue); clReleaseContext(context); return 0; }