/* * Write a message into the status file. */ static void upstat(struct printer *pp, const char *msg, int notifyuser) { int fd; char statfile[MAXPATHLEN]; status_file_name(pp, statfile, sizeof statfile); umask(0); seteuid(euid); fd = open(statfile, O_WRONLY|O_CREAT|O_EXLOCK, STAT_FILE_MODE); seteuid(uid); if (fd < 0) { printf("\tcannot create status file: %s\n", strerror(errno)); return; } (void) ftruncate(fd, 0); if (msg == (char *)NULL) (void) write(fd, "\n", 1); else (void) write(fd, msg, strlen(msg)); (void) close(fd); if (notifyuser) { if ((msg == (char *)NULL) || (strcmp(msg, "\n") == 0)) printf("\tstatus message is now set to nothing.\n"); else printf("\tstatus message is now: %s", msg); } }
Socket* set_up_connection__gui( Robot_location& robot_location_a, Robot_location& robot_location_b, Targets_manager* target_configurations_manager_ptr) { int host_port_g = 1103; int conenctions = 1; std::cout <<"in main thread : " <<boost::this_thread::get_id()<<std::endl; std::cout <<"before connecting to gui "<<std::endl<<std::endl; Socket_server server_g(host_port_g, conenctions); //here gui should be executed Socket* socket_g=server_g.accept(); std::cout <<"connected to gui"<<std::endl; std::stringstream initial_command; initial_command << configuration.get_workspace_file_name()<<" "; //workspace filename initial_command << configuration.get_robot_file_name_a()<<" "; //robot filename initial_command << configuration.get_all_target_configurations_file_name()<<" "; //query filename socket_g->send_line(initial_command.str().c_str()); //now send intial placements of each robot double x_a = CGAL::to_double(robot_location_a.get().get_location().x()); double y_a = CGAL::to_double(robot_location_a.get().get_location().y()); double t_a = robot_location_a.get().get_rotation().to_angle(); double x_b = CGAL::to_double(robot_location_b.get().get_location().x()); double y_b = CGAL::to_double(robot_location_b.get().get_location().y()); double t_b = robot_location_b.get().get_rotation().to_angle(); std::string path_file_name("initial_location.txt"); ofstream path_os(path_file_name.c_str()); path_os << 2 <<std::endl; //initial location path_os << x_a <<" " << y_a <<" " << t_a <<" " << x_b <<" " << y_b <<" " << t_b <<std::endl; //no movement path_os << 0 <<" " << 0 <<" " << 0 <<" " << 0 <<" " << 0 <<" " << 0 <<" " << 0 <<" " << std::endl; //get motion status and write to file std::string status_file_name("initial_status.txt"); ofstream status_os(status_file_name.c_str()); //get status Int_vec configuration_status; target_configurations_manager_ptr->get_configuration_status(configuration_status); //write status to file status_os <<"2" <<std::endl; //one entry status_os <<0<<std::endl; //before motion for (unsigned int i(0); i < configuration_status.size(); ++i) status_os <<configuration_status[i]<<" "; status_os <<1<<std::endl; //after motion for (unsigned int i(0); i < configuration_status.size(); ++i) status_os <<configuration_status[i]<<" "; status_os <<std::endl; std::stringstream path_update; path_update << path_file_name << " "; //path to draw filename path_update << status_file_name << " "; //state to draw filename socket_g->send_line(path_update.str().c_str()); return socket_g; }