コード例 #1
0
ファイル: audioprint.c プロジェクト: tidatida/gretl
static int speak_buffer (const char *buf, int (*should_stop)())
{
    ISpVoice *v = NULL;
    WCHAR *w;
    char line[2048];

    v = get_sapi_voice();
    if (v == NULL) return 1;

    bufgets_init(buf);

    while (bufgets(line, sizeof line, buf)) {
        if (should_stop()) {
            ISpVoice_Speak(v, L"OK, stopping", 0, NULL);
            break;
        }
        tailstrip(line);
        w = wide_string(line);
        ISpVoice_Speak(v, w, 0, NULL);
        free(w);
    }

    bufgets_finalize(buf);

    release_sapi_voice(v);

    return 0;
}
コード例 #2
0
States fsm_going_up(system_state_t* system_state, States fsm_previous_state){

	if (elev_get_stop_signal()){
		return stop;
	}
	
	system_state->next_floor = system_state->current_floor + system_state->motor_direction;
	
    elev_set_door_open_lamp(0);
    elev_set_motor_direction(DIRN_UP);
    
    check_cmd_buttons(system_state);
    check_call_buttons(system_state);

	check_floor(system_state);
    if (elev_get_floor_sensor_signal() >= 0) { 	
		
		elev_set_floor_indicator(system_state->current_floor);
		
		
		if (should_stop(system_state, system_state->current_floor)){
			elev_set_direction(system_state, 0);
            orders_clearAt(system_state, system_state->current_floor);
	    	reset_button_indicators(system_state);     	
			return door_open;
		}
    }  
    return going_up;
}
コード例 #3
0
ファイル: thread_pool.cpp プロジェクト: rockfireredmoon/iceee
std::pair<bool, thread_pool::task_t>
thread_pool::fetch_task_or_stop(void) {
  std::unique_lock<std::mutex> lock(m_tasks_mtx);

  __TACOPIE_LOG(debug, "waiting to fetch task");

  m_tasks_condvar.wait(lock, [&] { return should_stop() || !m_tasks.empty(); });

  if (should_stop()) {
    --m_nb_running_threads;
    return {true, nullptr};
  }

  task_t task = std::move(m_tasks.front());
  m_tasks.pop();
  return {false, task};
}
コード例 #4
0
ファイル: errorhandler.hpp プロジェクト: maverick0122/islang
	bool milestone() const
	{
		if(!should_stop())
			return true;

		std::cerr << ss.str();

		return false;
	}
コード例 #5
0
ファイル: audioprint.c プロジェクト: tidatida/gretl
static int read_listbox_content (GtkWidget *listbox, int (*should_stop)())
{
    GtkTreeModel *model;
    GtkTreeIter iter;
    gchar *line;
    gchar *tmpstr[3];
    int i, err = 0;

    model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
    gtk_tree_model_get_iter_first(model, &iter);

    err = speak_line("Contents of list box.\n");

    while (!err) {
        tmpstr[0] = tmpstr[1] = tmpstr[2] = NULL;

        if (!GTK_IS_TREE_MODEL(model)) break;

        gtk_tree_model_get(model, &iter,
                           0, &tmpstr[0],
                           1, &tmpstr[1],
                           2, &tmpstr[2],
                           -1);

        line = g_strdup_printf("%s. %s. %s.\n",
                               ((tmpstr[0] != NULL && *tmpstr[0] != '\0')?
                                tmpstr[0] : "empty column"),
                               ((tmpstr[1] != NULL && *tmpstr[1] != '\0')?
                                tmpstr[1] : "empty column"),
                               ((tmpstr[2] != NULL && *tmpstr[2] != '\0')?
                                tmpstr[2] : "empty column"));

        err = speak_line(line);

        for (i=0; i<3; i++) {
            g_free(tmpstr[i]);
        }
        g_free(line);

        if (!GTK_IS_TREE_MODEL(model) ||
                !gtk_tree_model_iter_next(model, &iter) ||
                should_stop()) {
            break;
        }
    }

#ifdef G_OS_WIN32
    speak_line(NULL);
#endif

    return err;
}
コード例 #6
0
ファイル: 1-8-BreakContinue.c プロジェクト: andrey-malets/C
int main(void) {
  for (size_t value = 30; value != 50; ++value) {
    if (should_stop(value)) {
      break;
    }
    if (!interesting(value)) {
      continue;
    }
    process(value);
  }

  return 0;
}
コード例 #7
0
ファイル: break.c プロジェクト: yy221/winedbg
/***********************************************************************
 *           break_should_continue
 *
 * Determine if we should continue execution after a SIGTRAP signal when
 * executing in the given mode.
 */
BOOL break_should_continue(ADDRESS64* addr, DWORD code)
{
    enum dbg_exec_mode  mode = dbg_curr_thread->exec_mode;


    if (dbg_curr_thread->stopped_xpoint > 0)
    {
        if (!should_stop(dbg_curr_thread->stopped_xpoint)) return TRUE;

        switch (dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].xpoint_type)
        {
        case be_xpoint_break:
        case be_xpoint_watch_exec:
            dbg_printf("Stopped on breakpoint %d at ", dbg_curr_thread->stopped_xpoint);
            print_address(&dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].addr, TRUE);
            dbg_printf("\n");
            break;
        case be_xpoint_watch_read:
        case be_xpoint_watch_write:
            dbg_printf("Stopped on watchpoint %d at ", dbg_curr_thread->stopped_xpoint);
            print_address(addr, TRUE);
            dbg_printf(" new value %s\n",
                       wine_dbgstr_longlong(dbg_curr_process->bp[dbg_curr_thread->stopped_xpoint].w.oldval));
        }
        return FALSE;
    }

    /*
     * If our mode indicates that we are stepping line numbers,
     * get the current function, and figure out if we are exactly
     * on a line number or not.
     */
    if (mode == dbg_exec_step_over_line || mode == dbg_exec_step_into_line)
    {
	if (symbol_get_function_line_status(addr) == dbg_on_a_line_number)
            dbg_curr_thread->exec_count--;
    }
    else if (mode == dbg_exec_step_over_insn || mode == dbg_exec_step_into_insn)
        dbg_curr_thread->exec_count--;

    if (dbg_curr_thread->exec_count > 0 || mode == dbg_exec_finish)
    {
	/*
	 * We still need to execute more instructions.
	 */
	return TRUE;
    }

    /* no breakpoint, continue if in continuous mode */
    return mode == dbg_exec_cont || mode == dbg_exec_finish;
}
コード例 #8
0
ファイル: task3.c プロジェクト: Denkata359/po-homework-1
int main(){
    while (1) {
        char* word;
        word = malloc(200);
        scanf("%s", word);
        add_to_hash(word);  
        free(word);      
        if (should_stop()){
            break;
        }
    }
 
    sort_all();
    print_all();    
    return 0;
}
コード例 #9
0
ファイル: replay-log.c プロジェクト: naota/log-writes
static int seek_to_mark(struct log *log, struct log_write_entry *entry,
			char *mark)
{
	int ret;

	while ((ret = log_seek_next_entry(log, entry, 1)) == 0) {
		if (should_stop(entry, LOG_MARK_FLAG, mark))
			break;
	}
	if (ret == 1) {
		fprintf(stderr, "Couldn't find starting mark\n");
		ret = -1;
	}

	return ret;
}
コード例 #10
0
int SimulatedFSM::calculate(int floor, int type)
{
  insert_order(floor, type);
  int step = 0;
  if (state.door_open)
    step++;
  while (!at_floor(floor))  {
    LOG(5, "dir=" << (int)state.direction << " floor=" << state.current_floor
	<< "state=" << (int)state.state_id);
    if (state.state_id == MOVING) {
      if (step > 0 && should_stop(state.current_floor)) {
	state.state_id = STOPPED;
	step++;
	continue;
      }
    }
    else {
      state.state_id = MOVING;
    }

    if (state.direction == Direction::UP) {
      if (floors_above()) {
	state.current_floor++;
	step++;
      }
      else if (floors_below()) {
	state.direction = Direction::DOWN;
	state.current_floor--;
	step++;
      }
    }
    else if (state.direction == Direction::DOWN) {
      if (floors_below()) {
	state.current_floor--;
	step++;
      }
      else if (floors_above()) {
	state.direction = Direction::UP;
	state.current_floor++;
	step++;
      }
    }
  }
  return step;
}
コード例 #11
0
int next_rep(int *c, int m, int n)
{
    if (should_stop(c, m, n))
        return 0;

    int i, carry = 1;
    int d = m + 1;
    for (i = 0; i < n; ++i) {
        int val = c[i] + carry;
        if (!overbidding)
            d = max_val[i] + 1;
        carry = val / d;
        val %= d;
        c[i] = val;
        if (carry == 0)
            break;
    }
    return 1;
}
コード例 #12
0
ファイル: message_loop.hpp プロジェクト: vinzenz/oga
 void run() {
     while (!should_stop()) {
         oga::proto::json::object message;
         error_type result = connection_.receive(message);
         if (result.code() == 0) {
             if (message.is_string("__name__")) {
                 std::string name = message["__name__"].get_string();
                 message.erase("__name__");
                 try {
                     messages_.dispatch_message(name, message);
                 }
                 catch (...) {
                     OGA_LOG_ERROR(log::get("message_loop"), "Unhandled exception caught while handling: {0} args: {1}") % name % message;
                 }
             }
         }
         else {
             OGA_LOG_INFO(log::get("message_loop"), "Failed to receive message from connection. Code: {0} Message: {1}") % result.code() % result.message();
             this_thread::sleep(1000);
         }
     }
 }
コード例 #13
0
ファイル: audioprint.c プロジェクト: tidatida/gretl
static int speak_buffer (const char *buf, int (*should_stop)())
{
    cst_voice *v;
    char line[2048];

    flite_init();
    v = register_cmu_us_kal();

    bufgets_init(buf);

    while (bufgets(line, sizeof line, buf)) {
        if (should_stop()) {
            flite_text_to_speech("OK, stopping", v, "play");
            break;
        }
        tailstrip(line);
        flite_text_to_speech(line, v, "play");
    }

    bufgets_finalize(buf);

    return 0;
}
コード例 #14
0
ファイル: ircclientthread.cpp プロジェクト: SeekingFor/FLIP
void IRCClientThread::thread()
{
	int ciphersuites[] =
	{
		SSL_EDH_RSA_AES_256_SHA,
		SSL_EDH_RSA_CAMELLIA_256_SHA,
		SSL_EDH_RSA_AES_128_SHA,
		SSL_EDH_RSA_CAMELLIA_128_SHA,
		SSL_EDH_RSA_DES_168_SHA,
		SSL_RSA_AES_256_SHA,
		SSL_RSA_CAMELLIA_256_SHA,
		SSL_RSA_AES_128_SHA,
		SSL_RSA_CAMELLIA_128_SHA,
		SSL_RSA_DES_168_SHA,
		SSL_RSA_RC4_128_SHA,
		SSL_RSA_RC4_128_MD5,
		0
	};
	int rval=0;
	fd_set readfs;
	fd_set writefs;
	struct timeval tv;
	std::string temp("");

	// setup SSL connection first
	if(m_contype==IRCClientConnection::CON_SSL)
	{
		m_log->Error("IRCClientThread::thread SSL handshaking with client");
		ssl_set_ciphersuites(&(m_ssl->m_ssl),ciphersuites);
		rval=ssl_handshake(&(m_ssl->m_ssl));
		if(rval!=0)
		{
			StringFunctions::Convert(rval,temp);
			m_log->Error("IRCClientThread::thread couldn't handshake with client - return value = "+temp);
			Disconnect();
			return;
		}
	}

	while(should_stop()==false && IsConnected()==true)
	{
		tv.tv_sec=0;
		tv.tv_usec=100000;
		FD_ZERO(&readfs);
		FD_ZERO(&writefs);

		FD_SET(m_socket,&readfs);
		if(SendBufferSize()>0)
		{
			FD_SET(m_socket,&writefs);
		}

		rval=select(m_socket+1,&readfs,&writefs,0,&tv);

		if(rval>0)
		{
			if(FD_ISSET(m_socket,&readfs))
			{
				SocketReceive();
			}
			if(IsConnected() && FD_ISSET(m_socket,&writefs))
			{
				SocketSend();
			}
		}

		if(m_wantdisconnect==true)
		{
			Disconnect();
		}
	}
}
コード例 #15
0
ファイル: replay-log.c プロジェクト: naota/log-writes
int main(int argc, char **argv)
{
	char *logfile = NULL, *replayfile = NULL, *fsck_command = NULL;
	struct log_write_entry *entry;
	u64 stop_flags = 0;
	u64 start_entry = 0;
	u64 run_limit = 0;
	u64 num_entries = 0;
	u64 check_number;
	char *end_mark = NULL, *start_mark = NULL;
	char *tmp = NULL;
	struct log *log;
	int find_mode = 0;
	int c;
	int opt_index;
	int ret;
	int print_num_entries = 0;
	int discard = 1;
	enum log_replay_check_mode check_mode = 0;

	while ((c = getopt_long(argc, argv, "v", long_options,
				&opt_index)) >= 0) {
		switch(c) {
		case 'v':
			log_writes_verbose++;
			continue;
		default:
			break;
		}

		switch(opt_index) {
		case NEXT_FLUSH:
			stop_flags |= LOG_FLUSH_FLAG;
			break;
		case NEXT_FUA:
			stop_flags |= LOG_FUA_FLAG;
			break;
		case START_ENTRY:
			start_entry = strtoull(optarg, &tmp, 0);
			if (tmp && *tmp != '\0') {
				fprintf(stderr, "Invalid entry number\n");
				exit(1);
			}
			tmp = NULL;
			break;
		case START_MARK:
			/*
			 * Biggest sectorsize is 4k atm, so limit the mark to 4k
			 * minus the size of the entry.  Say 4097 since we want
			 * an extra slot for \0.
			 */
			start_mark = strndup(optarg, 4097 -
					     sizeof(struct log_write_entry));
			if (!start_mark) {
				fprintf(stderr, "Couldn't allocate memory\n");
				exit(1);
			}
			break;
		case END_MARK:
			/*
			 * Biggest sectorsize is 4k atm, so limit the mark to 4k
			 * minus the size of the entry.  Say 4097 since we want
			 * an extra slot for \0.
			 */
			end_mark = strndup(optarg, 4097 -
					   sizeof(struct log_write_entry));
			if (!end_mark) {
				fprintf(stderr, "Couldn't allocate memory\n");
				exit(1);
			}
			stop_flags |= LOG_MARK_FLAG;
			break;
		case LOG:
			logfile = strdup(optarg);
			if (!logfile) {
				fprintf(stderr, "Couldn't allocate memory\n");
				exit(1);
			}
			break;
		case REPLAY:
			replayfile = strdup(optarg);
			if (!replayfile) {
				fprintf(stderr, "Couldn't allocate memory\n");
				exit(1);
			}
			break;
		case LIMIT:
			run_limit = strtoull(optarg, &tmp, 0);
			if (tmp && *tmp != '\0') {
				fprintf(stderr, "Invalid entry number\n");
				exit(1);
			}
			tmp = NULL;
			break;
		case FIND:
			find_mode = 1;
			break;
		case NUM_ENTRIES:
			print_num_entries = 1;
			break;
		case NO_DISCARD:
			discard = 0;
			break;
		case FSCK:
			fsck_command = strdup(optarg);
			if (!fsck_command) {
				fprintf(stderr, "Couldn't allocate memory\n");
				exit(1);
			}
			break;
		case CHECK:
			if (!strcmp(optarg, "flush")) {
				check_mode = CHECK_FLUSH;
			} else if (!strcmp(optarg, "fua")) {
				check_mode = CHECK_FUA;
			} else {
				check_mode = CHECK_NUMBER;
				check_number = strtoull(optarg, &tmp, 0);
				if (tmp && *tmp != '\0') {
					fprintf(stderr,
						"Invalid entry number\n");
					exit(1);
				}
				tmp = NULL;
			}
			break;
		default:
			usage();
		}
	}

	if (!logfile)
		usage();

	log = log_open(logfile, replayfile);
	if (!log)
		exit(1);
	free(logfile);
	free(replayfile);

	if (!discard)
		log->flags |= LOG_IGNORE_DISCARD;

	entry = malloc(log->sectorsize);
	if (!entry) {
		fprintf(stderr, "Couldn't allocate buffer\n");
		log_free(log);
		exit(1);
	}

	if (start_mark) {
		ret = seek_to_mark(log, entry, start_mark);
		if (ret)
			exit(1);
		free(start_mark);
	} else {
		ret = log_seek_entry(log, start_entry);
		if (ret)
			exit(1);
	}

	if ((fsck_command && !check_mode) || (!fsck_command && check_mode))
		usage();

	/* We just want to find a given entry */
	if (find_mode) {
		while ((ret = log_seek_next_entry(log, entry, 1)) == 0) {
			num_entries++;
			if ((run_limit && num_entries == run_limit) ||
			    should_stop(entry, stop_flags, end_mark)) {
				printf("%llu\n",
				       (unsigned long long)log->cur_entry - 1);
				log_free(log);
				return 0;
			}
		}
		log_free(log);
		if (ret < 0)
			return ret;
		fprintf(stderr, "Couldn't find entry\n");
		return 1;
	}

	/* Used for scripts, just print the number of entries in the log */
	if (print_num_entries) {
		printf("%llu\n", (unsigned long long)log->nr_entries);
		log_free(log);
		return 0;
	}

	/* No replay, just spit out the log info. */
	if (!replayfile) {
		printf("Log version=%d, sectorsize=%lu, entries=%llu\n",
		       WRITE_LOG_VERSION, (unsigned long)log->sectorsize,
		       (unsigned long long)log->nr_entries);
		log_free(log);
		return 0;
	}

	while ((ret = log_replay_next_entry(log, entry, 1)) == 0) {
		num_entries++;
		if (fsck_command) {
			if ((check_mode == CHECK_NUMBER) &&
			    !(num_entries % check_number))
				ret = run_fsck(fsck_command);
			else if ((check_mode == CHECK_FUA) &&
				 should_stop(entry, LOG_FUA_FLAG, NULL))
				ret = run_fsck(fsck_command);
			else if ((check_mode == CHECK_FLUSH) &&
				 should_stop(entry, LOG_FLUSH_FLAG, NULL))
				ret = run_fsck(fsck_command);
			else
				ret = 0;
			if (ret)
				break;
		}

		if ((run_limit && num_entries == run_limit) ||
		    should_stop(entry, stop_flags, end_mark))
			break;
	}
	fsync(log->replayfd);
	log_free(log);
	free(end_mark);
	if (ret < 0)
		exit(1);
	return 0;
}
コード例 #16
0
	void
	TraceFilter::thread_run()
	{		
		
		mlog(MLog::info, "TraceFilter") << "Waiting for FilteredTrace objects...\n";
		while (!should_stop())
		{				
			
			_queue_mutex.enterMutex();
			while(_queue.size() > 0)
			{
				FilteredTrace filtered_trace(_service_list);
				std::string queue_front = _queue.front();

				_queue_mutex.leaveMutex();
				if (filtered_trace.parse_nmea_string(queue_front))
				{
					_working_queue.push(filtered_trace);
					
					/*show_state("Inital state");*/
					
					int available_traces;
					int ready_traces;
	
					/* Test for time */
					available_traces = _working_queue.size();
					ready_traces = 0;
					while(ready_traces < available_traces)
					{
						apply_equal_time_filter(_working_queue.front());
						_working_queue.pop();
						++ready_traces;
						/*show_state("Applied time filter", ready_traces);*/
					}
					
					/* Test for location */
					available_traces = _working_queue.size();
					ready_traces = 0;
					while(ready_traces < available_traces)
					{
						apply_equal_location_filter(_working_queue.front());
						_working_queue.pop();
						++ready_traces;
						/*show_state("Applied location filter", ready_traces);*/
					}
	
					/* apply anti-cumulation filter */
					available_traces = _working_queue.size();
					ready_traces = 0;
					while(ready_traces < available_traces)
					{
						apply_anti_cumulation_filter(_working_queue.front());
						_working_queue.pop();
						++ready_traces;
						/*show_state("Applied anti-cumulation filter");*/
					}
					
					/* Test for gaps */
					available_traces = _working_queue.size();
					ready_traces = 0;
					while(ready_traces < available_traces)
					{
						apply_gap_filter(_working_queue.front());
						_working_queue.pop();
						++ready_traces;
						/*show_state("Applied speed filter", ready_traces);*/
					}
					
					/* Test for speed */
					available_traces = _working_queue.size();
					ready_traces = 0;
					while(ready_traces < available_traces)
					{
						apply_speed_filter(_working_queue.front());
						_working_queue.pop();
						++ready_traces;
						/*show_state("Applied speed filter", ready_traces);*/
					}
					
					/* Test for acceleration */
					available_traces = _working_queue.size();
					ready_traces = 0;
					while(ready_traces < available_traces)
					{
						apply_acceleration_filter(_working_queue.front());
						_working_queue.pop();
						++ready_traces;
						/*show_state("Applied acceleration filter", ready_traces);*/
					}
					
					/* Test for trace length and propagade it to the tile manager */
					int min_trace_length = 5;
					if (!_service_list->get_service_value("tracefilter.min_trace_length",
						min_trace_length))
					{
						mlog(MLog::info, "TraceFilter")
							<< "Configuration for min trace length not found,"
							<< " using default (" << min_trace_length << ").\n";
					}
	
					while(_working_queue.size() > 0)
					{
						FilteredTrace& trace = _working_queue.front();
						if (trace.size() < min_trace_length)
						{
//						mlog(MLog::debug, "TraceFilter")
//							<< "Trace too small. Discard it!\n";
						} else
						{
							_tile_manager->new_trace(trace);
						}
						
						_working_queue.pop();
						/*show_state("Propagation");*/
					}
				} else
				{
					mlog(MLog::warning, "TraceFilter")
							<< "Error parsing NMEA string!\n";
				}
				
				_queue_mutex.enterMutex();
				_queue.pop();
			}
			_queue_mutex.leaveMutex();
			// WARNING: The above enter leave combination is ok! Look at 
			// the beginning of the if/loop!

			_should_stop_event.wait(500);
		}
	}
コード例 #17
0
ファイル: dns_handler.cpp プロジェクト: HalfDemon/MCPP
	void DNSHandler::worker () {
	
		//	FD sets used for selecting
		fd_set readable;
		fd_set writeable;
		//	Maximum file descriptor to pass
		//	to select
		int nfds;
		//	The timeout for select
		struct timeval tv;
	
		//	Loop until shutdown
		for (;;) {
		
			//	Zero FDs
			FD_ZERO(&readable);
			FD_ZERO(&writeable);			
			
			if (lock.Execute([&] () mutable {
			
				//	Wait for there to be something actionable,
				//	either pending queries, or a shutdown command
				while (!stop && (queries.size()==0)) wait.Sleep(lock);
				
				//	If the command to shutdown has been given,
				//	do that at once
				if (stop) return true;
				
				//	Get the file descriptors from libcares
				nfds=ares_fds(
					channel,
					&readable,
					&writeable
				);
				//	Get the timeout from libcares
				ares_timeout(
					channel,
					nullptr,
					&tv
				);
				
				return false;
			
			})) break;
			
			//	If there's a message pending on
			//	the worker end of the socket pair,
			//	we want to be woken up, so 
			
			//	If there's a message pending
			//	on the worker end of the socket
			//	pair, we want to be woken up,
			//	so we're checking for readability
			nfds=control.Add(readable,nfds);
			
			//	Wait for something to happen
			if (select(
				nfds,
				&readable,
				&writeable,
				nullptr,
				&tv
			)==
			#ifdef ENVIRONMENT_WINDOWS
			SOCKET_ERROR
			#else
			-1
			#endif
			) raise_os();
			
			//	Did something happen with the
			//	control socket?
			if (control.Is(readable)) {
			
				//	Check to see if a shutdown command
				//	is coming through the control socket,
				//	if so end at once
				if (should_stop()) break;
			
				//	Remove it in case it matters to
				//	libcares what's in the fd_set
				control.Clear(readable);
			
			}
			
			//	Call libcares
			lock.Execute([&] () mutable {
			
				ares_process(
					channel,
					&readable,
					&writeable
				);
			
			});
		
		}
	
	}