void get_results(
         const string &num,
         int start,
         const string &current,
         vector<string> &result,
         int target,
         int64_t val,
         int64_t last) {
     if (start >= num.length()) {
         if (!current.empty() && val == target) {
             result.push_back(current);
         }
         return;
     }
     string current_num_s = string(1, num[start]);
     for (int i=start+1; i<=num.length(); ++i) {
         if (current_num_s.length() > 1 && current_num_s[0] == '0') {
             return;
         }
         auto current_num = stoll(current_num_s);
         if (current.empty()) {
             get_results(num, i, current_num_s, result, target, current_num, current_num);
         } else {
             get_results(num, i, current + "+" + current_num_s, result, target, val + current_num, current_num);
             get_results(num, i, current + "-" + current_num_s, result, target, val - current_num, -current_num);
             get_results(num, i, current + "*" + current_num_s, result, target, val - last + last * current_num, last * current_num);
         }
         if (i != num.length()) {
             current_num_s.push_back(num[i]);
         }
     }
 }
Esempio n. 2
0
int main(int argc, char **argv){
	int dhcp_socket;
	int result;

	if(process_arguments(argc,argv)!=OK){
		/*usage("Invalid command arguments supplied\n");*/
		printf("Invalid command arguments supplied\n");
		exit(STATE_UNKNOWN);
	        }


	/* create socket for DHCP communications */
	dhcp_socket=create_dhcp_socket();

	/* get hardware address of client machine */
	get_hardware_address(dhcp_socket,network_interface_name);

	/* send DHCPDISCOVER packet */
	send_dhcp_discover(dhcp_socket);

	/* wait for a DHCPOFFER packet */
	get_dhcp_offer(dhcp_socket);

	/* close socket we created */
	close_dhcp_socket(dhcp_socket);

	/* determine state/plugin output to return */
	result=get_results();

	/* free allocated memory */
	free_dhcp_offer_list();
	free_requested_server_list();

	return result;
        }
Esempio n. 3
0
        bool mysql_stmt_resultset::next()
        {
            if (stmt_ == NULL)
                return false;

            if (status_ == -1)
            {
                get_results();

                if (status_ == -1)
                    return false;
            }

            int res = mysql_stmt_fetch(stmt_);

            if (res == 1 || res == MYSQL_DATA_TRUNCATED)
                throw database_exception(last_stmt_error(stmt_));

            if (res == MYSQL_NO_DATA)
            {
                return false;
            }

            return true;

        }
int check_village(struct Village *top)
{
	struct Results result = get_results(top);
	int answer = 1;

	if (res_population != result.total_patients) answer = 2;
	if (res_hospitals != result.hosps_number) answer = 2;
	if (res_personnel != result.hosps_personnel) answer = 2;
	if (res_checkin != result.total_hosps_v) answer = 2;
	if (res_village != result.total_in_village) answer = 2;
	if (res_waiting != result.total_waiting) answer = 2;
	if (res_assess != result.total_assess) answer = 2;
	if (res_inside != result.total_inside) answer = 2;

	printf("\n");
	printf("Sim. Variables      = expect / result\n");
	printf("Total population    = %6d / %6d people\n", (int)   res_population, (int) result.total_patients);
	printf("Hospitals           = %6d / %6d people\n", (int)   res_hospitals, (int) result.hosps_number);
	printf("Personnel           = %6d / %6d people\n", (int)   res_personnel, (int) result.hosps_personnel);
	printf("Check-in's          = %6d / %6d people\n", (int)   res_checkin, (int) result.total_hosps_v);
	printf("In Villages         = %6d / %6d people\n", (int)   res_village, (int) result.total_in_village);
	printf("In Waiting List     = %6d / %6d people\n", (int)   res_waiting, (int) result.total_waiting);
	printf("In Assess           = %6d / %6d people\n", (int)   res_assess, (int) result.total_assess);
	printf("Inside Hospital     = %6d / %6d people\n", (int)   res_inside, (int) result.total_inside);
	printf("Average Stay        = %6f / %6f u/time\n", (float) res_avg_stay,(float) result.total_time/result.total_patients);

	if( answer == 1 ) printf( "RESULT_SUCCESSFUL!\n" );
	else {
		//my_print(top);
		printf( "RESULT_UNSUCCESSFUL!\n" );
	}


	return 0;
}
Esempio n. 5
0
STDLL stata_call(int argc, char *argv[])
{
	int get_results(void) ;	
	int load_data(void) ;	
	int write_data(void) ;	
	ST_retcode rc = 0;
	
	// Must specify an argument to plugin
	if (argc) {
		// Check number of arguments passed to plugin	
		if (argc > 1) {
			SF_error("too many options specified \n") ;
			return((ST_retcode) 198) ;
		}
		
		
	} else {
		SF_error("must specify the load, create, or write options \n") ;
		return((ST_retcode) 198) ;
	}

	//Option create was specified	
	if (argc == 1 && strcmp(argv[0], "create") == 0) {
		// Query database and get the data types for each variable
		rc = get_results() ;	
		if (rc) {
			mysql_free_result(res) ; 
			mysql_close(&mysql) ;
			return((ST_retcode) rc) ;
		}
	}
	//Option load was specified	
	else if (argc == 1 && strcmp(argv[0], "load") == 0) {
		// load the data from the  database
		rc = load_data() ;
		if (rc) {
			mysql_free_result(res) ; 
			mysql_close(&mysql) ;
			return((ST_retcode) rc) ;
		}
	}
	//Option write was specified	
	else if (argc == 1 && strcmp(argv[0], "write") == 0) {
		// Write data to database
		rc = write_data() ;
		if (rc) {
			return((ST_retcode) rc) ;
		}
	}
	else {
		// Invalid option 
		SF_error("option not allowed \n") ;
		return((ST_retcode) 198) ;
	}
	
	return 0;
}
Esempio n. 6
0
bool EM::purge_low_percent_expressed_transcripts(float min_percent_expressed) {
    
    double sum_fpkm = 0;
    
    vector<t_EM_result> em_results = get_results();
    
    // compute sum_fpkm
    for (vector<t_EM_result>::iterator it = em_results.begin(); it != em_results.end(); it++) {
        
        t_EM_result result = *it;
        double fpkm = result.FPKM;
        sum_fpkm += fpkm;
    }

    // identify and weed out lowly expressed transcripts
    vector<string> transcripts_to_delete;
    for (vector<t_EM_result>::iterator it = em_results.begin(); it != em_results.end(); it++) {
        
        t_EM_result result = *it;
        double fpkm = result.FPKM;
        
        double percent_expressed = fpkm/sum_fpkm * 100;

        if (percent_expressed < min_percent_expressed) {
            transcripts_to_delete.push_back(result.trans_id);
        
            cerr << "-purging transcript: " << result.trans_id << " as too lowly expressed: " << percent_expressed << "%" << endl;
        }
        
    }
    
    if(! transcripts_to_delete.empty()) {
        for (vector<string>::iterator it = transcripts_to_delete.begin();
             it != transcripts_to_delete.end();
             it++) {
            
            string transcript = *it;
            
            _trans_to_multi_map_counts.erase(transcript);
            _ENt[transcript] = 0;
            _theta[transcript] = 0;
        }
        
        // reset theta values:
        _M_step();
        
        return(true);
    }
    else {
        return(false); // no transcripts to delete
    }
        
}
Esempio n. 7
0
void do_arrays(const Config &config)
{
    const Frustum f = Frustum_Perspective(75.0f, 1.333f, 0.5f, 100.0f);
    Data data;

    data = generate_data(Structured, config);
    measure([&]{ naive_cull(data.results, data.spheres, f); }, 50, 10, "Naive culling / structured data", config);
    print_results(get_results(data), config);

    data = generate_data(Random, config);
    measure([&]{ naive_cull(data.results, data.spheres, f); }, 50, 10, "Naive culling / random data", config);
    print_results(get_results(data), config);

    data = generate_data(Structured, config);
    measure([&]{ sse_cull(data.results, data.spheres, f); }, 50, 10, "SSE culling / structured data", config);
    print_results(get_results(data), config);

    data = generate_data(Random, config);
    measure([&]{ sse_cull(data.results, data.spheres, f); }, 50, 10, "SSE culling / random data", config);
    print_results(get_results(data), config);
}
Esempio n. 8
0
static int cmd_dyno_graph(UNUSED(int argc), UNUSED(char **argv)) {
	get_results();

	/* Check data */
	if (dyno_nb_results <= 0) {
		printf("Dyno run has not been done, please do a run first\n");
		return CMD_OK;
	}

	display_graphs(dyno_results, dyno_nb_results);
	return CMD_OK;
}
Esempio n. 9
0
int main(int argc, char* argv[])
{
	int  ch, conn_timeout = 10, rw_timeout = 10;
	acl::string addr("127.0.0.1:6379");
	bool slice_req = false;

	while ((ch = getopt(argc, argv, "hs:C:I:S")) > 0)
	{
		switch (ch)
		{
		case 'h':
			usage(argv[0]);
			return 0;
		case 's':
			addr = optarg;
			break;
		case 'C':
			conn_timeout = atoi(optarg);
			break;
		case 'I':
			rw_timeout = atoi(optarg);
			break;
		case 'S':
			slice_req = true;
			break;
		default:
			break;
		}
	}

	acl::acl_cpp_init();
	acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);
	client.set_slice_request(slice_req);
	client.set_slice_respond(false);
	acl::redis_transaction redis(&client);

	bool ret;

	ret = test_multi(redis) && test_run_cmds(redis)
		&& test_exec(redis) && get_results(redis);

	printf("all cmds %s\r\n", ret ? "ok" : "failed");

#ifdef WIN32
	printf("enter any key to exit\r\n");
	getchar();
#endif
	return 0;
}
Esempio n. 10
0
int main(int argc, char **argv){
	int dhcp_socket;
	int result = STATE_UNKNOWN;

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	/* Parse extra opts if any */
	argv=np_extra_opts(&argc, argv, progname);

	if(process_arguments(argc,argv)!=OK){
		usage4 (_("Could not parse arguments"));
		}

	/* this plugin almost certainly needs root permissions. */
	np_warn_if_not_root();

	/* create socket for DHCP communications */
	dhcp_socket=create_dhcp_socket();

	/* get hardware address of client machine */
	if(user_specified_mac!=NULL)
		memcpy(client_hardware_address,user_specified_mac,6);
	else
		get_hardware_address(dhcp_socket,network_interface_name);

	if(unicast) /* get IP address of client machine */
		get_ip_address(dhcp_socket,network_interface_name);

	/* send DHCPDISCOVER packet */
	send_dhcp_discover(dhcp_socket);

	/* wait for a DHCPOFFER packet */
	get_dhcp_offer(dhcp_socket);

	/* close socket we created */
	close_dhcp_socket(dhcp_socket);

	/* determine state/plugin output to return */
	result=get_results();

	/* free allocated memory */
	free_dhcp_offer_list();
	free_requested_server_list();

	return result;
        }
Esempio n. 11
0
bool tcKernel::set_output_array(const char *ssc_output_name, const char *tcs_output_name, size_t len, double scaling)
{
	int idx=0;
	ssc_number_t *output_array = allocate( ssc_output_name, len );
	while( tcKernel::dataset *d = get_results(idx++) )
	{
		if ( (d->type == TCS_NUMBER) && (d->name == tcs_output_name) && (d->values.size() == len ) )
		{
			for (size_t i=0;i<len;i++)
				output_array[i] = (ssc_number_t)(d->values[i].dval * scaling);
			return true;
		}
	}

	return false;
}
Esempio n. 12
0
/*
 * Save dyno measures and results to a file
 */
static int cmd_dyno_save(int argc, char **argv) {
	char *filename;
	int rv;

	get_results();

	/* Check data */
	if (dyno_nb_results <= 0) {
		printf("Dyno run has not been done, please do a run first\n");
		return CMD_OK;
	}


	if (argc > 1) {
		/* Get filename from command arguments */
		size_t length = strlen(argv[1]);
		rv = diag_malloc(&filename, length + 1);
		if (rv != 0) {
			return rv;
		}
		strcpy(filename, argv[1]);
	} else {
		/* Get filename from user input */
		size_t nbytes = 256;
		rv = diag_malloc(&filename, nbytes + 1);
		if (rv != 0) {
			return rv;
		}

		printf("Enter filename: ");
		if (fgets(filename, (int)nbytes, stdin) == 0) {
			return CMD_OK;
		}

		/* Remove pending "\n" and "\r", if any */
		while ((filename[strlen(filename)-1] == '\n') ||
					 (filename[strlen(filename)-1] == '\r')) {
			filename[strlen(filename)-1] = '\0';
		}
	}

	dyno_save(filename, dyno_results, dyno_nb_results);
	printf("\n");

	free(filename);
	return CMD_OK;
}
Esempio n. 13
0
bool tcKernel::set_all_output_arrays()
{
	int idx=0;
	while( tcKernel::dataset *d = get_results(idx++) )
	{	// if the TCS value is a TCS_NUMBER (so that we can put the value into a one-dimensional array - single value for 8760 hours)
		// and
		// if there is an SSC_OUTPUT with the same name
		if ( (d->type == TCS_NUMBER) && ( is_ssc_array_output(d->name) ) )
		{
			ssc_number_t *output_array = allocate( d->name, d->values.size() );
			for (size_t i=0; i<d->values.size(); i++)
				output_array[i] = (ssc_number_t) d->values[i].dval;
		}
	}

	return true;
}
Esempio n. 14
0
void loopback_run(struct loopback_test *t)
{
	int i;
	int ret;

	for (i = 0; dict[i].name != NULL; i++) {
		if (strstr(dict[i].name, t->test_name))
			t->test_id = dict[i].type;
	}
	if (!t->test_id) {
		fprintf(stderr, "invalid test %s\n", t->test_name);
		usage();
		return;
	}

	prepare_devices(t);

	ret = open_poll_files(t);
	if (ret)
		goto err;

	start(t);

	ret = wait_for_complete(t);
	close_poll_files(t);
	if (ret)
		goto err;


	get_results(t);

	log_results(t);

	return;

err:
	printf("Error running test\n");
	return;
}
Esempio n. 15
0
void loopback_run(struct loopback_test *t)
{
	int i;
	int ret;

	for (i = 0; dict[i].name != NULL; i++) {
		if (strstr(dict[i].name, t->test_name))
			t->test_id = dict[i].type;
	}
	if (!t->test_id) {
		fprintf(stderr, "invalid test %s\n", t->test_name);
		usage();
		return;
	}

	prepare_devices(t);

	ret = register_for_notification(t);
	if (ret)
		goto err;

	start(t);

	sleep(1);

	wait_for_complete(t);

	unregister_for_notification(t);

	get_results(t);

	log_results(t);

	return;

err:
	printf("Error running test\n");
	return;
}
Esempio n. 16
0
vector<t_EM_result>  EM::get_and_report_results () {
    
    vector<t_EM_result> results = get_results();
    
    
    cout << "#Total reads mapped: " << get_total_mapped_read_count() << endl;
    cout << "#Total transcripts examined: " << get_num_transcripts() << endl;
    cout << "#transcript\t" << "trans_length\t" << "unique_map\t" << "multi_map\t" << "Theta\t" << "EM_frag_count\t" << "FPKM" << endl;
    
    for(vector<t_EM_result>::iterator it = results.begin(); it != results.end(); it++) {
        
        t_EM_result result = *it;
        
        cout << result.trans_id << "\t"
             << result.length << "\t"
             << result.unique_map << "\t"
             << result.multi_map << "\t"
             << result.theta << "\t"
             << result.expected_map << "\t"
             << result.FPKM << endl;
    }

    return (results);
}
struct Results get_results(struct Village *village)
{
	struct Village *vlist;
	struct Patient *p;
	struct Results t_res, p_res;

	t_res.hosps_number     = 0.0;
	t_res.hosps_personnel  = 0.0;
	t_res.total_patients   = 0.0;
	t_res.total_in_village = 0.0;
	t_res.total_waiting    = 0.0;
	t_res.total_assess     = 0.0;
	t_res.total_inside     = 0.0;
	t_res.total_hosps_v    = 0.0;
	t_res.total_time       = 0.0;

	if (village == NULL) return t_res;

	/* Traverse village hierarchy (lower level first)*/
	vlist = village->forward;
	while(vlist)
	{
		p_res = get_results(vlist);
		t_res.hosps_number     += p_res.hosps_number;
		t_res.hosps_personnel  += p_res.hosps_personnel;
		t_res.total_patients   += p_res.total_patients;
		t_res.total_in_village += p_res.total_in_village;
		t_res.total_waiting    += p_res.total_waiting;
		t_res.total_assess     += p_res.total_assess;
		t_res.total_inside     += p_res.total_inside;
		t_res.total_hosps_v    += p_res.total_hosps_v;
		t_res.total_time       += p_res.total_time;
		vlist = vlist->next;
	}
	t_res.hosps_number     += 1.0;
	t_res.hosps_personnel  += village->hosp.personnel;

	// Patients in the village
	p = village->population;
	while (p != NULL) 
	{
		t_res.total_patients   += 1.0;
		t_res.total_in_village += 1.0;
		t_res.total_hosps_v    += (float)(p->hosps_visited);
		t_res.total_time       += (float)(p->time); 
		p = p->forward; 
	}
	// Patients in hospital: waiting
	p = village->hosp.waiting;
	while (p != NULL) 
	{
		t_res.total_patients += 1.0;
		t_res.total_waiting  += 1.0;
		t_res.total_hosps_v  += (float)(p->hosps_visited);
		t_res.total_time     += (float)(p->time); 
		p = p->forward; 
	}
	// Patients in hospital: assess
	p = village->hosp.assess;
	while (p != NULL) 
	{
		t_res.total_patients += 1.0;
		t_res.total_assess   += 1.0;
		t_res.total_hosps_v  += (float)(p->hosps_visited);
		t_res.total_time     += (float)(p->time); 
		p = p->forward; 
	}
	// Patients in hospital: inside
	p = village->hosp.inside;
	while (p != NULL) 
	{
		t_res.total_patients += 1.0;
		t_res.total_inside   += 1.0;
		t_res.total_hosps_v  += (float)(p->hosps_visited);
		t_res.total_time     += (float)(p->time); 
		p = p->forward; 
	}  

	return t_res; 
}
Esempio n. 18
0
struct mpi_queue_task *mpi_queue_wait(struct mpi_queue *q, int timeout)
{
	struct mpi_queue_task *t;
	time_t stoptime;
	int result;

	if(timeout == MPI_QUEUE_WAITFORTASK) {
		stoptime = 0;
	} else {
		stoptime = time(0) + timeout;
	}


	while(1) {
		// If a task is already complete, return it
		t = list_pop_head(q->complete_list);
		if(t)
			return t;

		if(list_size(q->ready_list) == 0 && itable_size(q->active_list) == 0)
			break;

		// Wait no longer than the caller's patience.
		int msec;
		int sec;
		if(stoptime) {
			sec = MAX(0, stoptime - time(0));
			msec = sec * 1000;
		} else {
			sec = 5;
			msec = 5000;
		}

		if(!q->mpi_link) {
			q->mpi_link = link_accept(q->master_link, stoptime);
			if(q->mpi_link) {
				char working_dir[MPI_QUEUE_LINE_MAX];
				link_tune(q->mpi_link, LINK_TUNE_INTERACTIVE);
				link_usleep(q->mpi_link, msec, 0, 1);
				getcwd(working_dir, MPI_QUEUE_LINE_MAX);
				link_putfstring(q->mpi_link, "workdir %s\n", stoptime, working_dir);
				result = link_usleep(q->mpi_link, msec, 1, 1);
			} else {
				result = 0;
			}
		} else {
			debug(D_MPI, "Waiting for link to be ready\n");
			result = link_usleep(q->mpi_link, msec, 1, 1);
		}

		// If nothing was awake, restart the loop or return without a task.
		if(result <= 0) {
			if(stoptime && time(0) >= stoptime) {
				return 0;
			} else {
				continue;
			}
		}

		debug(D_MPI, "sending %d tasks to the MPI master process\n", list_size(q->ready_list));
		// Send all ready tasks to the MPI master process
		while(list_size(q->ready_list)) {
			struct mpi_queue_task *t = list_pop_head(q->ready_list);
			result = dispatch_task(q->mpi_link, t, msec/1000);
			if(result <= 0)
				return 0;
			itable_insert(q->active_list, t->taskid, t);
		}

		// Receive any results back
		result = get_results(q->mpi_link, q->active_list, q->complete_list, msec/1000);
		if(result < 0) {
			return 0;
		}
	}

	return 0;
}
Esempio n. 19
0
int
main(int argc, char **argv)
{
	RETCODE rc;
	const int rows_to_add = 50;
	LOGINREC *login;
	DBPROCESS *dbproc;
	int i;

	set_malloc_options();

	read_login_info(argc, argv);
	fprintf(stdout, "Starting %s\n", argv[0]);

	/* Fortify_EnterScope(); */
	dbinit();

	dberrhandle(syb_err_handler);
	dbmsghandle(syb_msg_handler);

	fprintf(stdout, "About to logon\n");

	login = dblogin();
	DBSETLPWD(login, PASSWORD);
	DBSETLUSER(login, USER);
	DBSETLAPP(login, "t0006");
	DBSETLHOST(login, "ntbox.dntis.ro");

	fprintf(stdout, "About to open\n");

	dbproc = dbopen(login, SERVER);
	if (strlen(DATABASE))
		dbuse(dbproc, DATABASE);
	dbloginfree(login);

#ifdef MICROSOFT_DBLIB
	dbsetopt(dbproc, DBBUFFER, "5000");
#else
	dbsetopt(dbproc, DBBUFFER, "5000", 0);
#endif

	fprintf(stdout, "creating table\n");
	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}

	fprintf(stdout, "insert\n");
	for (i = 1; i < rows_to_add; i++) {
		sql_cmd(dbproc);
		dbsqlexec(dbproc);
		while (dbresults(dbproc) != NO_MORE_RESULTS) {
			/* nop */
		}
	}

	fprintf(stdout, "first select\n");
	if (SUCCEED != sql_cmd(dbproc)) {
		fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__);
		failed = 1;
	}
	if (SUCCEED != dbsqlexec(dbproc)) {
		fprintf(stderr, "%s:%d: dbsqlexec failed\n", __FILE__, __LINE__);
		failed = 1;
	}


	if (dbresults(dbproc) != SUCCEED) {
		fprintf(stdout, "%s:%d: Was expecting a result set.", __FILE__, __LINE__);
		failed = 1;
		exit(1);
	}

	for (i = 1; i <= dbnumcols(dbproc); i++)
		printf("col %d is %s\n", i, dbcolname(dbproc, i));

	dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
	dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);

	get_results(dbproc, 1);

	testint = -1;
	strcpy(teststr, "bogus");
	fprintf(stdout, "second select\n");
	sql_cmd(dbproc);
	dbsqlexec(dbproc);

	if ((rc = dbresults(dbproc)) != SUCCEED) {
		fprintf(stdout, "%s:%d: Was expecting a result set. (rc=%d)\n", __FILE__, __LINE__, rc);
		failed = 1;
	}

	if (!failed) {
		dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
		dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);

		get_results(dbproc, 25);
	}
	dbexit();

	fprintf(stdout, "%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
	return failed ? 1 : 0;
}
Esempio n. 20
0
int zd_usb_ioread16v(struct zd_usb *usb, u16 *values,
                     const zd_addr_t *addresses, unsigned int count)
{
    int r;
    int i, req_len, actual_req_len;
    struct usb_device *udev;
    struct usb_req_read_regs *req = NULL;
    unsigned long timeout;

    if (count < 1) {
        dev_dbg_f(zd_usb_dev(usb), "error: count is zero\n");
        return -EINVAL;
    }
    if (count > USB_MAX_IOREAD16_COUNT) {
        dev_dbg_f(zd_usb_dev(usb),
                  "error: count %u exceeds possible max %u\n",
                  count, USB_MAX_IOREAD16_COUNT);
        return -EINVAL;
    }
    if (in_atomic()) {
        dev_dbg_f(zd_usb_dev(usb),
                  "error: io in atomic context not supported\n");
        return -EWOULDBLOCK;
    }
    if (!usb_int_enabled(usb)) {
        dev_dbg_f(zd_usb_dev(usb),
                  "error: usb interrupt not enabled\n");
        return -EWOULDBLOCK;
    }

    req_len = sizeof(struct usb_req_read_regs) + count * sizeof(__le16);
    req = kmalloc(req_len, GFP_KERNEL);
    if (!req)
        return -ENOMEM;
    req->id = cpu_to_le16(USB_REQ_READ_REGS);
    for (i = 0; i < count; i++)
        req->addr[i] = cpu_to_le16((u16)addresses[i]);

    udev = zd_usb_to_usbdev(usb);
    prepare_read_regs_int(usb);
    r = usb_bulk_msg(udev, usb_sndbulkpipe(udev, EP_REGS_OUT),
                     req, req_len, &actual_req_len, 1000 /* ms */);
    if (r) {
        dev_dbg_f(zd_usb_dev(usb),
                  "error in usb_bulk_msg(). Error number %d\n", r);
        goto error;
    }
    if (req_len != actual_req_len) {
        dev_dbg_f(zd_usb_dev(usb), "error in usb_bulk_msg()\n"
                  " req_len %d != actual_req_len %d\n",
                  req_len, actual_req_len);
        r = -EIO;
        goto error;
    }

    timeout = wait_for_completion_timeout(&usb->intr.read_regs.completion,
                                          msecs_to_jiffies(1000));
    if (!timeout) {
        disable_read_regs_int(usb);
        dev_dbg_f(zd_usb_dev(usb), "read timed out\n");
        r = -ETIMEDOUT;
        goto error;
    }

    r = get_results(usb, values, req, count);
error:
    kfree(req);
    return r;
}
Esempio n. 21
0
static int
process_packet(val_context_t *context)
{
    HEADER         *query_header, *response_header;
    u_char         *pos;
    int             q_name_len, rc;
    u_int16_t       type_h, class_h;

    struct sockaddr from;
    socklen_t       from_len;

    u_char          query[4096], response[4096];
    int             query_size, response_size;

    /*
     * get a packet
     */
    from_len = sizeof(from);
    memset(&from, 0x0, sizeof(from));
    do {
        rc = recvfrom(listen_fd, query, sizeof(query), 0, &from,
                      &from_len);
        if (rc < 0 && errno != EINTR) {
            // xxx-rks: log err msg
            break;
        }
    } while (rc < 0);
    if (rc < 0)
        return rc;

    query_size = rc;
    if (query_size < (sizeof(HEADER) + 1))
        return -1;

    query_header = (HEADER *) query;

    /*
     * get query name
     */
    pos = &query[sizeof(HEADER)];
    q_name_len = wire_name_length(pos);
    pos += q_name_len;

    /*
     * get class and type
     */
    VAL_GET16(type_h, pos);
    VAL_GET16(class_h, pos);

    response_size = sizeof(response);
    
    get_results(context, "test", (char *)&query[sizeof(HEADER)], (int)class_h,
                (int)type_h, response, &response_size, 0);

    /*
     * check to see if we need a dummy response
     */
    val_log(NULL, LOG_DEBUG, "XXX-RKS: handle no response");
    if (0 == response_size) {
        // no response; generate dummy/nxdomain response?
        return 1;
    }

    response_header = (HEADER*)response;
    response_header->id = query_header->id;

    /*
     * send response
     */
    do {
        rc = sendto(listen_fd, response, response_size, 0, &from,
                    sizeof(from));
        if (rc < 0 && errno != EINTR) {
            // xxx-rks: log err msg
            break;
        }
    } while (rc < 0);
    if (rc > 0) {
        val_log(NULL, LOG_DEBUG, "sent %d bytes", rc);
    }

    return 0;                   /* no error */
}
static gboolean
step_process_multiple (FilesCtx *ctx,
                       const gchar **orig_uris,
                       GError **err)
{
    SeahorseWidget *swidget;
    gboolean done = FALSE;
    FileInfo *pkg_info = NULL;
    gchar *package = NULL;
    gchar *ext;
    GFile *file, *parent;
    gboolean ok = FALSE;
    GtkWidget *dlg;
    guint nfolders, nfiles;
    gchar *uris[2];
    gchar *uri;
    GList *l;

    g_assert (err && !*err);

    for (l = ctx->finfos, nfolders = nfiles = 0; l; l = g_list_next (l)) {
        FileInfo *finfo = (FileInfo*)l->data;
        if (g_file_info_get_file_type (finfo->info) == G_FILE_TYPE_DIRECTORY)
            ++nfolders;
        else
            ++nfiles;
    }

    /* In the case of one or less files, no dialog */
    if(nfolders == 0 && nfiles <= 1)
        return TRUE;

    /* The package extension */
    if ((ext = g_settings_get_string (seahorse_tool_settings, "package-extension")) == NULL)
        ext = g_strdup (".zip"); /* Yes this happens when the schema isn't installed */

    /* Figure out a good URI for our package */
    for (l = ctx->finfos; l; l = g_list_next (l)) {
        if (l->data) {
            pkg_info = (FileInfo*)(l->data);
            break;
        }
    }

    /* This sets up but doesn't run the dialog */
    swidget = prepare_dialog (ctx, nfolders, nfiles, pkg_info->info, ext);

    g_free (ext);

    dlg = seahorse_widget_get_toplevel (swidget);

    /* Inhibit popping up of progress dialog */
    seahorse_tool_progress_block (TRUE);

    while (!done) {
        switch (gtk_dialog_run (GTK_DIALOG (dlg)))
        {
        case GTK_RESPONSE_HELP:
            /* TODO: Implement help */
            break;

        case GTK_RESPONSE_OK:
            package = get_results (swidget);
            ok = TRUE;
            /* Fall through */

        default:
            done = TRUE;
            break;
        }
    }

    /* Let progress dialog pop up */
    seahorse_tool_progress_block (FALSE);

    seahorse_widget_destroy (swidget);

    /* Cancelled */
    if (!ok)
        return FALSE;

    /* No package was selected? */
    if (!package)
        return TRUE;

    /* A package was selected */

    /* Make a new path based on the first uri */
    parent = g_file_get_parent (pkg_info->file);
    if (!parent)
    	parent = pkg_info->file;
    file = g_file_get_child_for_display_name (parent, package, err);
    if (!file)
	    return FALSE;

    uri = g_file_get_uri (file);
    g_return_val_if_fail (uri, FALSE);
    g_object_unref (file);

    if (!seahorse_util_uris_package (uri, orig_uris)) {
        g_free (uri);
        return FALSE;
    }

    /* Free all file info */
    g_list_foreach (ctx->finfos, (GFunc)free_file_info, NULL);
    g_list_free (ctx->finfos);
    ctx->finfos = NULL;

    /* Reload up the new file, as what to encrypt */
    uris[0] = uri;
    uris[1] = NULL;
    ok = step_check_uris (ctx, (const gchar**)uris, err);
    g_free (uri);

    return ok;
}
Esempio n. 23
0
iter_t
benchmp_interval(void* _state)
{
	char		c;
	iter_t		iterations;
	double		result;
	fd_set		fds;
	struct timeval	timeout;
	benchmp_child_state* state = (benchmp_child_state*)_state;

	iterations = (state->state == timing_interval ? state->iterations : state->iterations_batch);

	if (state->need_warmup) {
		/* remove spurious compilation warning */
		result = state->enough;
	} else {
		result = stop(0,0);
		if (state->cleanup) {
			if (benchmp_sigchld_handler == SIG_DFL)
				signal(SIGCHLD, SIG_DFL);
			(*state->cleanup)(iterations, state->cookie);
		}
		save_n(state->iterations);
		result -= t_overhead() + get_n() * l_overhead();
		settime(result >= 0. ? (uint64)result : 0.);
	}

	/* if the parent died, then give up */
	if (getppid() == 1 && state->cleanup) {
		if (benchmp_sigchld_handler == SIG_DFL)
			signal(SIGCHLD, SIG_DFL);
		(*state->cleanup)(0, state->cookie);
		exit(0);
	}

	timeout.tv_sec = 0;
	timeout.tv_usec = 0;
	FD_ZERO(&fds);

	switch (state->state) {
	case warmup:
		iterations = state->iterations_batch;
		FD_SET(state->start_signal, &fds);
		select(state->start_signal+1, &fds, NULL,
		       NULL, &timeout);
		if (FD_ISSET(state->start_signal, &fds)) {
			state->state = timing_interval;
			read(state->start_signal, &c, sizeof(char));
			iterations = state->iterations;
		}
		if (state->need_warmup) {
			state->need_warmup = 0;
			/* send 'ready' */
			write(state->response, &c, sizeof(char));
		}
		break;
	case timing_interval:
		iterations = state->iterations;
		if (state->parallel > 1 || result > 0.95 * state->enough) {
			insertsort(gettime(), get_n(), get_results());
			state->i++;
			/* we completed all the experiments, return results */
			if (state->i >= state->repetitions) {
				state->state = cooldown;
			}
		}
		if (state->parallel == 1 
		    && (result < 0.99 * state->enough || result > 1.2 * state->enough)) {
			if (result > 150.) {
				double tmp = iterations / result;
				tmp *= 1.1 * state->enough;
				iterations = (iter_t)(tmp + 1);
			} else {
				iterations <<= 3;
				if (iterations > 1<<27
				    || (result < 0. && iterations > 1<<20)) {
					state->state = cooldown;
				}
			}
		}
		state->iterations = iterations;
		if (state->state == cooldown) {
			/* send 'done' */
			write(state->response, (void*)&c, sizeof(char));
			iterations = state->iterations_batch;
		}
		break;
	case cooldown:
		iterations = state->iterations_batch;
		FD_SET(state->result_signal, &fds);
		select(state->result_signal+1, &fds, NULL, NULL, &timeout);
		if (FD_ISSET(state->result_signal, &fds)) {
			/* 
			 * At this point all children have stopped their
			 * measurement loops, so we can block waiting for
			 * the parent to tell us to send our results back.
			 * From this point on, we will do no more "work".
			 */
			read(state->result_signal, (void*)&c, sizeof(char));
			write(state->response, (void*)get_results(), state->r_size);
			if (state->cleanup) {
				if (benchmp_sigchld_handler == SIG_DFL)
					signal(SIGCHLD, SIG_DFL);
				(*state->cleanup)(0, state->cookie);
			}

			/* Now wait for signal to exit */
			read(state->exit_signal, (void*)&c, sizeof(char));
			exit(0);
		}
	};
	if (state->initialize) {
		(*state->initialize)(iterations, state->cookie);
	}
	start(0);
	return (iterations);
}
 vector<string> addOperators(string num, int target) {
     vector<string> result;
     get_results(num, 0, "", result, target, 0, 0);
     return result;
 }