void BeanSerialTransport::BTSetPairingPin(const uint16_t pin){
   write_message(MSG_ID_BT_SET_PIN, (const uint8_t*)&pin, sizeof(pin));
 };
void BeanSerialTransport::BTSetConnectionInterval(const int interval_ms){
  write_message(MSG_ID_BT_SET_CONN, (const uint8_t*)&interval_ms, sizeof(int));
}
Пример #3
0
bool addNhlGame(int fd, Game game) {
    bool status = true;

    status = status && write_message(fd, "      ");
    status = status && write_message(fd, game.atn.c_str());
    if (!game.ats.empty()){
        status = status && write_message(fd, " : ");
        status = status && write_message(fd, game.ats.c_str());
    }
    status = status && write_message(fd, " - ");
    status = status && write_message(fd, game.htn.c_str());
    
    if (!game.hts.empty()){
        status = status && write_message(fd, " : ");
        status = status && write_message(fd, game.hts.c_str());
    }

    set_font(fd, FIVE_HIGH_STD);
    status = status && write_message(fd, " (");
    if (game.bs == "LIVE") {
        status = status && write_message(fd, game.ts.c_str());
    } else {
        status = status && write_message(fd, game.bs.c_str());
        
    }
    status = status && write_message(fd, ")");   
    set_font(fd, SEVEN_HIGH_STD);

    return status;
}
 void BeanSerialTransport::BTSetAdvertisingOnOff(const bool setting, uint32_t timer){
   BT_ADV_ONOFF_T advOnOff;
   advOnOff.adv_timer = timer;
   advOnOff.adv_onOff = setting ? 1 : 0;
   write_message(MSG_ID_BT_ADV_ONOFF, (const uint8_t*)&advOnOff, sizeof(advOnOff));
 };
////////
// Sleep
////////
void BeanSerialTransport::sleep(uint32_t duration_ms){
  write_message(MSG_ID_AR_SLEEP, (const uint8_t *)&duration_ms, sizeof(duration_ms));
}
int
main_program(int num_messages, int num_channels, int num_connections, const char *server_hostname, int server_port, int timeout)
{
    struct sockaddr_in server_address;
    int main_sd = -1, num_events = 0, i, event_mask, channels_per_connection, num, start_time = 0, iters_to_next_summary = 0;
    Connection *connections = NULL, *connection;
    Statistics stats = {0,0,0,0,0};
    int exitcode = EXIT_SUCCESS;
    struct epoll_event events[MAX_EVENTS];
    char buffer[BIG_BUFFER_SIZE];

    info("Publisher starting up\n");
    info("Publish: %d messages to %d channels on server: %s:%d\n", num_messages, num_channels, server_hostname, server_port);

    if ((fill_server_address(server_hostname, server_port, &server_address)) != 0) {
        error2("ERROR host name not found\n");
    }

    if ((main_sd = epoll_create(200 /* this size is not used on Linux kernel 2.6.8+ */)) < 0) {
        error3("Failed %d creating main epoll socket\n", errno);
    }

    if ((connections = init_connections(num_connections, &server_address, main_sd)) == NULL) {
        error2("Failed to create to connections\n");
    }

    stats.requested_connections = num_connections;

    channels_per_connection = num_channels / num_connections;
    for (i = 0; i < num_connections; i++) {
        num = i * channels_per_connection;
        connections[i].channel_start = num;
        num += channels_per_connection - 1;
        connections[i].channel_end = ((num > num_channels) || (i == (num_connections - 1))) ? num_channels - 1 : num;
    }

    // infinite loop
    debug("Entering Infinite Loop\n");

    iters_to_next_summary = ITERATIONS_TILL_SUMMARY_PER_TIMEOUT/timeout;

    for(;;) {
        if ((num_events = epoll_wait(main_sd, events, MAX_EVENTS, timeout)) < 0) {
            error3("epoll_wait failed\n");
        }

        for (i = 0; i < num_events; i++) {
            event_mask = events[i].events;
            connection = (Connection *)(events[i].data.ptr);

            if ((connection->message_count >= num_messages) && (connection->channel_id > connection->channel_end)) {
                // remove write flag from event
                if (change_connection(connection, EPOLLIN | EPOLLHUP) < 0) {
                    error2("Failed creating socket for connection = %d\n", connection->index);
                }

                if (event_mask & EPOLLOUT) { // WRITE
                    continue;
                }
            }

            if (event_mask & EPOLLHUP) { // SERVER HUNG UP
                debug("EPOLLHUP\n");
                info("Server hung up on conncetion %d. Reconecting...\n", connection->index);
                sleep(1);
                reopen_connection(connection);

                continue;
            }

            if (event_mask & EPOLLERR) {
                debug("EPOLLERR\n");
                info("Server returned an error on connection %d. Reconecting...\n", connection->index);
                reopen_connection(connection);

                continue;
            }

            if (event_mask & EPOLLIN) { // READ
                debug("----------READ AVAILABLE-------\n");

                if (connection->state == CONNECTED) {
                    read_response(connection, &stats, buffer, BIG_BUFFER_SIZE);
                }
            }

            if (event_mask & EPOLLOUT) { // WRITE
                debug("----------WRITE AVAILABLE-------\n");

                if (start_time == 0) {
                    start_time = time(NULL);
                }

                if (connection->state == CONNECTING) {
                    connection->state = CONNECTED;
                    stats.connections++;
                    debug("Connection opened for index=%d\n", connection->index);
                }

                write_message(connection, &stats);
            }
        }

        if (iters_to_next_summary-- <= 0) {
            iters_to_next_summary = ITERATIONS_TILL_SUMMARY_PER_TIMEOUT/timeout;
            summary("Connections=%ld, Messages=%ld BytesWritten=%ld Msg/Sec=%0.2f\n", stats.connections, stats.messages, stats.bytes_written, calc_message_per_second(stats.messages, start_time));
        }

        if (stats.messages >= (num_channels * num_messages)) {
            summary("Connections=%ld, Messages=%ld BytesWritten=%ld Msg/Sec=%0.2f\n", stats.connections, stats.messages, stats.bytes_written, calc_message_per_second(stats.messages, start_time));
            for (i = 0; i < num_connections; i++) {
                close_connection(&connections[i]);
                stats.connections--;
            }
            exitcode = EXIT_SUCCESS;
            goto exit;
        }
    }


exit:
    if (connections != NULL) free(connections);

    return exitcode;
}
int create_sensor(sensor_handle *handle, sensor_create_params *params)
{
	sensor_context *sensor = NULL;
	int return_value = E_FAILURE;

	sensor = (sensor_context*)malloc(sizeof(sensor_context));
	if(NULL == sensor)
	{
		delete_sensor((sensor_handle)sensor);
		LOG_ERROR(("ERROR: Out of memory\n"));
		return (E_OUT_OF_MEMORY);
	}

	memset(sensor, 0, sizeof(sensor_context));
	sensor->interval = 5;
	sensor->sensor_params = params;
	sensor->clock = 0;
	sensor->value = 0;
	sensor->run = 1;
	sensor->recv_peer_count = 0;
	sensor->send_peer_count = 0;

	pthread_mutex_init(&sensor->mutex_lock, NULL);

	sensor->sensor_value_file_pointer = fopen(params->sensor_value_file_name, "r");
	if(!sensor->sensor_value_file_pointer)
	{
		LOG_ERROR(("Unable to open sensor value input file\n"));
		delete_sensor(sensor);
		return (E_FAILURE);
	}

	/* create network read thread */
	return_value = create_network_thread(&sensor->network_thread, params->sensor_ip_address);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Error in creating n/w read thread\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	/* create connection to server */
	return_value = create_server_socket(&sensor->server_socket_fd, params->sensor_ip_address, params->sensor_port_no);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Error in creating the socket\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	/* add socket to network read thread */
	return_value = add_socket(sensor->network_thread, sensor->server_socket_fd,  (void*)sensor, &accept_callback);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: add_socket() failed\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	/* create connection to server */
	return_value = create_socket(&sensor->socket_fd, params->gateway_ip_address, params->gateway_port_no);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Connection to Server failed\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	/* add socket to network read thread */
	return_value = add_socket(sensor->network_thread, sensor->socket_fd,  (void*)sensor, &read_callback);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: add_socket() filed\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	message msg;

	/* register sensor with gateway */
	msg.type = REGISTER;
	msg.u.s.type = KEY_CHAIN_SENSOR;
	msg.u.s.ip_address = sensor->sensor_params->sensor_ip_address;
	msg.u.s.port_no = sensor->sensor_params->sensor_port_no;
	msg.u.s.area_id = sensor->sensor_params->sensor_area_id;

	return_value = write_message(sensor->socket_fd, sensor->logical_clock, &msg);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Error in registering sensor\n"));
		return (E_FAILURE);
	}

	struct sigaction        actions;
	memset(&actions, 0, sizeof(actions));
	sigemptyset(&actions.sa_mask);
	actions.sa_flags = 0;
	actions.sa_handler = sighand;
	sigaction(SIGALRM,&actions,NULL);

	*handle = sensor;

	LOG_SCREEN(("INFO: Waiting for Peers to connect...\n"));

	return (E_SUCCESS);
}
void BeanSerialTransport::ledSet(const LED_SETTING_T &setting){
  write_message(MSG_ID_CC_LED_WRITE_ALL, (const uint8_t *)&setting, sizeof(setting));
}
Пример #9
0
void spawn_filter(const char *filter_command) {
  int input_pipe_fds[2];
  int output_pipe_fds[2];

  mypipe(input_pipe_fds);
  filter_input_fd = input_pipe_fds[1]; /* rlwrap writes filter input to this */ 
  
  mypipe(output_pipe_fds);
  filter_output_fd = output_pipe_fds[0]; /* rlwrap  reads filter output from here */
  DPRINTF1(DEBUG_FILTERING, "preparing to spawn filter <%s>", filter_command);
  assert(!command_pid || signal_handlers_were_installed);  /* if there is a command, then signal handlers are installed */
  
  if ((filter_pid = fork()) < 0)
    myerror(FATAL|USE_ERRNO, "Cannot spawn filter '%s'", filter_command); 
  else if (filter_pid == 0) {           /* child */
    int signals_to_allow[] = {SIGPIPE, SIGCHLD, SIGALRM, SIGUSR1, SIGUSR2};
    char **argv;
    unblock_signals(signals_to_allow);  /* when we run a pager from a filter we want to catch these */


    DEBUG_RANDOM_SLEEP;
    i_am_child =  TRUE;
    /* set environment for filter (it needs to know at least the file descriptors for its input and output) */
   
    if (!getenv("RLWRAP_FILTERDIR"))
      mysetenv("RLWRAP_FILTERDIR", add2strings(DATADIR,"/rlwrap/filters"));
    mysetenv("PATH", add3strings(getenv("RLWRAP_FILTERDIR"),":",getenv("PATH")));
    mysetenv("RLWRAP_VERSION", VERSION);
    mysetenv("RLWRAP_COMMAND_PID",  as_string(command_pid));
    mysetenv("RLWRAP_COMMAND_LINE", command_line); 
    if (impatient_prompt)
      mysetenv("RLWRAP_IMPATIENT", "1");
    mysetenv("RLWRAP_INPUT_PIPE_FD", as_string(input_pipe_fds[0]));
    mysetenv("RLWRAP_OUTPUT_PIPE_FD", as_string(output_pipe_fds[1]));
    mysetenv("RLWRAP_MASTER_PTY_FD", as_string(master_pty_fd));
        
    close(filter_input_fd);
    close(filter_output_fd);


    if (scan_metacharacters(filter_command, "'|\"><"))  { /* if filter_command contains shell metacharacters, let the shell unglue them */
      char *exec_command = add3strings("exec", " ", filter_command);
      argv = list4("sh", "-c", exec_command, NULL);
    } else {                                              /* if not, split and feed to execvp directly (cheaper, better error message) */
      argv = split_with(filter_command, " ");
    }   
    assert(argv[0]);    
    if(execvp(argv[0], argv) < 0) {
      char *sorry = add3strings("Cannot exec filter '", argv[0], add2strings("': ", strerror(errno))); 
      write_message(output_pipe_fds[1], TAG_ERROR, sorry, "to stdout"); /* this will kill rlwrap */
      mymicrosleep(100 * 1000); /* 100 sec for rlwrap to go away should be enough */
      exit (-1);
    }
    assert(!"not reached");
    
  } else {
    DEBUG_RANDOM_SLEEP;
    signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE - we have othere ways to deal with filter death */
    DPRINTF1(DEBUG_FILTERING, "spawned filter with pid %d", filter_pid);
    close (input_pipe_fds[0]);
    close (output_pipe_fds[1]);
  }
}
static void* read_callback(void *context)
{
	sensor_context *sensor = (sensor_context*)context;
	int return_value = 0;
	message msg, snd_msg;
	peer *client = NULL;
	int msg_logical_clock[CLOCK_SIZE];

	return_value = read_message(sensor->socket_fd, msg_logical_clock, &msg);
	if(return_value != E_SUCCESS)
	{
		if(return_value == E_SOCKET_CONNECTION_CLOSED)
		{
			LOG_ERROR(("ERROR: Socket connection from server closed...\n"));
			exit(0);
		}
		LOG_ERROR(("ERROR: Error in read message\n"));
		return NULL;
	}

	switch(msg.type)
	{
	case SET_INTERVAL:
		LOG_INFO(("INFO: SetInterval message received\n"));
		sensor->interval = msg.u.value;
		break;
	case REGISTER:
		LOG_INFO(("INFO: Register received from gateway\n"));

		client = (peer*)malloc(sizeof(peer));
		if(!client)
		{
			LOG_ERROR(("ERROR: Out of memory"));
			return (NULL);
		}

		client->ip_address = msg.u.s.ip_address;
		client->port_no = msg.u.s.port_no;

		LOG_INFO(("INFO: New Peer %s, %s\n", client->ip_address, client->port_no));

		/* create connection to server */
		return_value = create_socket(&client->comm_socket_fd,
				msg.u.s.ip_address,
				msg.u.s.port_no);
		if(E_SUCCESS != return_value)
		{
			LOG_ERROR(("ERROR: Connection to Server failed\n"));
		}

		/* add socket to network read thread */
		return_value = add_socket(sensor->network_thread,
				client->comm_socket_fd,
				(void*)client,
				&read_callback_peer);
		if(E_SUCCESS != return_value)
		{
			LOG_ERROR(("ERROR: add_socket() filed\n"));
		}
		sensor->send_peer[sensor->send_peer_count] = client;
		sensor->send_peer_count++;

		snd_msg.type = REGISTER;
		snd_msg.u.s.type = KEY_CHAIN_SENSOR;
		snd_msg.u.s.ip_address = sensor->sensor_params->sensor_ip_address;
		snd_msg.u.s.port_no = sensor->sensor_params->sensor_port_no;
		snd_msg.u.s.area_id = sensor->sensor_params->sensor_area_id;
		return_value = write_message(client->comm_socket_fd, sensor->logical_clock, &snd_msg);
		if(E_SUCCESS != return_value)
		{
			LOG_ERROR(("Error in communication\n"));
		}

		if(sensor->send_peer_count == 2 && sensor->recv_peer_count == 2)
		{
			pthread_create(&sensor->set_value_thread, NULL, &set_value_thread, sensor);
		}

		break;
	default:
		LOG_INFO(("INFO: Unknown/Unhandled message was received\n"));
		break;
	}

	return NULL;
}
Пример #11
0
static void write_to_filter(int tag, const char *string) {
  write_message(filter_input_fd, tag, string, "to filter");
}
Пример #12
0
void mode_server(int choice, SOCKET sock)
{
	int extremity_size, pid,pid2;
	SOCKET sock_serv= socket(AF_INET,SOCK_STREAM,0);
	
	SOCKET sock_cliServer, sockClient, sock_cli=-1;
	
	SOCKADDR_IN extremity_server;
	SOCKADDR_IN extremity_client;
	
	if(sock_serv == -1)
	{
		perror("[!] socket : mode_server()");
		exit(-1);
	}
	extremity_server.sin_addr.s_addr = htonl(INADDR_ANY);
	extremity_server.sin_family = AF_INET;
	extremity_server.sin_port = htons(PORT);
	
	if(bind (sock_serv,(SOCKADDR *) &extremity_server ,sizeof(extremity_server)) == -1)
	{
		perror("[!] bind : mode_ server");
		exit(-1);
	}
	if(listen(sock_serv,5) == -1)
	{
		perror("[!] Listen :mode_server()");
		exit(-1);
	}
	extremity_size = sizeof(extremity_client);
	printf("[ok] Server connected\n\n");
	
	
	while(1)
	{
		if(choice == 1)
		{
			
			choice=0;
			sock_cliServer = accept(sock_serv,(SOCKADDR *)&extremity_client,(socklen_t *)&extremity_size);
			if(sock_cliServer == -1)
			{	
				perror("[!] sock_cliServer : mode_server()");
				exit(-1);
			}

			printf("\n[ok] Nouveau client Connected\n");
	
			pid=fork();
			if(pid<0)
				perror("[!] fork(): mode_server");
			if(pid==0)						// RECEPTION MESSAGE BG
			{	

				read_message(sock_cliServer);
				return;
				

			}							// FIN RECEPTION MESSAGE BG
			sleep(1);
			printf("[ok] Connection client\n");
			
			char *temp=inet_ntoa(extremity_client.sin_addr);
		
			printf("####### LE CLIENT EST |%s|\n",inet_ntoa(extremity_client.sin_addr)); 
	
			sockClient=connection_client( temp , PORT);
		
	
			write_message(sockClient);
				
			return ;				// FIN ENVOIE MESSAGE FG

			

		}
		else if (choice == 2)
		{	
			
			choice=0;
			sock_cli = accept(sock_serv,(SOCKADDR *)&extremity_client,(socklen_t *)&extremity_size);
			if(sock_cli == -1)
			{	
				perror("[!] Sock_cli : mode_server()");
				exit(-1);
			}

			printf("\n[ok] Nouveau client Connected\n");
			
			pid2=fork();
			if(pid2<0)
				perror("[!] fork(): mode_server");
			if(pid2==0)							// RECEPTION MESSAGE BG
			{
				read_message(sock_cli);
				return;
				
			}
			printf("####### JE SUIS CONNECTE \n");
			
			write_message(sock);
			return;
			
		}
		else
			printf("ERROR\n");
	
	
	
	
	
	}
	

	
}
Пример #13
0
static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
{
	unsigned char head[20];
	struct commit *base, *next, *parent;
	const char *base_label, *next_label;
	struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
	char *defmsg = NULL;
	struct strbuf msgbuf = STRBUF_INIT;
	int res, unborn = 0, allow;

	if (opts->no_commit) {
		/*
		 * We do not intend to commit immediately.  We just want to
		 * merge the differences in, so let's compute the tree
		 * that represents the "current" state for merge-recursive
		 * to work on.
		 */
		if (write_cache_as_tree(head, 0, NULL))
			die (_("Your index file is unmerged."));
	} else {
		unborn = get_sha1("HEAD", head);
		if (unborn)
			hashcpy(head, EMPTY_TREE_SHA1_BIN);
		if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0))
			return error_dirty_index(opts);
	}
	discard_cache();

	if (!commit->parents) {
		parent = NULL;
	}
	else if (commit->parents->next) {
		/* Reverting or cherry-picking a merge commit */
		int cnt;
		struct commit_list *p;

		if (!opts->mainline)
			return error(_("Commit %s is a merge but no -m option was given."),
				sha1_to_hex(commit->object.sha1));

		for (cnt = 1, p = commit->parents;
		     cnt != opts->mainline && p;
		     cnt++)
			p = p->next;
		if (cnt != opts->mainline || !p)
			return error(_("Commit %s does not have parent %d"),
				sha1_to_hex(commit->object.sha1), opts->mainline);
		parent = p->item;
	} else if (0 < opts->mainline)
		return error(_("Mainline was specified but commit %s is not a merge."),
			sha1_to_hex(commit->object.sha1));
	else
		parent = commit->parents->item;

	if (opts->allow_ff &&
	    ((parent && !hashcmp(parent->object.sha1, head)) ||
	     (!parent && unborn)))
		return fast_forward_to(commit->object.sha1, head, unborn, opts);

	if (parent && parse_commit(parent) < 0)
		/* TRANSLATORS: The first %s will be "revert" or
		   "cherry-pick", the second %s a SHA1 */
		return error(_("%s: cannot parse parent commit %s"),
			action_name(opts), sha1_to_hex(parent->object.sha1));

	if (get_message(commit, &msg) != 0)
		return error(_("Cannot get commit message for %s"),
			sha1_to_hex(commit->object.sha1));

	/*
	 * "commit" is an existing commit.  We would want to apply
	 * the difference it introduces since its first parent "prev"
	 * on top of the current HEAD if we are cherry-pick.  Or the
	 * reverse of it if we are revert.
	 */

	defmsg = git_pathdup("MERGE_MSG");

	if (opts->action == REPLAY_REVERT) {
		base = commit;
		base_label = msg.label;
		next = parent;
		next_label = msg.parent_label;
		strbuf_addstr(&msgbuf, "Revert \"");
		strbuf_addstr(&msgbuf, msg.subject);
		strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
		strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));

		if (commit->parents && commit->parents->next) {
			strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
			strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
		}
		strbuf_addstr(&msgbuf, ".\n");
	} else {
		const char *p;

		base = parent;
		base_label = msg.parent_label;
		next = commit;
		next_label = msg.label;

		/*
		 * Append the commit log message to msgbuf; it starts
		 * after the tree, parent, author, committer
		 * information followed by "\n\n".
		 */
		p = strstr(msg.message, "\n\n");
		if (p) {
			p += 2;
			strbuf_addstr(&msgbuf, p);
		}

		if (opts->record_origin) {
			if (!has_conforming_footer(&msgbuf, NULL, 0))
				strbuf_addch(&msgbuf, '\n');
			strbuf_addstr(&msgbuf, cherry_picked_prefix);
			strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
			strbuf_addstr(&msgbuf, ")\n");
		}
	}

	if (!opts->strategy || !strcmp(opts->strategy, "recursive") || opts->action == REPLAY_REVERT) {
		res = do_recursive_merge(base, next, base_label, next_label,
					 head, &msgbuf, opts);
		write_message(&msgbuf, defmsg);
	} else {
		struct commit_list *common = NULL;
		struct commit_list *remotes = NULL;

		write_message(&msgbuf, defmsg);

		commit_list_insert(base, &common);
		commit_list_insert(next, &remotes);
		res = try_merge_command(opts->strategy, opts->xopts_nr, opts->xopts,
					common, sha1_to_hex(head), remotes);
		free_commit_list(common);
		free_commit_list(remotes);
	}

	/*
	 * If the merge was clean or if it failed due to conflict, we write
	 * CHERRY_PICK_HEAD for the subsequent invocation of commit to use.
	 * However, if the merge did not even start, then we don't want to
	 * write it at all.
	 */
	if (opts->action == REPLAY_PICK && !opts->no_commit && (res == 0 || res == 1))
		write_cherry_pick_head(commit, "CHERRY_PICK_HEAD");
	if (opts->action == REPLAY_REVERT && ((opts->no_commit && res == 0) || res == 1))
		write_cherry_pick_head(commit, "REVERT_HEAD");

	if (res) {
		error(opts->action == REPLAY_REVERT
		      ? _("could not revert %s... %s")
		      : _("could not apply %s... %s"),
		      find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
		      msg.subject);
		print_advice(res == 1, opts);
		rerere(opts->allow_rerere_auto);
		goto leave;
	}

	allow = allow_empty(opts, commit);
	if (allow < 0) {
		res = allow;
		goto leave;
	}
	if (!opts->no_commit)
		res = run_git_commit(defmsg, opts, allow);

leave:
	free_message(&msg);
	free(defmsg);

	return res;
}
void BeanSerialTransport::BTSetTxPower(const BT_TXPOWER_DB_T& power){
  write_message(MSG_ID_BT_SET_TX_PWR, (const uint8_t*)&power, sizeof(BT_TXPOWER_DB_T));
}
void* set_value_thread(void *context)
{
	sensor_context *sensor = NULL;
	message msg;
	int return_value;
	char *tokens[10];
	char line[LINE_MAX];
	int count = 0;
	int start, end, value;

	sensor = (sensor_context*)context;

	msg.type = CURRENT_VALUE;
	while(sensor->run)
	{
		if(!(start <= sensor->clock && sensor->clock < end))
		{
			/* Figure out the value from file */
			if(fgets(line, LINE_MAX, sensor->sensor_value_file_pointer) == NULL)
			{
				LOG_DEBUG(("DEBUG: Seeking to beginning of file"));
				rewind(sensor->sensor_value_file_pointer);
				sensor->clock = 0;
				continue;
			}

			str_tokenize(line, ";\n\r", tokens, &count);
			if(count != 3)
			{
				LOG_ERROR(("ERROR: Wrong sensor temperature value file\n"));
				break;
			}

			start = atoi(tokens[0]);
			end = atoi(tokens[1]);
			if(strcmp (tokens[2], "true") == 0)
			{
				value = 1; 
			}
			else
			{
				value = 0;
			}
			sensor->value = value;
		}

		msg.u.value = sensor->value;
		msg.timestamp = time(NULL);

		pthread_mutex_lock(&sensor->mutex_lock);

		sensor->logical_clock[2]++;
		LOG_SCREEN(("INFO: Event Sent, "));
		LOG_INFO(("INFO: Event Sent, "));
		print_logical_clock_to_screen(sensor->logical_clock);
		print_logical_clock(sensor->logical_clock);
		LOG_INFO(("timestamp: %lu, Motion: %s\n", msg.timestamp, tokens[2]));
		LOG_SCREEN(("timestamp: %lu, Motion: %s\n", msg.timestamp, tokens[2]));
		return_value = write_message(sensor->socket_fd, sensor->logical_clock, &msg);
		if(E_SUCCESS != return_value)
		{
			LOG_ERROR(("ERROR: Error in sending sensor temperature value to gateway\n"));
		}

		for(int index=0; index<sensor->send_peer_count; index++)
		{
			return_value = write_message(sensor->send_peer[index]->comm_socket_fd,
					sensor->logical_clock,
					&msg);
			if(E_SUCCESS != return_value)
			{
				LOG_ERROR(("ERROR: Error in sending sensor temperature value to peer\n"));
			}
		}
		pthread_mutex_unlock(&sensor->mutex_lock);

		sleep(sensor->interval);
		sensor->clock += sensor->interval;
	}

	LOG_DEBUG(("Exiting SetValueThread...\n"));
	return (NULL);
}
void BeanSerialTransport::BTSetScratchChar(BT_SCRATCH_T* setting, uint8_t length){
  write_message(MSG_ID_BT_SET_SCRATCH, (uint8_t*)setting, (size_t)length);
};
Пример #17
0
void set_color(int fd, const char * color_code) {
    write_message(fd, code_FS);
    write_message(fd, color_code);
    
}
void BeanSerialTransport::accelRangeSet( uint8_t range )
{
  write_message(MSG_ID_CC_ACCEL_SET_RANGE, (const uint8_t *)&range, sizeof(range));
}
Пример #19
0
void set_font(int fd, const char * font_code) {
    write_message(fd, SELECT_CHAR_SET);
    write_message(fd, font_code);
    
}
void BeanSerialTransport::enableWakeOnConnect( bool enable )
{
  uint8_t enableBuff = (enable == true ) ? 1 : 0;

  write_message(MSG_ID_AR_WAKE_ON_CONNECT, (const uint8_t *)&enableBuff, sizeof(enableBuff));
}
Пример #21
0
static int do_pick_commit(void)
{
	unsigned char head[20];
	struct commit *base, *next, *parent;
	const char *base_label, *next_label;
	struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
	char *defmsg = NULL;
	struct strbuf msgbuf = STRBUF_INIT;
	int res;

	if (no_commit) {
		/*
		 * We do not intend to commit immediately.  We just want to
		 * merge the differences in, so let's compute the tree
		 * that represents the "current" state for merge-recursive
		 * to work on.
		 */
		if (write_cache_as_tree(head, 0, NULL))
			die (_("Your index file is unmerged."));
	} else {
		if (get_sha1("HEAD", head))
			die (_("You do not have a valid HEAD"));
		if (index_differs_from("HEAD", 0))
			die_dirty_index(me);
	}
	discard_cache();

	if (!commit->parents) {
		parent = NULL;
	}
	else if (commit->parents->next) {
		/* Reverting or cherry-picking a merge commit */
		int cnt;
		struct commit_list *p;

		if (!mainline)
			die(_("Commit %s is a merge but no -m option was given."),
			    sha1_to_hex(commit->object.sha1));

		for (cnt = 1, p = commit->parents;
		     cnt != mainline && p;
		     cnt++)
			p = p->next;
		if (cnt != mainline || !p)
			die(_("Commit %s does not have parent %d"),
			    sha1_to_hex(commit->object.sha1), mainline);
		parent = p->item;
	} else if (0 < mainline)
		die(_("Mainline was specified but commit %s is not a merge."),
		    sha1_to_hex(commit->object.sha1));
	else
		parent = commit->parents->item;

	if (allow_ff && parent && !hashcmp(parent->object.sha1, head))
		return fast_forward_to(commit->object.sha1, head);

	if (parent && parse_commit(parent) < 0)
		/* TRANSLATORS: The first %s will be "revert" or
		   "cherry-pick", the second %s a SHA1 */
		die(_("%s: cannot parse parent commit %s"),
		    me, sha1_to_hex(parent->object.sha1));

	if (get_message(commit->buffer, &msg) != 0)
		die(_("Cannot get commit message for %s"),
				sha1_to_hex(commit->object.sha1));

	/*
	 * "commit" is an existing commit.  We would want to apply
	 * the difference it introduces since its first parent "prev"
	 * on top of the current HEAD if we are cherry-pick.  Or the
	 * reverse of it if we are revert.
	 */

	defmsg = git_pathdup("MERGE_MSG");

	if (action == REVERT) {
		base = commit;
		base_label = msg.label;
		next = parent;
		next_label = msg.parent_label;
		strbuf_addstr(&msgbuf, "Revert \"");
		strbuf_addstr(&msgbuf, msg.subject);
		strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
		strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));

		if (commit->parents && commit->parents->next) {
			strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
			strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
		}
		strbuf_addstr(&msgbuf, ".\n");
	} else {
		base = parent;
		base_label = msg.parent_label;
		next = commit;
		next_label = msg.label;
		add_message_to_msg(&msgbuf, msg.message);
		if (no_replay) {
			strbuf_addstr(&msgbuf, "(cherry picked from commit ");
			strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
			strbuf_addstr(&msgbuf, ")\n");
		}
		if (!no_commit)
			write_cherry_pick_head();
	}

	if (!strategy || !strcmp(strategy, "recursive") || action == REVERT) {
		res = do_recursive_merge(base, next, base_label, next_label,
					 head, &msgbuf);
		write_message(&msgbuf, defmsg);
	} else {
		struct commit_list *common = NULL;
		struct commit_list *remotes = NULL;

		write_message(&msgbuf, defmsg);

		commit_list_insert(base, &common);
		commit_list_insert(next, &remotes);
		res = try_merge_command(strategy, xopts_nr, xopts, common,
					sha1_to_hex(head), remotes);
		free_commit_list(common);
		free_commit_list(remotes);
	}

	if (res) {
		error(action == REVERT
		      ? _("could not revert %s... %s")
		      : _("could not apply %s... %s"),
		      find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
		      msg.subject);
		print_advice();
		rerere(allow_rerere_auto);
	} else {
		if (!no_commit)
			res = run_git_commit(defmsg);
	}

	free_message(&msg);
	free(defmsg);

	return res;
}