int client(int *maxfds, fd_set *readfds, int *num_clients, client_data *fd_array, annuaireData *user, waitList *waitlist){ int sock_host; struct hostent *hostinfo; struct sockaddr_in address; int port = -1; char client_inaddr[INET_ADDRSTRLEN]; message *msg = (message *) malloc(sizeof(message)); //Si on ne peut pas recevoir le client if (*num_clients >= MAX_CLIENTS) { printf(BLUE"[Program] You tried to establish a connection with someone, but you are already connected to too many clients."RESET"\n\n"); return -1; } if(user != NULL){ hostinfo = ask_server_address(&port, user); }else{ printf(BLUE"\n[PROGRAM] *** Enter server's address : \"address:port\" ***\n[PROGRAM] Type \"/exit\" to interrupt."RESET"\n\n"); hostinfo = ask_server_address(&port, NULL); } /* Cas où l'utilisateur veut quitter la routine de connexion */ if(port == -1) { return -1; } sock_host = socket(AF_INET, SOCK_STREAM, 0); address.sin_addr = *(struct in_addr *)*hostinfo -> h_addr_list; address.sin_family = AF_INET; address.sin_port = htons(port); inet_ntop(AF_INET, &(address.sin_addr), client_inaddr, INET_ADDRSTRLEN); printf(BLUE"\n*** Attempt to establish a connection with "RED"%s:%i"BLUE" ***"RESET"\n\n", client_inaddr, port); /* Connection au serveur */ if(connect(sock_host, (struct sockaddr *)&address, sizeof(address)) < 0) { perror("Connect"); if (userInterface_fd > 0) { sendUiMsg("CONNECTERROR Client unreachable.\n",readfds,fd_array,num_clients); } return -1; } //gérer autrement car il ne faut pas quitter si on arrive pas a se co opt_desc(&sock_host, maxfds, readfds); session_initiate(msg); //génération du message de session-initiate send_msg(msg,&sock_host,readfds,fd_array,num_clients); ((*waitlist).nb_connect)++; /* Ajout de l'adresse socket du client auquel on se connecte à ses données */ memset(fd_array[*num_clients+(*waitlist).nb_connect].address_client, '\0', sizeof(fd_array->address_client)); strcpy(fd_array[*num_clients+(*waitlist).nb_connect].address_client, client_inaddr); fd_array[*num_clients+(*waitlist).nb_connect].fd_client = sock_host; (*waitlist).waiting[(*waitlist).nb_connect]=sock_host; free((*msg).msg_content); free(msg); return 0; }//main
irods::error parseProgramOptions( int _argc, char* _argv[], boost::program_options::variables_map &_vm ) { namespace po = boost::program_options; po::options_description opt_desc( "options" ); opt_desc.add_options() ( "help,h", "Show command usage" ) ( "test,t", "Test mode" ) ( "string,s", "String mode" ) ( "file,F", po::value< std::string >(), "Rule file" ) ( "list,l", "List file" ) ( "verbose,v", "Verbose output" ) ( "available,a", "List available rule engine instances" ) ( "rule-engine-plugin-instance,r", po::value< std::string >(), "Run rule on specified instance" ) ( "parameters", po::value< std::vector< std::string > >()->multitoken(), "Rule input/output parameters" ); po::positional_options_description pos_desc; pos_desc.add( "parameters", -1 ); try { po::store( po::command_line_parser( _argc, _argv ).options( opt_desc ).positional( pos_desc ).run(), _vm ); po::notify( _vm ); } catch (po::error& _e ) { rodsLog( LOG_ERROR, "Error in irule parseProgramOptions: [%s]", _e.what() ); std::cerr << std::endl << "Error: " << _e.what() << std::endl << std::endl; usage(/*std::cerr*/); return ERROR( SYS_INVALID_INPUT_PARAM, "Illegal command line argument" ); } return SUCCESS(); }
// currently only written to support iput. needs to be expanded to // support the full range of icommand options static int parse_program_options( int _argc, char** _argv, rodsArguments_t& _rods_args, path_list_t& _paths ) { namespace po = boost::program_options; po::options_description opt_desc( "options" ); opt_desc.add_options() ( "help,h", "show command usage" ) ( "all,a", "all - update all existing copies" ) ( "bulk,b", "bulk upload to reduce overhead" ) ( "force,f", "force - write data-object even it exists already; overwrite it" ) ( "redirect,I", "redirect connection - redirect the connection to connect directly to the resource server." ) ( "checksum,k", "checksum - calculate a checksum on the data server-side, and store it in the catalog" ) ( "verify_checksum,K", "verify checksum - calculate and verify the checksum on the data, both client-side and server-side, without storing in the catalog." ) ( "repl_num,n", po::value<std::string>(), "replNum - the replica to be replaced, typically not needed" ) ( "num_threads,N", po::value<int>(), "numThreads - the number of threads to use for the transfer. A value of 0 means no threading. By default (-N option not used) the server decides the number of threads to use.") ( "physical_path,p", po::value<std::string>(), "physicalPath - the absolute physical path of the uploaded file on the server" ) ( "progress,P", "output the progress of the upload." ) ( "rbudp,Q", "use RBUDP (datagram) protocol for the data transfer" ) ( "recursive,r", "recursive - store the whole subdirectory" ) ( "dest_resc,R", po::value<std::string>(), "resource - specifies the resource to store to. This can also be specified in your environment or via a rule set up by the administrator" ) ( "ticket,t", po::value<std::string>(), "ticket - ticket (string) to use for ticket-based access" ) ( "renew_socket,T", "renew socket connection after 10 minutes" ) ( "verbose,v", "verbose" ) ( "very_verbose,V", "very verbose" ) ( "data_type,D", po::value<std::string>(), "dataType - the data type string" ) ( "restart_file,X", po::value<std::string>(), "restartFile - specifies that the restart option is on and the restartFile input specifies a local file that contains the restart information." ) ( "link", "ignore symlink." ) ( "lfrestart", po::value<std::string>(), "lfRestartFile - specifies that the large file restart option is on and the lfRestartFile input specifies a local file that contains the restart information." ) ( "retries", po::value<int>(), "count - Retry the iput in case of error. The 'count' input specifies the number of times to retry. It must be used with the -X option" ) ( "wlock", "use advisory write (exclusive) lock for the upload" ) ( "rlock", "use advisory read lock for the download" ) ( "purgec", "Purge the staged cache copy after uploading an object to a" ) ( "kv_pass", po::value<std::string>(), "pass key-value strings through to the plugin infrastructure" ) ( "metadata", po::value<std::string>(), "atomically assign metadata after a data object is put" ) ( "acl", po::value<std::string>(), "atomically apply an access control list after a data object is put" ) ( "path_args", po::value<path_list_t>(&_paths)->composing(), "some files and stuffs" ); po::positional_options_description pos_desc; pos_desc.add( "path_args", -1 ); try { po::store( po::command_line_parser( _argc, _argv ).options( opt_desc ).positional( pos_desc ).run(), global_prog_ops_var_map ); po::notify( global_prog_ops_var_map ); } catch ( po::error& _e ) { std::cout << std::endl << "Error: " << _e.what() << std::endl << std::endl; usage(); return -1; } // path args are passed out in a separate parameter //if( global_prog_ops_var_map.count( "path_args" ) ) { //} memset( &_rods_args, 0, sizeof( _rods_args ) ); if( global_prog_ops_var_map.count( "help" ) ) { usage(); return -1; } if( global_prog_ops_var_map.count( "all" ) ) { _rods_args.all = 1; } if( global_prog_ops_var_map.count( "bulk" ) ) { _rods_args.bulk = 1; } if( global_prog_ops_var_map.count( "force" ) ) { _rods_args.bulk = 1; } if( global_prog_ops_var_map.count( "force" ) ) { _rods_args.force = 1; } if( global_prog_ops_var_map.count( "redirect" ) ) { _rods_args.redirectConn = 1; } if( global_prog_ops_var_map.count( "checksum" ) ) { _rods_args.checksum = 1; } if( global_prog_ops_var_map.count( "verify_checksum" ) ) { _rods_args.verifyChecksum = 1; } if( global_prog_ops_var_map.count( "" ) ) { _rods_args.verifyChecksum = 1; } if( global_prog_ops_var_map.count( "repl_num" ) ) { _rods_args.replNum = 1; try { _rods_args.replNumValue = (char*)global_prog_ops_var_map[ "repl_num" ].as<std::string>().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "num_threads" ) ) { _rods_args.number = 1; try { _rods_args.numberValue = global_prog_ops_var_map[ "num_threads" ].as<int>(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "physical_path" ) ) { _rods_args.physicalPath = 1; try { _rods_args.physicalPathString = (char*)global_prog_ops_var_map[ "physical_path" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "progress" ) ) { _rods_args.progressFlag = 1; } if( global_prog_ops_var_map.count( "rbudp" ) ) { _rods_args.rbudp = 1; } if( global_prog_ops_var_map.count( "recursive" ) ) { _rods_args.recursive = 1; } if( global_prog_ops_var_map.count( "dest_resc" ) ) { _rods_args.resource = 1; try { _rods_args.resourceString = (char*)global_prog_ops_var_map[ "dest_resc" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "ticket" ) ) { _rods_args.ticket = 1; try { _rods_args.ticketString = (char*)global_prog_ops_var_map[ "ticket" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "renew_socket" ) ) { _rods_args.reconnect = 1; } if( global_prog_ops_var_map.count( "verbose" ) ) { _rods_args.verbose = 1; } if( global_prog_ops_var_map.count( "very_verbose" ) ) { _rods_args.verbose = 1; _rods_args.veryVerbose = 1; rodsLogLevel( LOG_NOTICE ); } if( global_prog_ops_var_map.count( "data_type" ) ) { _rods_args.dataType = 1; try { _rods_args.dataTypeString = (char*)global_prog_ops_var_map[ "data_type" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "restart_file" ) ) { _rods_args.restart = 1; try { _rods_args.restartFileString = (char*)global_prog_ops_var_map[ "restart_file" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "link" ) ) { _rods_args.link = 1; } if( global_prog_ops_var_map.count( "lfrestart" ) ) { _rods_args.lfrestart = 1; try { _rods_args.lfrestartFileString = (char*)global_prog_ops_var_map[ "lfrestart" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "retries" ) ) { _rods_args.retries = 1; try { _rods_args.retriesValue = global_prog_ops_var_map[ "retries" ].as< int >(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "wlock" ) ) { _rods_args.wlock = 1; } if( global_prog_ops_var_map.count( "rlock" ) ) { _rods_args.rlock = 1; } if( global_prog_ops_var_map.count( "purgec" ) ) { _rods_args.purgeCache = 1; } if( global_prog_ops_var_map.count( "kv_pass" ) ) { _rods_args.kv_pass = 1; try { _rods_args.kv_pass_string = (char*)global_prog_ops_var_map[ "kv_pass" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "metadata" ) ) { try { _rods_args.metadata_string = (char*)global_prog_ops_var_map[ "metadata" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } if( global_prog_ops_var_map.count( "acl" ) ) { try { _rods_args.acl_string = (char*)global_prog_ops_var_map[ "acl" ].as< std::string >().c_str(); } catch ( const boost::bad_any_cast& ) { return INVALID_ANY_CAST; } } return 0; } // parse_program_options
int main(int argc, char* argv[]) { po::options_description opt_desc("Edge detection client. Available options"); opt_desc.add_options() ("dataset-path,d", po::value<std::string>()->default_value("../images/e1088_mag1_small"), "Specify path to dataset in Knossos format.") ("cross-section-x1", po::value<int>()->default_value(50), "Cross section dimensions. X coordinate of top-left corner.") ("cross-section-y1", po::value<int>()->default_value(50), "Cross section dimensions. Y coordinate of top-left corner.") ("cross-section-x2", po::value<int>()->default_value(320), "Cross section dimensions. X coordinate of bottom-right corner.") ("cross-section-y2", po::value<int>()->default_value(320), "Cross section dimensions. Y coordinate of bottom-right corner.") ("cross-section-z", po::value<int>()->default_value(120), "Cross section dimensions. Z coordinate of cross-section plane.") ("gaussian_sigma", po::value<float>()->default_value(0.8408964), "") ("sup_rad1", po::value<int>(), "") ("sup_rad2", po::value<int>(), "") ("thresh_high1", po::value<int>(), "") ("thresh_high2", po::value<int>(), "") ("thresh_diff1", po::value<int>(), "") ("thresh_diff2", po::value<int>(), "") ("ep1", po::value<float>(), "") ("ep2", po::value<float>(), "") ("ep3", po::value<float>(), "") ("thresh_ray", po::value<int>(), "") ("union_ray", po::value<int>(), "") ("print_compounds", po::value<bool>(), "") ("do_matching", po::value<bool>(), "") ; options opts(opt_desc, argc, argv); dataset d(opts.string_var("dataset-path")); image i = cross_section_z(d, opts.int_var("cross-section-x1"), opts.int_var("cross-section-x2"), opts.int_var("cross-section-y1"), opts.int_var("cross-section-y2"), opts.int_var("cross-section-z")); { std::cerr << "Exporting original image to output/edge-detection/original.pgm." << std::endl; pgm_export(i, boost::filesystem::path("../output/edge-detection/original.pgm")); } image magnified = gaussian(i, opts.float_var("gaussian_sigma")); { std::cerr << "Exporting blurred image to output/edge-detection/blurred.pgm." << std::endl; pgm_export(magnified, boost::filesystem::path("../output/edge-detection/blurred.pgm")); } { std::stringstream coords; coords << opts.int_var("cross-section-x1") << "#"; coords << opts.int_var("cross-section-x2") << "#"; coords << opts.int_var("cross-section-y1") << "#"; coords << opts.int_var("cross-section-y2") << "#"; coords << opts.int_var("cross-section-z") << "#"; int sup_rad1 = opts.int_var("sup_rad1"); int sup_rad2 = opts.int_var("sup_rad2"); int thresh_high1 = opts.int_var("thresh_high1"); int thresh_high2 = opts.int_var("thresh_high2"); int thresh_diff1 = opts.int_var("thresh_diff1"); int thresh_diff2 = opts.int_var("thresh_diff2"); for(int supp_radius = sup_rad1; supp_radius <= sup_rad2; supp_radius++) for(int thigh = thresh_high1; thigh <= thresh_high2; thigh += 10) for(int tlow = thigh-thresh_diff1; tlow <= thigh-thresh_diff2; tlow += 10) { image i_edge_detection; rgb_image i_before_join; rgb_image i_after_join; std::tie(i_edge_detection, i_before_join, i_after_join) = detect_edges(magnified,thigh,tlow,supp_radius,0, opts.float_var("ep1"), opts.float_var("ep2"), opts.float_var("ep3"), opts.bool_var("print_compounds"), opts.bool_var("do_matching"), opts.int_var("union_ray"), opts.int_var("thresh_ray"), coords.str() ); { std::stringstream ss; ss << "../output/edge-detection/edge_detection" << thigh << "_"<< tlow << "_" << supp_radius << ".pgm"; std::cerr << "Exporting image to " << ss.str() << std::endl; pgm_export(i_edge_detection, boost::filesystem::path(ss.str())); } { std::stringstream ss; ss << "../output/edge-detection/edge_detection" << thigh << "_"<< tlow << "_" << supp_radius << "before.ppm"; std::cerr << "Exporting image to " << ss.str() << std::endl; ppm_export(i_before_join, boost::filesystem::path(ss.str())); } { std::stringstream ss; ss << "../output/edge-detection/edge_detection" << thigh << "_"<< tlow << "_" << supp_radius << "after.ppm"; std::cerr << "Exporting image to " << ss.str() << std::endl; ppm_export(i_after_join, boost::filesystem::path(ss.str())); } } } std::cerr << "Program finished successfully." << std::endl; return 0; }
int main(int argc, char* argv[]) { po::options_description opt_desc("Image client reads cubes from dataset, and renders serie of images through the dataset."); opt_desc.add_options() ("dataset-path,d", po::value<std::string>()->default_value("../images/e1088_mag1_small"), "Specify path to dataset in Knossos format.") ("z-begin", po::value<int>()->default_value(0), "Loop through dataset z coordinate; initial value") ("z-end", po::value<int>()->default_value(10), "Loop through dataset z coordinate; limit value") ("cross-section-x1", po::value<int>()->default_value(0), "Cross section dimensions. X coordinate of top-left corner.") ("cross-section-y1", po::value<int>()->default_value(0), "Cross section dimensions. Y coordinate of top-left corner.") ("cross-section-x2", po::value<int>()->default_value(128), "Cross section dimensions. X coordinate of bottom-right corner.") ("cross-section-y2", po::value<int>()->default_value(128), "Cross section dimensions. Y coordinate of bottom-right corner.") ("out-dir", po::value<std::string>()->default_value("../output/image-client"), "Output directory.") ("out-filename", po::value<std::string>()->default_value("slice"), "Prefix of output filename. E.g. for out-filname=slice, the program will output slice1.pgm, slice2.pgm etc."); options opts(opt_desc, argc, argv); dataset d(opts.string_var("dataset-path")); for(int z = opts.int_var("z-begin"); z < opts.int_var("z-end"); z ++) { /*if(z % cube::dim == 0) { const int useless_z = (z / cube::dim) - 1; d.unload_z_lower_than(d.min_z + useless_z); }*/ std::cout << "Processing z coordinate " << z << std::endl; image i = cross_section_z(d, opts.int_var("cross-section-x1"), opts.int_var("cross-section-x2"), opts.int_var("cross-section-y1"), opts.int_var("cross-section-y2"), z); std::cout << "Successfully loaded image from grid" << std::endl; std::stringstream ss; ss << opts.string_var("out-dir") << "/" << opts.string_var("out-filename") << z << ".pgm"; pgm_export(i, boost::filesystem::path(ss.str())); std::cout << "Successfully exported slice of tissue to file " << ss.str() << "." << std::endl; } return 0; }