示例#1
0
/** Please see header for specification */
Anvil::SwapchainUniquePtr Anvil::Swapchain::create(Anvil::SwapchainCreateInfoUniquePtr in_create_info_ptr)
{
    SwapchainUniquePtr result_ptr(nullptr,
                                  std::default_delete<Swapchain>() );
    auto               window_ptr(in_create_info_ptr->get_window() );

    result_ptr.reset(
        new Anvil::Swapchain(
            std::move(in_create_info_ptr)
        )
    );

    if (result_ptr)
    {
        if (!result_ptr->init() )
        {
            result_ptr.reset();

            goto end;
        }

        if (window_ptr                 != nullptr                                  &&
            window_ptr->get_platform() == WINDOW_PLATFORM_DUMMY_WITH_PNG_SNAPSHOTS)
        {
            dynamic_cast<Anvil::DummyWindowWithPNGSnapshots*>(window_ptr)->set_swapchain(result_ptr.get() );
        }
    }

end:
    return result_ptr;
}
示例#2
0
int
vr_send_interface_add(struct nl_client *cl, int router_id, char *vif_name,
        int os_index, int vif_index, int vif_xconnect_index, int vif_type,
        unsigned int vrf, unsigned int flags, int8_t *vif_mac, int8_t vif_transport)
{
    int platform;
    vr_interface_req req;

    platform = get_platform();
    memset(&req, 0, sizeof(req));

    req.h_op = SANDESH_OP_ADD;
    if (vif_name)
        req.vifr_name = vif_name;
    if (vif_mac) {
        req.vifr_mac_size = 6;
        req.vifr_mac = vif_mac;
    }
    req.vifr_vrf = vrf;

    if (os_index > 0)
        req.vifr_os_idx = os_index;

    req.vifr_idx = vif_index;
    req.vifr_rid = router_id;
    req.vifr_type = vif_type;
    req.vifr_flags = flags;
    req.vifr_transport = vif_transport;

    if (vif_type == VIF_TYPE_HOST) {
        req.vifr_cross_connect_idx = vif_xconnect_index;
    }

    return vr_sendmsg(cl, &req, "vr_interface_req");
}
示例#3
0
void 
hippo_quip_window_show(HippoQuipWindow *quip_window)
{
    HippoRectangle monitor_rect;
    int pointer_x, pointer_y;
    int window_width, window_height;
    int window_x, window_y;
    
    g_return_if_fail(HIPPO_IS_QUIP_WINDOW(quip_window));

    if (quip_window->visible)
        return;

    quip_window->visible = TRUE;
    g_object_ref(quip_window);

    hippo_platform_get_screen_info(get_platform(quip_window), &monitor_rect, NULL, NULL);
    
    if (!hippo_platform_get_pointer_position(get_platform(quip_window), &pointer_x, &pointer_y)) {
        /* Pointer on a different X screen, we'll just position at lower right */
        pointer_x = monitor_rect.x + monitor_rect.width;
        pointer_y = monitor_rect.y + monitor_rect.height;
    }

    hippo_window_get_size(quip_window->window, &window_width, &window_height);

    /* Try to position the window window so the pointer is near the upper left, but force it
     * within the workarea
     */
    window_x = pointer_x + POINTER_X_OFFSET - window_width;
    window_y = pointer_y + POINTER_Y_OFFSET;

    if (window_x + window_width > monitor_rect.x + monitor_rect.width)
        window_x = monitor_rect.x + monitor_rect.width - window_width;
    if (window_x < 0)
        window_x = 0;

    if (window_y + window_height > monitor_rect.y + monitor_rect.height)
        window_y = monitor_rect.y + monitor_rect.height - window_height;
    if (window_y < 0)
        window_y = 0;

    hippo_window_set_position(quip_window->window, window_x, window_y);

    hippo_window_present(quip_window->window);

}
示例#4
0
int
main(int argc, char *argv[])
{
	struct cmd_opts opts;
	int rc;

	switch (get_platform()) {
	case PLATFORM_UNKNOWN:
	case PLATFORM_POWERNV:
		fprintf(stderr, "%s: is not supported on the %s platform\n",
						argv[0], platform_name);
		exit(1);
	}

	/* make sure that we're running on the proper platform.	*/
	if (! valid_platform("chrp"))
		exit(1);

	memset(&opts, 0, sizeof(opts));

	/* default to DRSLOT type */
	opts.slot_type = SLOT;
	parse_options(argc, argv, &opts);

	rc = dr_lock();
	if (rc) {
		say(ERROR, "Unable to obtain Dynamic Reconfiguration lock. "
		    "Please try command again later.\n");
		exit(1);
	}

	switch (opts.slot_type) {
	    case SLOT:
	    case PCI:
		rc = lsslot_chrp_pci(&opts);
		break;

	    case PHB:
		rc = lsslot_chrp_phb(&opts);
		break;

	    case CPU:
		rc = lsslot_chrp_cpu(&opts);
		break;

	    case MEM:
		rc = lsslot_chrp_mem(&opts);
		break;

	    case PORT:
		rc = lsslot_chrp_port(&opts);
		break;
	}

	free_drc_info();
	dr_unlock();
	exit(rc);
}
示例#5
0
   stage_t::~stage_t()
   {
      // this only happens in case the stage dir was not specified at cmd line
      if ( m_remove_dir_on_exit &&  
            (get_platform()->get_temp_dir() != "") && 
               ( dir_exists(get_platform()->get_temp_dir()) ) ){
            std::string old_wkg_dir = get_working_dir();
            change_wkg_dir_to(get_platform()->get_temp_dir());
            system ("rm -f *.zip *.bz2");
            // for testing
//            std::cout << "Pres key for del\n";
//            char ch;
//            std::cin.get(ch);
            change_wkg_dir_to(old_wkg_dir);
            std::string cmd = "rmdir  " + get_platform()->get_temp_dir();
            system (cmd.c_str());

      }
   }
示例#6
0
static void validation_entry(unsigned char *b)
{
	printf("\nValidation entry\n");
	report("  Header ID", "%d", *b); b++;
	report("  Platform ID", "%d (%s)", *b, get_platform(*b)); b++;
	b += 2;			/* reserved */
	report_s("  ID string", "%-24.24s", b); b += 24;
	report("  Checksum word", "%02X %02X", b[0], b[1]); b += 2;
	report("  Key byte", "%02X", *b++);
	report("  Key byte", "%02X", *b++);
}
示例#7
0
int main(int argc, char *argv[])
{
	int opt, opt_index = 0;
	char *key = NULL;
	bool e_flag = false;
	int rc;

	if (get_platform() != PLATFORM_PSERIES_LPAR)
		errx(1,	"activate_firmware is not supported on the %s platform",
		     platform_name);

	while ((opt = getopt_long(argc, argv, "e::hVv",
				  long_opts, &opt_index)) != -1) {
		switch (opt) {
		case 'e':
			e_flag = true;
			/* optarg isn't set to the option argument if it's
			 * optional hence using optind
			 */
			if (argv[optind] && argv[optind][0] != '-') {
				key = argv[optind];
				/* So that getopt doesn't try to parse
				 * the keyfile option argument
				 */
				optind++;
			}
			break;
		case 'V':
			printf("activate_firmware - %s\n", VERSION);
			return 0;
		case 'v':
			verbose = 1;
			break;
		case 'h':
		case '?':
			print_usage(argv[0]);
			return (opt == 'h' ? 0 : -1);
		}
	}

	if (e_flag) {
		if (key)
			rc = apply_uak_key(key);
		else
			rc = get_uak_expiry_date();
	} else {
		rc = activate_firmware();
	}
	return rc;
}
示例#8
0
   bool stage_t::set_dir( std::string const & dir)
   {
       if ( dir_exists(dir)){
            if ( (m_temp_dir_name != "") && (m_remove_dir_on_exit == true) && (m_temp_dir_name != dir)){
                std::string cmd = "rmdir " + m_temp_dir_name;
               // std::cout  <<" cmd is " << cmd << '\n';
                int result =  system (cmd.c_str());
                if (result == -1){
                  std::cout << "warning couldnt remove old temp dir\n";
                }
            }
            m_remove_dir_on_exit = false;
            if ( dir.at(dir.length() -1) != get_platform()->get_dir_sep().at(0)){
               m_temp_dir_name = dir + get_platform()->get_dir_sep();
            }else{
              m_temp_dir_name = dir;
            }

            return true;
       }else{
         std::cout << "dir not found\n";
         return false;
       }
   }
示例#9
0
void
hippo_actions_load_music_thumbnail_async(HippoActions    *actions,
        const char      *image_url,
        HippoCanvasItem *image_item)
{
    char *absolute;

    if (actions->music_thumbnail_cache == NULL) {
        actions->music_thumbnail_cache = hippo_image_cache_new(get_platform(actions));
    }

    /* hippo_object_cache_debug_dump(HIPPO_OBJECT_CACHE(actions->music_thumbnail_cache)); */

    absolute = hippo_connection_make_absolute_url(get_connection(actions),
               image_url);
    load_image_url_async(actions, actions->music_thumbnail_cache, absolute, image_item);

    g_free(absolute);
}
示例#10
0
文件: vdb_info.c 项目: ncbi/sra-tools
static rc_t vdb_info_db( vdb_info_data * data, VSchema * schema, const VDBManager *mgr )
{
    const VDatabase * db;
    rc_t rc = VDBManagerOpenDBRead( mgr, &db, schema, "%s", data->acc );
    if ( rc == 0 )
    {
        const VTable * tab;
        const KMetadata * meta = NULL;

        rc_t rc1 = VDatabaseOpenTableRead( db, &tab, "SEQUENCE" );
        if ( rc1 == 0 )
        {
            data->s_platform = get_platform( tab );
            data->seq_rows = get_rowcount( tab );
            VTableRelease( tab );
        }

        data->ref_rows          = get_tab_row_count( db, "REFERENCE" );
        data->prim_rows         = get_tab_row_count( db, "PRIMARY_ALIGNMENT" );
        data->sec_rows          = get_tab_row_count( db, "SECONDARY_ALIGNMENT" );
        data->ev_rows           = get_tab_row_count( db, "EVIDENCE_ALIGNMENT" );
        data->ev_int_rows       = get_tab_row_count( db, "EVIDENCE_INTERVAL" );
        data->consensus_rows    = get_tab_row_count( db, "CONSENSUS" );
        data->passes_rows       = get_tab_row_count( db, "PASSES" );
        data->metrics_rows      = get_tab_row_count( db, "ZMW_METRICS" );

        if ( data->ref_rows > 0 )
            get_species( data->species, sizeof data->species, db, mgr );
        
        rc = VDatabaseOpenMetadataRead ( db, &meta );
        if ( rc == 0 )
        {
            get_meta_info( data, meta );
            KMetadataRelease ( meta );
        }

        VDatabaseRelease( db );
    }
    return rc;

}
示例#11
0
static rc_t vdb_info_tab( vdb_info_data * data, VSchema * schema, const VDBManager *mgr )
{
    const VTable * tab;
    rc_t rc = VDBManagerOpenTableRead( mgr, &tab, schema, "%s", data->acc );
    if ( rc == 0 )
    {
        const KMetadata * meta = NULL;

        data->s_platform = get_platform( tab );
        data->seq_rows = get_rowcount( tab );

        rc = VTableOpenMetadataRead ( tab, &meta );
        if ( rc == 0 )
        {
            get_meta_info( data, meta );
            KMetadataRelease ( meta );
        }

        VTableRelease( tab );
    }
    return rc;
}
示例#12
0
int
main(int argc, char *argv[])
{
    int ret, opt, option_index;
    vrouter_ops req;

    parse_ini_file();
    platform = get_platform();

    if (argc == 1) {
        Usage();
    }

    while ((opt = getopt_long(argc, argv, "",
                    long_options, &option_index)) >= 0) {
        switch (opt) {
        case 0:
            parse_long_opts(option_index, optarg);
            break;

        case '?':
        default:
            Usage();
            break;
        }
    }


    validate_options();

    cl = vr_get_nl_client(VR_NETLINK_PROTO_DEFAULT);
    if (!cl) {
        exit(1);
    }

    vr_vrouter_op(cl);

    return 0;
}
示例#13
0
void test_platforms()
{
	int i, j;
	char desc[256];
	struct cl_exec exec = { 0, 0, 1 };

	//Initialize the runtime
	cl_runtime rt = new_cl_runtime(false);
	printf("Testing %d platforms\n\n", get_num_platforms());
	for(i = 0; i < get_num_platforms(); i++)
	{
		exec.platform = i;
		clGetPlatformInfo(get_platform(rt, i), CL_PLATFORM_NAME, sizeof(desc), desc, NULL);
		printf("Testing devices for %s platform\n", desc);
		for(j = 0; j < get_num_devices(i); j++)
		{
			exec.device = j;
			test_device(rt, exec, get_device(rt, i, j));
		}
		printf("\n");
	}
	delete_cl_runtime(rt);
}
示例#14
0
void
hippo_actions_load_entity_photo_async(HippoActions    *actions,
                                      HippoEntity     *entity,
                                      int              size,
                                      HippoCanvasItem *image_item)
{
    const char *url;
    char *sized;
    char *absolute;

    url = hippo_entity_get_photo_url(entity);

    g_debug("Loading photo for entity '%s' url '%s' to a canvas item",
            hippo_entity_get_guid(entity),
            url ? url : "null");

    if (url == NULL) {
        /* not gonna succeed in loading this... */
        return;
    }

    sized = hippo_size_photo_url(url, size);

    if (actions->entity_photo_cache == NULL) {
        actions->entity_photo_cache = hippo_image_cache_new(get_platform(actions));
    }

    /* hippo_object_cache_debug_dump(HIPPO_OBJECT_CACHE(actions->entity_photo_cache)); */

    absolute = hippo_connection_make_absolute_url(get_connection(actions),
               sized);
    load_image_url_async(actions, actions->entity_photo_cache, absolute, image_item);

    g_free(absolute);
    g_free(sized);
}
示例#15
0
int 
main(int argc, char **argv)
{
    int res=0,
        run=0,
        dump=0,
        reset=0,
        detachall=0,
        detachpid=0,
        all=0,                  /* applies to all running processes */
        pid=-1,                 /* applies to pid, -1 means -all */
        hotp_nudge_pid=0,
        hotp_modes_nudge_pid=0,
        hotp_nudge_all=0,
        hotp_modes_nudge_all=0,
        nudge=0,                /* generic nudge with argument */
        nudge_action_mask=0,    /* generic nudge action mask */
        delay_ms_all=           /* delay between acting on processes */
                NUDGE_NO_DELAY,         
        timeout_ms=             /* timeout for finishing a nudge on a single process */
                DETACH_RECOMMENDED_TIMEOUT,
        runval=0,
        canary_default=0,
        canary_run = CANARY_RUN_FLAGS_DEFAULT,
        canary_fault_run = 0,
        exists = 0,
        destroy = 0,
        free_eventlog = 0;

    uint64 nudge_client_arg=0;     /* client nudge argument */

    int verbose = 0;

    char *create=NULL,
        *addapp=NULL, 
        *appdump=NULL, 
        *removeapp=NULL, 
        *opstring=NULL,
        *drdll=NULL,
        *preinject=NULL,
        *logdir=NULL,
        *sharedcache=NULL,
        *appname=NULL,
        *drhome=NULL,
        *modes=NULL,
        *defs=NULL,
        *detach_exename=NULL,
        *load=NULL,
        *save=NULL,
        *eventlog=NULL,
        *canary_process=NULL,
        *scratch_folder=NULL,
        *canary_fault_ops=NULL;

    dr_platform_t dr_platform = DR_PLATFORM_DEFAULT;
    
    int argidx=1;

    WCHAR wbuf[MAX_PATH];
    ConfigGroup *policy = NULL, *working_group;

    if (argc < 2) 
        usage();

    while (argidx < argc) {

        if (!strcmp(argv[argidx], "-help")) {
  	    help();
	}
        /* ******************** actions on active processes ******************** */
	else if (!strcmp(argv[argidx], "-detachall")) {
	    detachall=1;
	}
	else if (!strcmp(argv[argidx], "-detach")) {
            if (++argidx >= argc)
                usage();
	    detachpid=atoi(argv[argidx]);
	}
	else if (!strcmp(argv[argidx], "-detachexe")) {
            if (++argidx >= argc)
                usage();
	    detach_exename=argv[argidx];
	}
        else if (!strcmp(argv[argidx], "-pid") || !strcmp(argv[argidx], "-p")) {
            if (++argidx >= argc)
                usage();
            pid=atoi(argv[argidx]);
        }
	else if (!strcmp(argv[argidx], "-all")) {
	    all=1;
	}
        else if (!strcmp(argv[argidx], "-delay")) {
            /* in milliseconds */
            if (++argidx >= argc)
                usage();
            delay_ms_all=atoi(argv[argidx]);
        }
        else if (!strcmp(argv[argidx], "-timeout")) {
            /* in milliseconds */
            if (++argidx >= argc)
                usage();
            timeout_ms=atoi(argv[argidx]);
        }
	else if (!strcmp(argv[argidx], "-hot_patch_nudge")) {
            if (++argidx >= argc)
                usage();
	    hotp_nudge_pid=atoi(argv[argidx]);
	}
	else if (!strcmp(argv[argidx], "-hot_patch_modes_nudge")) {
            if (++argidx >= argc)
                usage();
	    hotp_modes_nudge_pid=atoi(argv[argidx]);
	}
	else if (!strcmp(argv[argidx], "-hot_patch_nudge_all")) {
	    hotp_nudge_all = 1;
	}
	else if (!strcmp(argv[argidx], "-verbose")) {
	    verbose = 1;
	}
	else if (!strcmp(argv[argidx], "-hot_patch_modes_nudge_all")) {
	    hotp_modes_nudge_all = 1;
	}
	else if (!strcmp(argv[argidx], "-drpop")) {
	    nudge = 1;
            /* allow composition */
	    nudge_action_mask |= NUDGE_GENERIC(opt) | NUDGE_GENERIC(reset);
	}
	else if (!strcmp(argv[argidx], "-nudge")) {
            int nudge_numeric;
            if (++argidx >= argc)
                usage();
            nudge_numeric = atoi(argv[argidx]); /* 0 if fails */
            nudge_action_mask |= nudge_numeric;

            /* compare against numeric new code, or against symbolic names */
            /* -nudge opt -nudge reset -nudge stats -nudge 30000 */
            {
                int found = 0;
#define NUDGE_DEF(name, comment) if (strcmp(#name, argv[argidx]) == 0) { found = 1; nudge_action_mask |= NUDGE_GENERIC(name);}
                NUDGE_DEFINITIONS();
#undef NUDGE_DEF
                if (!found && nudge_numeric == 0) {
                    printf("unknown -nudge %s\n", argv[argidx]);
                    usage();
                }
            }   

	    nudge=1;
	}
        else if (!strcmp(argv[argidx], "-client_nudge")) {
            if (++argidx >= argc)
                usage();
            nudge_client_arg = _strtoui64(argv[argidx], NULL, 16);
            nudge_action_mask |= NUDGE_GENERIC(client);
            nudge = 1;
        }
        /* ******************** configuration actions ******************** */
	else if (!strcmp(argv[argidx], "-reset")) {
	    reset=1;
	}
	else if (!strcmp(argv[argidx], "-create")) {
            if (++argidx >= argc)
                usage();
	    create = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-destroy")) {
            destroy = 1;
	}
	else if (!strcmp(argv[argidx], "-exists")) {
            exists = 1;
	}
	else if (!strcmp(argv[argidx], "-run")) {
            run = 1;
            if (++argidx >= argc)
                usage();
            runval = atoi(argv[argidx]);
	}
	else if (!strcmp(argv[argidx], "-app")) {
            if (++argidx >= argc)
                usage();
            appname = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-add")) {
            if (++argidx >= argc)
                usage();
	    addapp = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-remove")) {
            if (++argidx >= argc)
                usage();
	    removeapp = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-options")) {
            if (++argidx >= argc)
                usage();
	    opstring = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-drlib")) {
            if (++argidx >= argc)
                usage();
	    drdll = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-preinject")) {
            if (++argidx >= argc)
                usage();
            preinject = argv[argidx];
	}
        else if (!strcmp(argv[argidx], "-create_eventlog")) {
            if (++argidx >= argc)
                usage();
            eventlog = argv[argidx];
        }
	else if (!strcmp(argv[argidx], "-destroy_eventlog")) {
            free_eventlog = 1;
	}
	else if (!strcmp(argv[argidx], "-drhome")) {
            if (++argidx >= argc)
                usage();
            drhome = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-modes")) {
            if (++argidx >= argc)
                usage();
            modes = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-defs")) {
            if (++argidx >= argc)
                usage();
            defs = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-logdir")) {
            if (++argidx >= argc)
                usage();
	    logdir = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-sharedcache")) {
            if (++argidx >= argc)
                usage();
	    sharedcache = argv[argidx];
	}
	else if (!strcmp(argv[argidx], "-load")) {
            if (++argidx >= argc)
                usage();
	    load = argv[argidx];
	}
        else if (!strcmp(argv[argidx], "-save")) {
            if (++argidx >= argc)
                usage();
            save = argv[argidx];
        }
	else if (!strcmp(argv[argidx], "-dump")) {
	    dump = 1;
	}
	else if (!strcmp(argv[argidx], "-appdump")) {
            if (++argidx >= argc)
                usage();
            appdump = argv[argidx];	    
	}
	else if (!strcmp(argv[argidx], "-fulldump")) {
	    dump = 1;
	}
	else if (!strcmp(argv[argidx], "-v")) {
#ifdef BUILD_NUMBER
	  printf("DRcontrol.exe build %d -- %s", BUILD_NUMBER, __DATE__);
#else
	  printf("DRcontrol.exe custom build -- %s, %s", __DATE__, __TIME__);
#endif
	} else if (!strcmp(argv[argidx], "-canary_default")) {
            canary_default = 1;
	} else if (!strcmp(argv[argidx], "-canary")) {
            if (++argidx >= argc)
                usage();
	    canary_process=argv[argidx];
            if (++argidx >= argc)
                usage();
	    scratch_folder=argv[argidx];
	} else if (!strcmp(argv[argidx], "-canary_run")) {
            if (++argidx >= argc)
                usage();
	    canary_run = strtol(argv[argidx], NULL, 0);
	} else if (!strcmp(argv[argidx], "-canary_fault")) {
            char *dummy;
            if (++argidx >= argc)
                usage();
            canary_fault_run = strtol(argv[argidx], &dummy, 0);
            if (++argidx >= argc)
                usage();
            canary_fault_ops = argv[argidx];
	} else if (!strcmp(argv[argidx], "-32")) {
	    dr_platform = DR_PLATFORM_32BIT;
	} else if (!strcmp(argv[argidx], "-64")) {
	    dr_platform = DR_PLATFORM_64BIT;
	} else {
	    fprintf(stderr, "Unknown option: %s\n", argv[argidx]);
	    usage();
	}
	argidx++;
    }
  
    /* PR 244206: set the registry view before any registry access */
    set_dr_platform(dr_platform);

    if (canary_process != NULL || canary_default != 0) {
        BOOL result = TRUE;
        WCHAR canary_fault_args[MAX_PATH];
        CANARY_INFO info = {0};

        info.run_flags = canary_run;
        info.info_flags = CANARY_INFO_FLAGS_DEFAULT;
        info.fault_run = canary_fault_run;
        _snwprintf(canary_fault_args, BUFFER_SIZE_ELEMENTS(canary_fault_args),
                   L"%S", canary_fault_ops);
        NULL_TERMINATE_BUFFER(canary_fault_args);
        info.canary_fault_args = canary_fault_args;

        if (canary_process != NULL && *canary_process != '\0' &&
            scratch_folder != NULL && *scratch_folder != '\0') {
            wchar_t canary[MAX_PATH], scratch[MAX_PATH], out[MAX_PATH];
            FILE *out_file;
            _snwprintf(canary, BUFFER_SIZE_ELEMENTS(canary), L"%S", canary_process);
            NULL_TERMINATE_BUFFER(canary);
            _snwprintf(scratch, BUFFER_SIZE_ELEMENTS(scratch), L"%S\\canary_test",
                       scratch_folder);
            NULL_TERMINATE_BUFFER(scratch);
            CreateDirectory(scratch, NULL);
            _snwprintf(out, BUFFER_SIZE_ELEMENTS(out), L"%S\\canary_report.crep",
                       scratch_folder);
            out_file = _wfopen(out, L"wb");
            /* FIXME - check directory, out_file, and canary proc exist */
            result = run_canary_test_ex(out_file, &info, scratch, canary);
        } else if (canary_default != 0) {
            result = run_canary_test(&info, L_EXPAND_LEVEL(STRINGIFY(BUILD_NUMBER)));
            printf("See report file \"%S\"\n", info.report);
        }
        printf("Canary test - %s enable protection - code 0x%08x\n"
               "  msg=\"%S\"\n  url=\"%S\"\n", result ? "do" : "don\'t",
               info.canary_code, info.msg, info.url);
        return info.canary_code;
    }

    if (exists) {
        if (get_dynamorio_home() != NULL) {
            printf("Registry setup exists\n");
            return 0;
        }
        printf("Registry setup doesn't exist\n");
        return 1;
    }    

    if (save) {
        _snwprintf(wbuf, MAX_PATH, L"%S", save);
        NULL_TERMINATE_BUFFER(wbuf);
        checked_operation("save policy", save_policy(wbuf));
    }

    if (destroy) {
        checked_operation("delete product key", destroy_root_key());
        if (!load && create == NULL)
            return 0;
    }

    if (load) {
        _snwprintf(wbuf, MAX_PATH, L"%S", load);
        NULL_TERMINATE_BUFFER(wbuf);
        checked_operation("load policy", load_policy(wbuf, FALSE, NULL));
    }

    if (create != NULL) {
        _snwprintf(wbuf, MAX_PATH, L"%S", create);
        NULL_TERMINATE_BUFFER(wbuf);
        /* FALSE: do not overwrite (preserves old behavior) */
        checked_operation("create registry", setup_installation(wbuf, FALSE));
    }

    /* ensure we init dynamorio_home, case 4009 */
    get_dynamorio_home(); /* ignore return value */

    if (nudge) {
        if (verbose)
            printf("-nudge %d -pid %d %s\n", nudge_action_mask, pid, all ? "all" : "");
        if (pid == -1)           /* explicitly set */
            all = 1;

        if (all)
            checked_operation("nudge all", 
                              generic_nudge_all(nudge_action_mask, nudge_client_arg,
                                                timeout_ms, delay_ms_all));
        else
            checked_operation("nudge", 
                              generic_nudge(pid, TRUE,
                                            nudge_action_mask,
                                            0, /* client ID (ignored here) */
                                            nudge_client_arg,
                                            timeout_ms));
        goto finished;
    }

    if (detachall) {
        checked_operation("detach all", 
                          detach_all(timeout_ms));
        goto finished;
    }
    if (detachpid) {
        checked_operation("detach", 
                          detach(detachpid, TRUE, timeout_ms));
        goto finished;
    }

    if (detach_exename) {
        _snwprintf(wbuf, MAX_PATH, L"%S", detach_exename);
        NULL_TERMINATE_BUFFER(wbuf);
        checked_operation("detach-exe", 
                          detach_exe(wbuf, timeout_ms));
        goto finished;
    }

    
    if (hotp_nudge_pid) {
        checked_operation("hot patch update", 
                          hotp_notify_defs_update(hotp_nudge_pid, TRUE,
                                                  timeout_ms));
        goto finished;
    }

    if (hotp_modes_nudge_pid) {
        checked_operation("hot patch modes update", 
                          hotp_notify_modes_update(hotp_modes_nudge_pid, TRUE,
                                                   timeout_ms));
        goto finished;
    }

    if (hotp_nudge_all) {
        checked_operation("hot patch nudge all", 
                          hotp_notify_all_defs_update(timeout_ms));
        goto finished;
    }

    if (hotp_modes_nudge_all) {
        checked_operation("hot patch modes nudge all", 
                          hotp_notify_all_modes_update(timeout_ms));
        goto finished;
    }

    checked_operation("read config",
                      read_config_group(&policy, L_PRODUCT_NAME, TRUE));
    
    if (reset) {
        remove_children(policy);
        policy->should_clear = TRUE;
        checked_operation("write registry", write_config_group(policy));
    }

    working_group = policy;

    if (dump || appdump)
        goto dumponly;

    if (preinject) {
        if (0 == strcmp(preinject, "OFF")) {
            checked_operation("unset autoinject", unset_autoinjection());
        }
        else if (0 == strcmp(preinject, "ON")) {
            checked_operation("set autoinject", set_autoinjection());
        }
        else if (0 == strcmp(preinject, "CLEAR")) {
            checked_operation("clear autoinject", 
                              set_autoinjection_ex(FALSE, 
                                                   APPINIT_USE_WHITELIST,
                                                   NULL,
                                                   L"",
                                                   NULL,
                                                   NULL,
                                                   NULL,
                                                   0));
        }
        else if (0 == strcmp(preinject, "LIST")) {
            WCHAR list[MAX_PARAM_LEN];
            checked_operation("read appinit",
                              get_config_parameter(INJECT_ALL_KEY_L, 
                                                   TRUE, 
                                                   INJECT_ALL_SUBKEY_L, 
                                                   list, 
                                                   MAX_PARAM_LEN));
            printf("%S\n", list);
            if (is_vista()) {
                printf("LoadAppInit is %s\n",
                       is_loadappinit_set() ? "on" : "off");
            }
        }
        else if (0 == strcmp(preinject, "REPORT")) {
            WCHAR list[MAX_PARAM_LEN], *entry, *sep;
            checked_operation("read appinit",
                              get_config_parameter(INJECT_ALL_KEY_L, 
                                                   TRUE, 
                                                   INJECT_ALL_SUBKEY_L, 
                                                   list, 
                                                   MAX_PARAM_LEN));
            entry = get_entry_location(list, L_EXPAND_LEVEL(INJECT_DLL_8_3_NAME),
                                       APPINIT_SEPARATOR_CHAR);
            if (NULL != entry) {
                sep = wcschr(entry, APPINIT_SEPARATOR_CHAR);
                if (NULL != sep)
                    *sep = L'\0';
                printf("%S\n", entry);
                if (is_vista()) {
                    printf("LoadAppInit is %s\n",
                           is_loadappinit_set() ? "on" : "off");
                }
            }
        }
        else if (0 == strcmp(preinject, "LOAD_OFF")) {
            checked_operation("unset load autoinject", unset_loadappinit());
        }
        else if (0 == strcmp(preinject, "LOAD_ON")) {
            checked_operation("set load autoinject", set_loadappinit());
        }
        else {
            _snwprintf(wbuf, MAX_PATH, L"%S", preinject);
            NULL_TERMINATE_BUFFER(wbuf);
            checked_operation("set custom autoinject", 
                              set_autoinjection_ex(TRUE, APPINIT_OVERWRITE,
                                                   NULL, NULL, NULL, wbuf,
                                                   NULL, 0));
        }

        if (0 != strcmp(preinject, "LIST") &&
            0 != strcmp(preinject, "REPORT") &&
            using_system32_for_preinject(NULL)) {
            DWORD platform;
            if (get_platform(&platform) == ERROR_SUCCESS &&
                platform == PLATFORM_WIN_NT_4) {
                fprintf(stderr, "Warning! On NT4, new AppInit_DLLs setting will not take effect until reboot!\n");
            }
        }

    }

    if (free_eventlog) {
        checked_operation("free eventlog", destroy_eventlog());
    }

    if (eventlog) {
        _snwprintf(wbuf, BUFFER_SIZE_ELEMENTS(wbuf), L"%S", eventlog);
        NULL_TERMINATE_BUFFER(wbuf);
        checked_operation("create eventlog", create_eventlog(wbuf));
    }

    /* configuration */


    if (addapp) {
        _snwprintf(wbuf, MAX_PATH, L"%S", addapp);
        NULL_TERMINATE_BUFFER(wbuf);
        if (NULL == get_child(wbuf, policy)) {
            add_config_group(policy, new_config_group(wbuf));
        }
    }

    if (removeapp) {
        _snwprintf(wbuf, MAX_PATH, L"%S", removeapp);
        NULL_TERMINATE_BUFFER(wbuf);
        remove_child(wbuf, policy);
        policy->should_clear = TRUE;
    }

    if (appname) {
        _snwprintf(wbuf, MAX_PATH, L"%S", appname);
        NULL_TERMINATE_BUFFER(wbuf);
        working_group = get_child(wbuf, policy);

        if (NULL == working_group) {
            working_group = new_config_group(wbuf);
            add_config_group(policy, working_group);
        }
    }
    
    if (run) {
        _snwprintf(wbuf, MAX_PATH, L"%d", runval);
        NULL_TERMINATE_BUFFER(wbuf);
        set_config_group_parameter(working_group, 
                                   L_DYNAMORIO_VAR_RUNUNDER, wbuf);
    }

    if (opstring) {
        _snwprintf(wbuf, MAX_PATH, L"%S", opstring);
        NULL_TERMINATE_BUFFER(wbuf);
        set_config_group_parameter(working_group,
                                   L_DYNAMORIO_VAR_OPTIONS, wbuf);
    }
    
    if (drdll) {
        _snwprintf(wbuf, MAX_PATH, L"%S", drdll);
        NULL_TERMINATE_BUFFER(wbuf);
        set_config_group_parameter(working_group, 
                                   L_DYNAMORIO_VAR_AUTOINJECT, wbuf);
    }

    if (drhome) {
        _snwprintf(wbuf, MAX_PATH, L"%S", drhome);
        NULL_TERMINATE_BUFFER(wbuf);
        set_config_group_parameter(working_group, 
                                   L_DYNAMORIO_VAR_HOME, wbuf);
    }

    if (modes) {
        _snwprintf(wbuf, MAX_PATH, L"%S", modes);
        NULL_TERMINATE_BUFFER(wbuf);
        set_config_group_parameter(working_group, 
                                   L_DYNAMORIO_VAR_HOT_PATCH_MODES, wbuf);
    }

    if (defs) {
        _snwprintf(wbuf, MAX_PATH, L"%S", defs);
        NULL_TERMINATE_BUFFER(wbuf);
        set_config_group_parameter(working_group, 
                                   L_DYNAMORIO_VAR_HOT_PATCH_POLICIES, wbuf);
    }

    if (logdir) {
        _snwprintf(wbuf, MAX_PATH, L"%S", logdir);
        NULL_TERMINATE_BUFFER(wbuf);
        set_config_group_parameter(working_group, 
                                   L_DYNAMORIO_VAR_LOGDIR, wbuf);
    }

    if (sharedcache) {
        /* note if the sharedcache root directory doesn't exist it should be
         * created before calling this function */
        _snwprintf(wbuf, MAX_PATH, L"%S", sharedcache);
        NULL_TERMINATE_BUFFER(wbuf);

        res = setup_cache_shared_directories(wbuf);
        if (res != ERROR_SUCCESS) {
            fprintf(stderr, "error %d creating directories!\n", res);
        }
        setup_cache_shared_registry(wbuf, working_group);
    }

    checked_operation("write policy", write_config_group(policy));

 dumponly:

    if (appdump) {
        _snwprintf(wbuf, MAX_PATH, L"%S", appdump);
        NULL_TERMINATE_BUFFER(wbuf);
        working_group = get_child(wbuf, policy);
    }
    else {
        working_group = policy;
    }

    if (dump || appdump) {
        if (NULL == working_group)
            fprintf(stderr, "No Configuration Exists!\n");
        else
            dump_config_group("","  ",working_group,FALSE);
    }

 finished:
    if (policy != NULL)
        free_config_group(policy);

    return 0;

}
int
main(int argc, char *argv[])
{
	int option_index, rc, fail=0;
	int platform = 0;
	uint64_t dump_tag;

	platform = get_platform();
	switch (platform) {
	case PLATFORM_UNKNOWN:
	case PLATFORM_POWERKVM:
		fprintf(stderr, "%s: is not supported on the %s platform\n",
				argv[0], __power_platform_name(platform));
		return -1;
	}

	for (;;) {
		option_index = 0;
		rc = getopt_long(argc, argv, "hv", long_options,
				&option_index);

		if (rc == -1)
			break;

		switch (rc) {
		case 'h':
			print_usage(argv[0]);
			return 0;
		case 'v':
			flag_v = 1;
			break;
		case '?':
			print_usage(argv[0]);
			return -1;
			break;
		default:
			printf("huh?\n");
			break;
		}
	}

	if (optind < argc) {
		/* Parse ppc64-diag config file */
		rc = diag_cfg(0, &msg);
		if (rc) {
			fprintf(stderr, "Could not parse configuration file "
				"%s\n", config_file);
			return -2;
		}

		while (optind < argc) {
			dump_tag = strtoll(argv[optind++], NULL, 16);
			fail += extract_platform_dump(dump_tag);
		}
	}
	else {
		fprintf(stderr, "No dump tag specified\n");
		print_usage(argv[0]);
		return -1;
	}

	return fail;
}
int main(int argc, char **argv) 
{
	char *loc_code = "";
	char err_buf[ERR_BUF_SIZE];
	int lflag = 0, rc, c;
	unsigned int seq = 1, next_seq;
	struct buf_element *list, *current;

	if (get_platform() != PLATFORM_PSERIES_LPAR) {
		fprintf(stderr, "%s: is not supported on the %s platform\n",
							argv[0], platform_name);
		exit(1);
	}

	if (!check_rtas_call()) {
		fprintf(stderr, "The ibm,get-vpd RTAS call is not available "
			"on this system.\n");
		return 4;
	}

	/* Parse command line options */
	opterr = 0;
	while ((c = getopt (argc, argv, "l:h")) != -1) {
		switch (c) {
		case 'l':
			loc_code = optarg;
			lflag = 1;
			break;
		case 'h':
			print_help(argv[0]);
			return 0;
		case '?':
			if (isprint (optopt))
				fprintf(stderr, "Unrecognized option: -%c.\n", 
					optopt);
			else
				fprintf(stderr, "Unrecognized option character "
					"\\x%x.\n", optopt);
			print_usage(argv[0]);
			return 1;
		default:
			abort();
		}
	}

	list = (struct buf_element *)malloc(sizeof(struct buf_element));
	if (!list) {
		fprintf(stderr, "Out of memory\n");
		return 5;
	}
	list->size = 0;
	list->next = NULL;
	current = list;

	do {
		rc = rtas_get_vpd(loc_code, current->buf, BUF_SIZE,
				seq, &next_seq, &(current->size));

		switch (rc) {
		case CONTINUE:
			seq = next_seq;
			current->next = (struct buf_element *)
					malloc(sizeof(struct buf_element));
			if (!current->next) {
				fprintf(stderr, "Out of memory\n");
				delete_list(list);
				return 5;
			}
			current = current->next;
			current->size = 0;
			current->next = NULL;
			/* fall through */
		case SUCCESS:
			break;
		case VPD_CHANGED:
			seq = 1;
			delete_list(list);
			list = (struct buf_element *)
					malloc(sizeof(struct buf_element));
			if (!list) {
				fprintf(stderr, "Out of memory\n");
				return 5;
			}
			list->size = 0;
			list->next = NULL;
			current = list;
			break;
		case PARAMETER_ERROR:
			delete_list(list);
			return 1;
		case HARDWARE_ERROR:
			delete_list(list);
			return 2;
		default:
			delete_list(list);
			if (is_librtas_error(rc)) {
				librtas_error(rc, err_buf, ERR_BUF_SIZE);
				fprintf(stderr, "Could not gather vpd\n%s\n", err_buf);
			} else {
				fprintf(stderr, "Could not gather vpd\n");
			}

	                return 3;
        	}
	} while(rc != SUCCESS);

	current = list;
	do {
		size_t count;

		if (current->size <= 0) 
			continue;
		
		count = fwrite(current->buf, 1, current->size, stdout);
		if (count < current->size)
			break;

	} while ((current = (current->next)) != NULL);

	delete_list(list);

	return 0;
}
示例#18
0
int
main(int argc, char *argv[])
{
	int failure = 0, option_index, rc;
	char path[PATH_MAX];
	DIR *edir, *sdir;
	struct dirent *sdirent, *edirent;
	struct dev_vpd *diagnosed = NULL;

	platform = get_platform();
	if (platform != PLATFORM_PSERIES_LPAR) {
		fprintf(stderr, "%s is not supported on the %s platform\n",
				argv[0], __power_platform_name(platform));
		return -1;
	}

	memset(&cmd_opts, 0, sizeof(cmd_opts));

	for (;;) {
		option_index = 0;
		rc = getopt_long(argc, argv, "cf:hlsvV", long_options,
				 &option_index);

		if (rc == -1)
			break;

		switch (rc) {
		case 'c':
			cmd_opts.cmp_prev = 1;
			break;
		case 'f':
			if (cmd_opts.fake_path) {
				fprintf(stderr, "Multiple -f options not "
						"supported.\n");
				return -1;
			}
			cmd_opts.fake_path = optarg;
			break;
		case 'h':
			print_usage(argv[0]);
			return 0;
		case 'l':
			cmd_opts.leds = 1;
			break;
		case 's':
			cmd_opts.serv_event = 1;
			break;
		case 'v':
			cmd_opts.verbose = 1;
			break;
		case 'V':
			printf("%s %s\n", argv[0], VERSION);
			return 0;
		case '?':
			print_usage(argv[0]);
			return -1;
		default:
			/* Shouldn't get here. */
			fprintf(stderr, "huh?\n");
			print_usage(argv[0]);
			return -1;
		}
	}

	if (cmd_opts.cmp_prev && !cmd_opts.serv_event) {
		fprintf(stderr, "No -c option without -s\n");
		return -1;
	}

	if (cmd_opts.leds && !cmd_opts.serv_event) {
		fprintf(stderr, "No -l option without -s\n");
		return -1;
	}

	if ((cmd_opts.serv_event || cmd_opts.leds) && geteuid() != 0) {
		fprintf(stderr, "-s and -l options require superuser "
				"privileges\n");
		return -1;
	}

	if (cmd_opts.fake_path) {
		const char *dot = strrchr(cmd_opts.fake_path, '.');
		if (!dot || strcmp(dot, ".pg2") != 0) {
			fprintf(stderr, "Name of file with fake diagnostic "
					"data must end in '.pg2'.\n");
			return -1;
		}
		if (optind + 1 != argc) {
			fprintf(stderr, "Please specify an sg device with the "
					"-f pathname. It need not be an "
					"enclosure.\n");
			return -1;
		}
		failure += diagnose(argv[optind++], &diagnosed);
	} else if (optind < argc) {
		while (optind < argc)
			failure += diagnose(argv[optind++], &diagnosed);

	} else {
		edir = opendir(SCSI_SES_PATH);
		if (!edir) {
			fprintf(stderr,
				"System does not have SCSI enclosure(s).\n");
			return -1;
		}

		/* loop over all enclosures */
		while ((edirent = readdir(edir)) != NULL) {
			if (!strcmp(edirent->d_name, ".") ||
			    !strcmp(edirent->d_name, ".."))
				continue;

			snprintf(path, PATH_MAX, "%s/%s/device/scsi_generic",
				 SCSI_SES_PATH, edirent->d_name);

			sdir = opendir(path);
			if (!sdir)
				continue;

			while ((sdirent = readdir(sdir)) != NULL) {
				if (!strcmp(sdirent->d_name, ".") ||
				    !strcmp(sdirent->d_name, ".."))
					continue;

				/* run diagnostics */
				failure += diagnose(sdirent->d_name,
						    &diagnosed);
			}
			closedir(sdir);
		} /* outer while loop */
		closedir(edir);
	}

	free(cmd_opts.prev_path);
	free_dev_vpd(diagnosed);

	return failure;
}
示例#19
0
/*
 * Connect to a DAV server
 * This function sets the flag _connected if the connection is established
 * and returns if the flag is set, so calling it frequently is save.
 */
static int dav_connect(const char *base_url) {
    int useSSL = 0;
    int rc;
    char protocol[6] = {'\0'};
    char uaBuf[256];
    char *path = NULL;
    char *scheme = NULL;
    char *host = NULL;
    unsigned int port = 0;
    int proxystate = -1;

    if (_connected) {
        return 0;
    }

    rc = c_parse_uri( base_url, &scheme, &dav_session.user, &dav_session.pwd, &host, &port, &path );
    if( rc < 0 ) {
        DEBUG_WEBDAV("Failed to parse uri %s", base_url );
        goto out;
    }

    DEBUG_WEBDAV("* scheme %s", scheme );
    DEBUG_WEBDAV("* host %s", host );
    DEBUG_WEBDAV("* port %u", port );
    DEBUG_WEBDAV("* path %s", path );

    if( strcmp( scheme, "owncloud" ) == 0 ) {
        strcpy( protocol, "http");
    } else if( strcmp( scheme, "ownclouds" ) == 0 ) {
        strcpy( protocol, "https");
        useSSL = 1;
    } else {
        DEBUG_WEBDAV("Invalid scheme %s, go outa here!", scheme );
        rc = -1;
        goto out;
    }

    DEBUG_WEBDAV("* user %s", dav_session.user ? dav_session.user : "");

    if (port == 0) {
        port = ne_uri_defaultport(protocol);
    }

#if 0
    rc = ne_sock_init();
    DEBUG_WEBDAV("ne_sock_init: %d", rc );
    if (rc < 0) {
        rc = -1;
        goto out;
    }
#endif

    dav_session.ctx = ne_session_create( protocol, host, port);

    if (dav_session.ctx == NULL) {
        DEBUG_WEBDAV("Session create with protocol %s failed", protocol );
        rc = -1;
        goto out;
    }

    if (dav_session.read_timeout == 0)
        dav_session.read_timeout = 300;  // set 300 seconds as default.

    ne_set_read_timeout(dav_session.ctx, dav_session.read_timeout);

    snprintf( uaBuf, sizeof(uaBuf), "Mozilla/5.0 (%s) csyncoC/%s",
              get_platform(), CSYNC_STRINGIFY( LIBCSYNC_VERSION ));
    ne_set_useragent( dav_session.ctx, uaBuf);
    ne_set_server_auth(dav_session.ctx, ne_auth, 0 );

    if( useSSL ) {
        if (!ne_has_support(NE_FEATURE_SSL)) {
            DEBUG_WEBDAV("Error: SSL is not enabled.");
            rc = -1;
            goto out;
        }

        ne_ssl_trust_default_ca( dav_session.ctx );
        ne_ssl_set_verify( dav_session.ctx, verify_sslcert, 0 );
    }

    /* Hook called when a request is created. It sets the proxy connection header. */
    ne_hook_create_request( dav_session.ctx, request_created_hook, NULL );
    /* Hook called after response headers are read. It gets the Session ID. */
    ne_hook_post_headers( dav_session.ctx, post_request_hook, NULL );
    /* Hook called before a request is sent. It sets the cookies. */
    ne_hook_pre_send( dav_session.ctx, pre_send_hook, NULL );
    /* Hook called after request is dispatched. Used for handling possible redirections. */
    ne_hook_post_send( dav_session.ctx, post_send_hook, NULL );

    /* Proxy support */
    proxystate = configureProxy( dav_session.ctx );
    if( proxystate < 0 ) {
        DEBUG_WEBDAV("Error: Proxy-Configuration failed.");
    } else if( proxystate > 0 ) {
        ne_set_proxy_auth( dav_session.ctx, ne_proxy_auth, 0 );
    }

    _connected = 1;
    rc = 0;
out:
    SAFE_FREE(path);
    SAFE_FREE(host);
    SAFE_FREE(scheme);
    return rc;
}
示例#20
0
文件: ap1000.c 项目: cmp1084/u-boot
/** serial number and platform display at startup */
int checkboard (void)
{
	char *s = getenv ("serial#");
	char *e;

	/* After a loadace command, the SystemAce control register is left in a wonky state. */
	/* this code did not work in board_pre_init */
	unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE;

	p[SYSACE_CTRLREG0] = 0x0;

	/* add platform and device to banner */
	switch (get_device ()) {
	case AP1xx_AP107_TARGET:
		puts (AP1xx_AP107_TARGET_STR);
		break;
	case AP1xx_AP120_TARGET:
		puts (AP1xx_AP120_TARGET_STR);
		break;
	case AP1xx_AP130_TARGET:
		puts (AP1xx_AP130_TARGET_STR);
		break;
	case AP1xx_AP1070_TARGET:
		puts (AP1xx_AP1070_TARGET_STR);
		break;
	case AP1xx_AP1100_TARGET:
		puts (AP1xx_AP1100_TARGET_STR);
		break;
	default:
		puts (AP1xx_UNKNOWN_STR);
		break;
	}
	puts (AP1xx_TARGET_STR);
	puts (" with ");

	switch (get_platform ()) {
	case AP100_BASELINE_PLATFORM:
	case AP1000_BASELINE_PLATFORM:
		puts (AP1xx_BASELINE_PLATFORM_STR);
		break;
	case AP1xx_QUADGE_PLATFORM:
		puts (AP1xx_QUADGE_PLATFORM_STR);
		break;
	case AP1xx_MGT_REF_PLATFORM:
		puts (AP1xx_MGT_REF_PLATFORM_STR);
		break;
	case AP1xx_STANDARD_PLATFORM:
		puts (AP1xx_STANDARD_PLATFORM_STR);
		break;
	case AP1xx_DUAL_PLATFORM:
		puts (AP1xx_DUAL_PLATFORM_STR);
		break;
	case AP1xx_BASE_SRAM_PLATFORM:
		puts (AP1xx_BASE_SRAM_PLATFORM_STR);
		break;
	case AP1xx_PCI_PCB_TESTPLATFORM:
	case AP1000_PCI_PCB_TESTPLATFORM:
		puts (AP1xx_PCI_PCB_TESTPLATFORM_STR);
		break;
	case AP1xx_DUAL_GE_MEZZ_TESTPLATFORM:
		puts (AP1xx_DUAL_GE_MEZZ_TESTPLATFORM_STR);
		break;
	case AP1xx_SFP_MEZZ_TESTPLATFORM:
		puts (AP1xx_SFP_MEZZ_TESTPLATFORM_STR);
		break;
	default:
		puts (AP1xx_UNKNOWN_STR);
		break;
	}

	if ((get_platform () & AP1xx_TESTPLATFORM_MASK) != 0) {
		puts (AP1xx_TESTPLATFORM_STR);
	} else {
		puts (AP1xx_PLATFORM_STR);
	}

	putc ('\n');

	puts ("Serial#: ");

	if (!s) {
		printf ("### No HW ID - assuming AMIRIX");
	} else {
		for (e = s; *e; ++e) {
			if (*e == ' ')
				break;
		}

		for (; s < e; ++s) {
			putc (*s);
		}
	}

	putc ('\n');

	return (0);
}
示例#21
0
HippoQuipWindow*
hippo_quip_window_new(HippoDataCache *cache)
{
    HippoQuipWindow *quip_window;
    HippoCanvasBox *outer_box;
    HippoCanvasBox *top_box;
    HippoCanvasBox *middle_box;
    HippoCanvasBox *bottom_box;
    HippoCanvasBox *box;
    HippoCanvasItem *item;

    g_return_val_if_fail(HIPPO_IS_DATA_CACHE(cache), NULL);

    quip_window = g_object_new(HIPPO_TYPE_QUIP_WINDOW,
                               NULL);

    g_object_ref(cache);
    quip_window->cache = cache;

    quip_window->window = hippo_platform_create_window(get_platform(quip_window));

    g_signal_connect(quip_window->window, "notify::active",
                     G_CALLBACK(on_notify_active),  quip_window);

    g_object_set(quip_window->window, "role", HIPPO_WINDOW_ROLE_INPUT_POPUP, NULL);    

    outer_box = g_object_new(HIPPO_TYPE_CANVAS_BOX,
                             "box-width", WINDOW_WIDTH,
                             "padding-left", 7,
                             "padding-right", 3,
                             "padding-top", 3,
                             "padding-bottom", 7,
                             "border", 1,
                             "background-color", 0xffffffff,
                             "border-color", 0x000000ff,
                             "spacing", 4,
                             NULL);
    hippo_window_set_contents(quip_window->window, HIPPO_CANVAS_ITEM(outer_box));

    top_box = g_object_new(HIPPO_TYPE_CANVAS_BOX,
                           "orientation", HIPPO_ORIENTATION_HORIZONTAL,
                           NULL);
    hippo_canvas_box_append(outer_box, HIPPO_CANVAS_ITEM(top_box), 0);

    quip_window->title_item = g_object_new(HIPPO_TYPE_CANVAS_TEXT,
                                           "xalign", HIPPO_ALIGNMENT_START,
                                           "padding-top", 1,
                                           "size-mode", HIPPO_CANVAS_SIZE_ELLIPSIZE_END,
                                           NULL);
    hippo_canvas_box_append(top_box, HIPPO_CANVAS_ITEM(quip_window->title_item), HIPPO_PACK_EXPAND);

    /* This box keeps the image from expanding beyond it's natural size, since we only
     * want the image itself to show as a link; really a HIPPO_CANVAS_IMAGE_BUTTON bug
     * but hardish to fix.
     */
    box = g_object_new(HIPPO_TYPE_CANVAS_BOX,
                       "orientation", HIPPO_ORIENTATION_VERTICAL,
                       NULL);
    hippo_canvas_box_append(top_box, HIPPO_CANVAS_ITEM(box), HIPPO_PACK_END);

    item = g_object_new(HIPPO_TYPE_CANVAS_IMAGE_BUTTON,
                        "normal-image-name", "flat_x",
                        NULL);
    hippo_canvas_box_append(box, item, 0);
    g_signal_connect(G_OBJECT(item), "activated",
                     G_CALLBACK(on_close_activated), quip_window);
     
    middle_box = g_object_new(HIPPO_TYPE_CANVAS_BOX,
                              "orientation", HIPPO_ORIENTATION_HORIZONTAL,
                              "spacing", 4,
                              NULL);
    hippo_canvas_box_append(outer_box, HIPPO_CANVAS_ITEM(middle_box), 0);

    quip_window->indifferent_box = create_sentiment_box(quip_window,
                                                        "Quip",
                                                        "chat",
                                                        G_CALLBACK(on_indifferent_activated));
    hippo_canvas_box_append(middle_box, HIPPO_CANVAS_ITEM(quip_window->indifferent_box), 0);

    quip_window->love_box = create_sentiment_box(quip_window,
                                                 "I love it!",
                                                 "quiplove_icon",
                                                 G_CALLBACK(on_love_activated));
    hippo_canvas_box_append(middle_box, HIPPO_CANVAS_ITEM(quip_window->love_box), 0);

    quip_window->hate_box = create_sentiment_box(quip_window,
                                                 "I hate it!",
                                                 "quiphate_icon",
                                                 G_CALLBACK(on_hate_activated));
    hippo_canvas_box_append(middle_box, HIPPO_CANVAS_ITEM(quip_window->hate_box), 0);
    
    bottom_box = g_object_new(HIPPO_TYPE_CANVAS_BOX,
                              "orientation", HIPPO_ORIENTATION_HORIZONTAL,
                              NULL);
    hippo_canvas_box_append(outer_box, HIPPO_CANVAS_ITEM(bottom_box), 0);

    quip_window->entry = hippo_canvas_entry_new();
    hippo_canvas_box_append(bottom_box, quip_window->entry, HIPPO_PACK_EXPAND);
    g_signal_connect(G_OBJECT(quip_window->entry), "key-press-event",
                     G_CALLBACK(on_key_press_event), quip_window);

    item = hippo_canvas_button_new();
    g_object_set(item,
                 "padding-left", 8,
                 "padding-right", 4,
                 "text", "Quip!",
                 NULL);
    hippo_canvas_box_append(bottom_box, item, HIPPO_PACK_END);
    g_signal_connect(G_OBJECT(item), "activated",
                     G_CALLBACK(on_quip_activated), quip_window);

    hippo_quip_window_update_sentiment(quip_window);
    
    return quip_window;
}
/**
 * main
 * @brief Parse command line args process database
 *
 * @param argc the number of command-line arguments
 * @param argv array of command-line arguments
 * @return exit status: 0 for normal exit, 1 for usage error, >1 for other error
 */
int
main(int argc, char *argv[])
{
	struct servicelog *slog;
	int rc;
	struct sl_event *event, *events;
	struct sl_repair_action *repair, *repairs;
	struct sl_notify *notify, *notifications;
	int option_index, action=ACTION_UNSPECIFIED;
	int flag_force=0;
	int age = 60;	/* default age for --clean */
	int platform = 0;
	char buf[124];
	char *tmp;
	char *next_char;
	uint32_t num=0, num_repaired=0, num_unrepaired=0, num_info=0, num_ra=0;
	uint32_t span;
	time_t now;

	cmd = argv[0];

	platform = get_platform();
	switch (platform) {
	case PLATFORM_UNKNOWN:
	case PLATFORM_POWERNV:
		fprintf(stderr, "%s: is not supported on the %s platform\n",
					cmd, __power_platform_name(platform));
		exit(1);
	}

	if (argc <= 1) {
		print_usage();
		exit(0);
	}

	for (;;) {
		option_index = 0;
		rc = getopt_long(argc, argv, ARG_LIST, long_options,
				&option_index);

		if (rc == -1)
			break;

		switch (rc) {
		case 's':
			if (action != ACTION_UNSPECIFIED)
				action = ACTION_TOOMANY;
			if (action != ACTION_TOOMANY)
				action = ACTION_STATUS;
			break;
		case 't':
			if (!optarg) {
				fprintf(stderr, "The --truncate option "
					"requires either \"events\" or "
					"\"notify\" as an argument.\n");
				print_usage();
				exit(1);
			}

			if (!strcmp(optarg, "events")) {
				if (action != ACTION_UNSPECIFIED)
					action = ACTION_TOOMANY;
				if (action != ACTION_TOOMANY)
					action = ACTION_TRUNCATE_EVENTS;
			}
			else if (!strcmp(optarg, "notify")) {
				if (action != ACTION_UNSPECIFIED)
					action = ACTION_TOOMANY;
				if (action != ACTION_TOOMANY)
					action = ACTION_TRUNCATE_NOTIFY;
			}
			else {
				fprintf(stderr, "The --truncate option "
					"requires either \"events\" or "
					"\"notify\" as an argument.\n");
				print_usage();
				exit(1);
			}
			break;
		case 'c':
			if (action != ACTION_UNSPECIFIED)
				action = ACTION_TOOMANY;
			if (action != ACTION_TOOMANY)
				action = ACTION_CLEAN;
			break;
		case 'a':
			age = (int)strtoul(optarg, &next_char, 10);
			if (optarg[0] == '\0' || *next_char != '\0' ||
								age < 0) {
				print_usage();
				exit(1);
			}
			break;
		case 'f':
			flag_force = 1;
			break;
		case 'h':	/* help */
			print_usage();
			exit(0);
		case '?':
			print_usage();
			exit(1);
		default:
			printf("Invalid argument: %s\n", optarg);
			print_usage();
			exit(1);
		}
	}

	if (optind < argc) {
		print_usage();
		exit(1);
	}

	/* Command-line validation */
	if (action == ACTION_UNSPECIFIED) {
		fprintf(stderr, "One of the action options is required.\n");
		print_usage();
		exit(1);
	}

	if (action == ACTION_TOOMANY) {
		fprintf(stderr, "Only one of the action options may be "
			"specified.\n");
		print_usage();
		exit(1);
	}


	switch (action) {

	case ACTION_STATUS:
		rc = servicelog_open(&slog, 0);
		if (rc != 0) {
			fprintf(stderr, "%s: Could not open servicelog "
					"database.\n%s\n",
					argv[0], servicelog_error(slog));
			exit(2);
		}

		rc = servicelog_event_query(slog, "", &events);
		if (rc != 0) {
			fprintf(stderr, "%s\n", servicelog_error(slog));
			servicelog_close(slog);
			exit(2);
		}

		for (event = events; event; event = event->next) {
			num++; // total event count
			if (event->serviceable && (event->repair > 0))
				num_repaired++;
			else if (event->serviceable)
				num_unrepaired++;
			else
				num_info++; // informational events
		}

		servicelog_event_free(events);

		// Now need to query repair actions:
		rc = servicelog_repair_query(slog, "", &repairs);
		if (rc != 0) {
			fprintf(stderr, "%s\n", servicelog_error(slog));
			servicelog_close(slog);
			exit(2);
		}

		for (repair = repairs; repair; repair = repair->next)
			num_ra++;
		servicelog_repair_free(repairs);

		servicelog_close(slog);

		printf("%-39s%10u\n", "Logged events:", num);
		printf("    %-35s%10u\n", "unrepaired serviceable events:",
		       num_unrepaired);
		printf("    %-35s%10u\n", "repaired serviceable events:",
		       num_repaired);
		printf("    %-35s%10u\n", "informational events:", num_info);
		printf("    %-35s%10u\n", "repair actions:", num_ra);
		break;


	case ACTION_TRUNCATE_EVENTS:
		if (geteuid() != 0) // Check to see if user is root
		{
			printf("Must be root to truncate the database!\n");
			exit(2);
		}

		num = 0;

		if (!flag_force) {
			printf("Are you certain you wish to delete ALL events "
			       "from the servicelog?\n");
			printf("Enter 'yes' to continue > ");
			tmp = fgets(buf, 80, stdin);
			if (!tmp)
				exit(2);

			if (strcasecmp(buf, "yes\n")) {
				printf("Operation cancelled.\n");
				exit(4);
			}
		}

		rc = servicelog_open(&slog, SL_FLAG_ADMIN);
		if (rc != 0) {
			fprintf(stderr, "%s: Could not open servicelog "
					"database.\n%s\n",
					argv[0], servicelog_error(slog));
			exit(2);
		}
		rc = servicelog_event_query(slog, "", &events);
		if (rc != 0) {
			fprintf(stderr, "%s\n", servicelog_error(slog));
			servicelog_close(slog);
			exit(2);
		}

		for (event = events; event; event = event->next) {
			num++;
			servicelog_event_delete(slog, event->id);
		}

		servicelog_event_free(events);

		// Delete repair actions as well.
		rc = servicelog_repair_query(slog, "", &repairs);
		if (rc != 0) {
			fprintf(stderr, "%s\n", servicelog_error(slog));
			servicelog_close(slog);
			exit(2);
		}

		for (repair = repairs; repair; repair = repair->next) {
			num_ra++;
			servicelog_repair_delete(slog, repair->id);
		}
		servicelog_repair_free(repairs);

		printf("Deleted %u records.\n", num + num_ra);
		servicelog_close(slog);
		break;

	case ACTION_TRUNCATE_NOTIFY:
		if (geteuid() != 0) // Check to see if user is root
		{
			printf("Must be root to truncate the database!\n");
			exit(2);
		}

		num = 0;

		if (!flag_force) {
			printf("Are you certain you wish to delete ALL "
					"notification tools from the servicelog?\n");
			printf("Enter 'yes' to continue > ");
			tmp = fgets(buf, 80, stdin);
			if (!tmp)
				exit(2);

			if (strcasecmp(buf, "yes\n")) {
				printf("Operation cancelled.\n");
				exit(4);
			}
		}

		rc = servicelog_open(&slog, SL_FLAG_ADMIN);
		if (rc != 0) {
			fprintf(stderr, "%s: Could not open servicelog "
					"database.\n%s\n",
					argv[0], servicelog_error(slog));
			exit(2);
		}
		rc = servicelog_notify_query(slog, "", &notifications);
		if (rc != 0) {
			fprintf(stderr, "%s\n", servicelog_error(slog));
			servicelog_close(slog);
			exit(2);
		}

		for (notify = notifications; notify; notify = notify->next) {
			num++;
			servicelog_notify_delete(slog, notify->id);
		}
		servicelog_notify_free(notifications);
		servicelog_close(slog);

		printf("Deleted %u records.\n", num);
		break;

	case ACTION_CLEAN:
		if (geteuid() != 0) { // Check to see if user is root
			printf("Must be root to purge older events "
			       "in the database!\n");
			exit(2);
		}

		if (!flag_force) {
			printf("Are you certain you wish to perform the "
			       "following tasks?\n"
			       " - Delete all repaired serviceable events\n"
			       " - Delete all informational events older than "
			       "%d days\n"
			       " - Delete all repair actions older than "
			       "%d days\n"
			       " - Delete anything older than 1 year\n",
			       age, age);
			printf("Enter 'yes' to continue > ");
			tmp = fgets(buf, 80, stdin);
			if (!tmp)
				exit(2);

			if (strcasecmp(buf, "yes\n")) {
				printf("Operation cancelled.\n");
				break;
			}
		}

		rc = servicelog_open(&slog, 0);
		if (rc != 0) {
			fprintf(stderr, "%s: Could not open servicelog "
					"database.\n%s\n",
					argv[0], servicelog_error(slog));
			exit(2);
		}

		now = time(NULL);
		span = age * SECONDS_IN_DAY;

		rc = servicelog_event_query(slog, "", &events);
		if (rc != 0) {
			fprintf(stderr, "%s\n", servicelog_error(slog));
			servicelog_close(slog);
			exit(2);
		}

		for (event = events; event; event = event->next) {
			if (event->serviceable && event->closed) {
				num_repaired++;
				servicelog_event_delete(slog, event->id);
			}
			else if (!event->serviceable &&
				 (event->time_logged + span) < now) {
				num_info++;
				servicelog_event_delete(slog, event->id);
			}
			else if ((event->time_logged + SECONDS_IN_YEAR) < now) {
				num++;
				servicelog_event_delete(slog, event->id);
			}
		}
		servicelog_event_free(events);

		/* Delete repair actions which are older than age */
		rc = servicelog_repair_query(slog, "", &repairs);
		if (rc != 0) {
			fprintf(stderr, "%s\n", servicelog_error(slog));
			servicelog_close(slog);
			exit(2);
		}
		for (repair = repairs; repair; repair = repair->next) {
			if ((repair->time_logged + span) < now ) {
				num_ra++;
				servicelog_repair_delete(slog, repair->id);
			}
		}
		servicelog_repair_free(repairs);
		servicelog_close(slog);

		printf("Removed %u repaired serviceable events.\n",
		       num_repaired);
		printf("Removed %u informational events older than %d days.\n",
		       num_info, age);
		printf("Removed %u repair actions older than %d days.\n",
		       num_ra, age);
		printf("Removed %u other events older than one year.\n", num);
		break;

	default:
		fprintf(stderr, "Internal error; unknown action %d\n", action);
		exit(3);
	}

	exit(0);
}
示例#23
0
gboolean
hippo_actions_can_play_song_download(HippoActions      *actions,
                                     HippoSongDownload *song_download)
{
    return hippo_platform_can_play_song_download(get_platform(actions), song_download);
}
示例#24
0
int main(int argc, char **argv){
	cl_context context = get_platform(CL_DEVICE_TYPE_GPU);
	cl_device_id device = 0;
	cl_command_queue queue = get_first_device(context, &device);
	char *prog_src = read_file(CL_PROGRAM("convolution.cl"), NULL);
	cl_program program = build_program(prog_src, context, device, NULL);
	free(prog_src);
	cl_int err = CL_SUCCESS;
	cl_kernel kernel = clCreateKernel(program, "convolve", &err);
	check_cl_err(err, "failed to create kernel");

	//Setup our input signal and mask
	cl_uint in_signal[IN_DIM][IN_DIM] = {
		{ 3, 1, 1, 4, 8, 2, 1, 3 },
		{ 4, 2, 1, 1, 2, 1, 2, 3 },
		{ 4, 4, 4, 4, 3, 2, 2, 2 },
		{ 9, 8, 3, 8, 9, 0, 0, 0 },
		{ 9, 3, 3, 9, 0, 0, 0, 0 },
		{ 0, 9, 0, 8, 0, 0, 0, 0 },
		{ 3, 0, 8, 8, 9, 4, 4, 4 },
		{ 5, 9, 8, 1, 8, 1, 1, 1 }
	};
	cl_uint mask[MASK_DIM][MASK_DIM] = {
		{ 1, 1, 1 },
		{ 1, 0, 1 },
		{ 1, 1, 1 }
	};
	//0 is input, 1 is mask, 2 is output
	cl_mem mem_objs[3];
	mem_objs[0] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
		sizeof(cl_uint) * IN_DIM * IN_DIM, in_signal, &err);
	mem_objs[1] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
		sizeof(cl_uint) * MASK_DIM * MASK_DIM, mask, &err);
	mem_objs[2] = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
		sizeof(cl_uint) * OUT_DIM * OUT_DIM, NULL, &err);
	check_cl_err(err, "failed to create buffers");

	for (int i = 0; i < 3; ++i){
		err = clSetKernelArg(kernel, i, sizeof(cl_mem), &mem_objs[i]);
		check_cl_err(err, "failed to set kernel argument");
	}
	size_t in_dim = IN_DIM, mask_dim = MASK_DIM;
	err = clSetKernelArg(kernel, 3, sizeof(unsigned), &in_dim);
	err = clSetKernelArg(kernel, 4, sizeof(unsigned), &mask_dim);
	check_cl_err(err, "failed to set kernel argument");

	size_t global_size[2] = { OUT_DIM, OUT_DIM };
	size_t local_size[2] = { 2, 2 };
	err = clEnqueueNDRangeKernel(queue, kernel, 2, NULL, global_size, local_size, 0,
		NULL, NULL);
	check_cl_err(err, "failed to enqueue ND range kernel");
	
	cl_uint* out = clEnqueueMapBuffer(queue, mem_objs[2], CL_TRUE, CL_MAP_READ, 0,
		sizeof(cl_uint) * OUT_DIM * OUT_DIM, 0, NULL, NULL, &err);
	check_cl_err(err, "failed to map result");

	printf("Result:\n");
	for (int i = 0; i < OUT_DIM; ++i){
		for (int j = 0; j < OUT_DIM; ++j){
			printf("%d ", out[i * OUT_DIM + j]);
		}
		printf("\n");
	}
	printf("\n");
	clEnqueueUnmapMemObject(queue, mem_objs[2], out, 0, 0, NULL);

	for (int i = 0; i < 3; ++i){
		clReleaseMemObject(mem_objs[i]);
	}
	clReleaseKernel(kernel);
	clReleaseProgram(program);
	clReleaseCommandQueue(queue);
	clReleaseContext(context);
	return 0;
}
示例#25
0
const char *get_jre_home(void)
{
	const char *result;
	int len;
	static struct string *jre;
	static int initialized;

	if (jre)
		return jre->buffer;

	if (initialized)
		return NULL;
	initialized = 1;

	/* ImageJ 1.x ships the JRE in <ij.dir>/jre/ */
	result = legacy_jre_path ? legacy_jre_path->buffer : ij_path("jre");
	if (dir_exists(result)) {
		struct string *libjvm = string_initf("%s/%s", result, default_library_path);
		if (!file_exists(libjvm->buffer)) {
			if (debug)
				error("Invalid jre/: '%s' does not exist!",
						libjvm->buffer);
		}
		else if (!is_native_library(libjvm->buffer)) {
			if (debug)
				error("Invalid jre/: '%s' is not a %s library!",
						libjvm->buffer, get_platform());
		}
		else {
			string_release(libjvm);
			jre = string_initf("%s", result);
			if (debug)
				error("JRE found in '%s'", jre->buffer);
			return jre->buffer;
		}
		string_release(libjvm);
	}
	else {
		if (debug)
			error("JRE not found in '%s'", result);
	}

	result = get_java_home();
	if (!result) {
		const char *jre_home = getenv("JRE_HOME");
		if (jre_home && *jre_home && is_jre_home(jre_home)) {
			jre = string_copy(jre_home);
			if (debug)
				error("Found a JRE in JRE_HOME: %s", jre->buffer);
			return jre->buffer;
		}
		jre_home = getenv("JAVA_HOME");
		if (jre_home && *jre_home && is_jre_home(jre_home)) {
			jre = string_copy(jre_home);
			if (debug)
				error("Found a JRE in JAVA_HOME: %s", jre->buffer);
			return jre->buffer;
		}
		if (debug)
			error("No JRE was found in default locations");
		return NULL;
	}

	len = strlen(result);
	if (len > 4 && !suffixcmp(result, len, "/jre")) {
		jre = string_copy(result);
		if (debug)
			error("JAVA_HOME points to a JRE: '%s'", result);
		return jre->buffer;
	}

	jre = string_initf("%s/jre", result);
	if (dir_exists(jre->buffer)) {
		if (debug)
			error("JAVA_HOME contains a JRE: '%s'", jre->buffer);
		return jre->buffer;
	}
	string_set(jre, result);
	if (debug)
		error("JAVA_HOME appears to be a JRE: '%s'", jre->buffer);
	return jre->buffer;
}
int main (void) {
  float *sum;
  cl_kernel kernel;
  cl_mem sum_buffer;
  cl_context context;
  cl_program program;
  cl_uint devices_num;
  char *program_source;
  cl_device_id device_id;
  cl_platform_id platform_id;
  cl_command_queue command_queue;

  sum = (float *) calloc (NUM_STEPS, sizeof (float));
  program_source = (char *) calloc (1000, sizeof (char));
  program_source = readKernel ();

  /* number of platforms on the system */
  platforms_number ();

  /* id of the first platform proposed by the system */
  platform_id = get_platform ();

  /* number of devices on the platform specified by platform_id */
  devices_num = devices_number (platform_id);

  /* id of the first device proposed by the system on the platform
     specified by platform_id */
  device_id = create_device (platform_id);

  /* create a context to stablish a communication channel between the
     host process and the device */
  context = create_context (device_id);

  /* create a program providing the source code */
  program = create_program (context, program_source);

  /* compile the program for the specific device architecture */
  build_program (program, device_id);\

  /* create a kernel given the program */
  kernel = create_kernel (program);

  /* create a memory object, in this case this will be float number
     that will contain the values of the partial sums */
  sum_buffer = create_buffer (context, "sum_buffer", NUM_STEPS);

  /* assign this buffer as the only kernel argument */
  set_kernel_argument (kernel, sum_buffer, 0, "sum_buffer");

  /* create a command queue, here we can enqueue tasks for the device
     specified by device_id */
  command_queue = create_command_queue (context, device_id);

  /* enqueue a task to execute the kernel on the device */
  enqueue_kernel_execution (command_queue, kernel, NUM_STEPS);

  /* copy the content of the buffer from the global memory of the
     device to the host memory */
  enqueue_read_buffer_task (command_queue, sum_buffer, NUM_STEPS, sum, "sum");

  printf (ANSI_COLOR_CYAN "\nAproximación de PI: %.10lf\n\n" ANSI_COLOR_RESET, sum[0] / NUM_STEPS);

  return 0;
}
示例#27
0
void
hippo_actions_join_chat_id(HippoActions    *actions,
                           const char      *chat_id)
{
    hippo_platform_show_chat_window(get_platform(actions), chat_id);
}
void Anvil::RenderingSurface::update_surface_extents() const
{
    const Anvil::DeviceType& device_type                   (m_device_ptr->get_type                             () );
    auto                     instance_ptr                  (m_create_info_ptr->get_instance_ptr                () );
    auto                     khr_surface_entrypoints       (instance_ptr->get_extension_khr_surface_entrypoints() );
    const Anvil::MGPUDevice* mgpu_device_ptr               (dynamic_cast<const Anvil::MGPUDevice*>             (m_device_ptr));
    uint32_t                 n_physical_devices            (0);
    const Anvil::SGPUDevice* sgpu_device_ptr               (dynamic_cast<const Anvil::SGPUDevice*>(m_device_ptr));
    auto                     window_ptr                    (m_create_info_ptr->get_window_ptr     () );

    if (window_ptr != nullptr)
    {
        const WindowPlatform window_platform(window_ptr->get_platform() );

        if (window_platform == WINDOW_PLATFORM_DUMMY                     ||
            window_platform == WINDOW_PLATFORM_DUMMY_WITH_PNG_SNAPSHOTS)
        {
            /* Nothing to update - off-screen rendering is active. */
            goto end;
        }
        else
        {
            /* In this case, width & height may change at run-time */
        }
    }
    else
    {
        /* In this case, width & height may change at run-time */
    }

    switch (device_type)
    {
        case Anvil::DeviceType::MULTI_GPU:  n_physical_devices = mgpu_device_ptr->get_n_physical_devices(); break;
        case Anvil::DeviceType::SINGLE_GPU: n_physical_devices = 1;                                         break;

        default:
        {
            anvil_assert_fail();
        }
    }

    /* Retrieve general properties */
    for (uint32_t n_physical_device = 0;
                  n_physical_device < n_physical_devices;
                ++n_physical_device)
    {
        const Anvil::PhysicalDevice* physical_device_ptr = nullptr;
        VkResult                     result_vk;
        Anvil::SurfaceCapabilities   surface_caps;

        ANVIL_REDUNDANT_VARIABLE_CONST(result_vk);

        switch (device_type)
        {
            case Anvil::DeviceType::MULTI_GPU:  physical_device_ptr = mgpu_device_ptr->get_physical_device(n_physical_device); break;
            case Anvil::DeviceType::SINGLE_GPU: physical_device_ptr = sgpu_device_ptr->get_physical_device();                  break;

            default:
            {
                anvil_assert_fail();
            }
        }

        if (m_surface == VK_NULL_HANDLE)
        {
            /* Nothing to update */
            goto end;
        }

        const VkPhysicalDevice physical_device_vk = physical_device_ptr->get_physical_device();

        result_vk = khr_surface_entrypoints.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device_vk,
                                                                                      m_surface,
                                                                                      reinterpret_cast<VkSurfaceCapabilitiesKHR*>(&surface_caps) );

        anvil_assert_vk_call_succeeded(result_vk);

        if (n_physical_device == 0)
        {
            m_height = surface_caps.current_extent.height;
            m_width  = surface_caps.current_extent.width;
        }
        else
        {
            anvil_assert(m_height == surface_caps.current_extent.height);
            anvil_assert(m_width  == surface_caps.current_extent.width);
        }
    }

end:
    ;
}
int main (void) {
  int *a;
  cl_mem a_in;
  cl_event event;
  cl_kernel kernel;
  cl_context context;
  cl_program program;
  cl_uint devices_num;
  char *program_source;
  cl_device_id device_id;
  cl_platform_id platform_id;
  cl_command_queue command_queue;

  program_source = (char *) calloc (1000, sizeof (char));
  program_source = readKernel ();

  /* number of platforms on the system */
  platforms_number ();

  /* id of the first platform proposed by the system */
  platform_id = get_platform ();

  /* number of devices on the platform specified by platform_id */
  devices_num = devices_number (platform_id);

  /* id of the first device proposed by the system on the platform
     specified by platform_id */
  device_id = create_device (platform_id);

  /* create a context to stablish a communication channel between the
     host process and the device */
  context = create_context (device_id);

  /* create a program providing the source code */
  program = create_program (context, program_source);

  /* compile the program for the specific device architecture */
  build_program (program, device_id);

  /* create a kernel given the program */
  kernel = create_kernel (program);

  /* create a memory object, in this case this will be an array of
     integers of length specified by the LENGTH macro */
  a = create_memory_object (LENGTH, "a");

  /* create a buffer, this will be allocated on the global memory of
     the device */
  a_in = create_buffer (LENGTH, context, "a_in");

  /* assign this buffer as the only kernel argument */
  set_kernel_argument (kernel, a_in, 0, "a_in");

  /* create a command queue, here we can enqueue tasks for the device
     specified by device_id */
  command_queue = create_command_queue (context, device_id);

  /* copy the memory object allocated on the host memory into the
     buffer created on the global memory of the device */
  enqueue_write_buffer_task (command_queue, a_in, LENGTH, a, "a_in");

  /* enqueue a task to execute the kernel on the device */
  event = enqueue_kernel_execution (command_queue, kernel, LENGTH, 0, NULL);
  enqueue_kernel_execution (command_queue, kernel, LENGTH, 1, &event);

  /* copy the content of the buffer from the global memory of the
     device to the host memory */
  enqueue_read_buffer_task (command_queue, a_in, LENGTH,  a, "a_in");

  /* print the memory object with the result of the execution */
  print_memory_object (a, LENGTH, "a");

  return 0;
}
/* Please see header for specification */
void Anvil::RenderingSurface::cache_surface_properties()
{
    const Anvil::DeviceType&             device_type                   (m_device_ptr->get_type() );
    bool                                 is_offscreen_rendering_enabled(true);
    auto                                 khr_surface_entrypoints       (m_create_info_ptr->get_instance_ptr()->get_extension_khr_surface_entrypoints() );
    const Anvil::MGPUDevice*             mgpu_device_ptr               (dynamic_cast<const Anvil::MGPUDevice*>(m_device_ptr));
    uint32_t                             n_physical_devices            (0);
    const Anvil::SGPUDevice*             sgpu_device_ptr               (dynamic_cast<const Anvil::SGPUDevice*>(m_device_ptr));
    std::vector<Anvil::SurfaceFormatKHR> supported_formats;
    auto                                 window_ptr                    (m_create_info_ptr->get_window_ptr() );

    if (window_ptr != nullptr)
    {
        const WindowPlatform window_platform(window_ptr->get_platform() );

        is_offscreen_rendering_enabled = (window_platform == WINDOW_PLATFORM_DUMMY                     ||
                                          window_platform == WINDOW_PLATFORM_DUMMY_WITH_PNG_SNAPSHOTS);

        if (is_offscreen_rendering_enabled)
        {
            m_height = window_ptr->get_height_at_creation_time();
            m_width  = window_ptr->get_width_at_creation_time ();
        }
        else
        {
            /* In this case, width & height may change at run-time */
        }
    }
    else
    {
        /* In this case, width & height may change at run-time */
    }

    switch (device_type)
    {
        case Anvil::DeviceType::MULTI_GPU:  n_physical_devices = mgpu_device_ptr->get_n_physical_devices(); break;
        case Anvil::DeviceType::SINGLE_GPU: n_physical_devices = 1;                                         break;

        default:
        {
            anvil_assert_fail();
        }
    }

    /* Retrieve general properties */
    uint32_t n_supported_formats           (0);
    uint32_t n_supported_presentation_modes(0);
    VkResult result                        (VK_ERROR_INITIALIZATION_FAILED);

    ANVIL_REDUNDANT_VARIABLE(result);

    for (uint32_t n_physical_device = 0;
                  n_physical_device < n_physical_devices;
                ++n_physical_device)
    {
        const Anvil::PhysicalDevice* physical_device_ptr = nullptr;

        switch (device_type)
        {
            case Anvil::DeviceType::MULTI_GPU:  physical_device_ptr = mgpu_device_ptr->get_physical_device(n_physical_device); break;
            case Anvil::DeviceType::SINGLE_GPU: physical_device_ptr = sgpu_device_ptr->get_physical_device();                  break;

            default:
            {
                anvil_assert_fail();
            }
        }

        auto& result_caps = m_physical_device_capabilities[physical_device_ptr->get_device_group_device_index()];

        if (m_surface == VK_NULL_HANDLE)
        {
            result_caps.supported_composite_alpha_flags = Anvil::CompositeAlphaFlagBits::INHERIT_BIT_KHR;
            result_caps.supported_transformations       = Anvil::SurfaceTransformFlagBits::INHERIT_BIT_KHR;
            result_caps.supported_usages                = static_cast<Anvil::ImageUsageFlags> (Anvil::ImageUsageFlagBits::COLOR_ATTACHMENT_BIT |
                                                                                               Anvil::ImageUsageFlagBits::TRANSFER_SRC_BIT     |
                                                                                               Anvil::ImageUsageFlagBits::TRANSFER_DST_BIT     |
                                                                                               Anvil::ImageUsageFlagBits::STORAGE_BIT);

            result_caps.supported_presentation_modes.push_back(Anvil::PresentModeKHR::IMMEDIATE_KHR);

            continue;
        }

        const VkPhysicalDevice physical_device_vk = physical_device_ptr->get_physical_device();

        result = khr_surface_entrypoints.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device_vk,
                                                                                   m_surface,
                                                                                   reinterpret_cast<VkSurfaceCapabilitiesKHR*>(&result_caps.capabilities) );

        anvil_assert_vk_call_succeeded(result);

        if (n_physical_device == 0)
        {
            m_height = result_caps.capabilities.current_extent.height;
            m_width  = result_caps.capabilities.current_extent.width;
        }
        else
        {
            anvil_assert(m_height == result_caps.capabilities.current_extent.height);
            anvil_assert(m_width  == result_caps.capabilities.current_extent.width);
        }

        result_caps.supported_composite_alpha_flags = result_caps.capabilities.supported_composite_alpha;
        result_caps.supported_transformations       = result_caps.capabilities.supported_transforms;
        result_caps.supported_usages                = result_caps.capabilities.supported_usage_flags;

        /* Retrieve a list of formats supported by the surface */
        result = khr_surface_entrypoints.vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device_vk,
                                                                              m_surface,
                                                                             &n_supported_formats,
                                                                              nullptr /* pSurfaceFormats */);

        anvil_assert                  (n_supported_formats >  0);
        anvil_assert_vk_call_succeeded(result);

        supported_formats.resize(n_supported_formats);

        result = khr_surface_entrypoints.vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device_vk,
                                                                              m_surface,
                                                                             &n_supported_formats,
                                                                              reinterpret_cast<VkSurfaceFormatKHR*>(&supported_formats.at(0) ));
        anvil_assert_vk_call_succeeded(result);

        for (unsigned int n_format = 0;
                          n_format < n_supported_formats;
                        ++n_format)
        {
            result_caps.supported_formats.push_back(RenderingSurfaceFormat(supported_formats[n_format]) );
        }

        /* Retrieve a list of supported presentation modes
         *
         * NOTE: In case of mGPU devices, n_supported_presentation_modes may actually be 0 here for slave devices.
         */
        result = khr_surface_entrypoints.vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device_vk,
                                                                                   m_surface,
                                                                                  &n_supported_presentation_modes,
                                                                                   nullptr /* pPresentModes */);

        anvil_assert_vk_call_succeeded(result);

        if (n_supported_presentation_modes > 0)
        {
            std::vector<VkPresentModeKHR> temp_storage(n_supported_presentation_modes);

            result_caps.supported_presentation_modes.resize(n_supported_presentation_modes);

            result = khr_surface_entrypoints.vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device_vk,
                                                                                       m_surface,
                                                                                      &n_supported_presentation_modes,
                                                                                      &temp_storage.at(0) );
            anvil_assert_vk_call_succeeded(result);

            for (uint32_t n_presentation_mode = 0;
                          n_presentation_mode < static_cast<uint32_t>(temp_storage.size() );
                        ++n_presentation_mode)
            {
                result_caps.supported_presentation_modes.at(n_presentation_mode) = static_cast<Anvil::PresentModeKHR>(temp_storage.at(n_presentation_mode) );
            }
        }
    }
}