trick/trick_source/sim_services/MonteCarlo/MonteCarlo_slave_init.cpp
Alex Lin 19025d77ad Standardize directory names
Reorganized.  Created a new top level include directory that will hold all of Trick's header files. Moved all of the Trick headers to this directory.  Created a libexec directory that holds all of the executables that users don't need to execute directly.  Changed all of the executables remaining in bin to start with "trick-".  In the sim_services directories changed all source files to find the Trick headers in their new location.  Since all of the include files are gone in sim_services, removed the src directories as well, moving all of the source files up a level.  Moved the makefiles, docs, man, and other architecture independent files into a top level share directory.  Renamed lib_${TRICK_HOST_CPU} to lib64 or lib depending on the platform we're currently on.

refs #63
2015-06-09 08:44:42 -05:00

66 lines
2.3 KiB
C++

#include <sys/stat.h>
#include <libgen.h>
#include "trick/MonteCarlo.hh"
#include "trick/command_line_protos.h"
#include "trick/message_proto.h"
#include "trick/message_type.h"
#include "trick/tc_proto.h"
/** @par Detailed Design: */
int Trick::MonteCarlo::slave_init() {
/** <ul><li> Construct the run directory. */
run_directory = std::string(command_line_args_get_output_dir());
if (access(run_directory.c_str(), F_OK) != 0) {
if (mkdir(run_directory.c_str(), 0775) == -1) {
if (verbosity >= ERROR) {
message_publish(MSG_ERROR, "Monte [%s:%d] : Unable to create directory %s.\nTerminating.\n",
run_directory.c_str(), machine_name.c_str(), slave_id) ;
}
exit(-1);
}
}
/** <li> Run the slave initialization jobs. */
run_queue(&slave_init_queue, "in slave_init queue") ;
/** <li> Initialize the sockets. */
tc_error(&listen_device, 0);
tc_error(&connection_device, 0);
tc_error(&data_listen_device, 0);
tc_error(&data_connection_device, 0);
socket_init(&listen_device);
listen_device.disable_handshaking = TC_COMM_TRUE;
/** <li> Connect to the master and write the port over which we are listening for new runs. */
if (tc_connect(&connection_device) != TC_SUCCESS) {
if (verbosity >= ERROR) {
message_publish(MSG_ERROR, "Monte [%s:%d] : Failed to initialize communication sockets.\nTerminating.\n",
machine_name.c_str(), slave_id) ;
}
exit(-1);
}
if (verbosity >= ALL) {
message_publish(MSG_INFO, "Monte [%s:%d] : Making initial connection with Master.\n",
machine_name.c_str(), slave_id) ;
}
int id = htonl(slave_id);
tc_write(&connection_device, (char *)&id, (int)sizeof(id));
char hostname[HOST_NAME_MAX];
gethostname(hostname, sizeof(hostname)-1);
int num_bytes = htonl(strlen(hostname));
tc_write(&connection_device, (char *)&num_bytes, (int)sizeof(num_bytes));
tc_write(&connection_device, hostname, strlen(hostname));
int listen_port = htonl(listen_device.port);
tc_write(&connection_device, (char *)&listen_port, (int)sizeof(listen_port));
tc_disconnect(&connection_device);
return 0;
}