X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fcontrol.c;h=280a1323aba0d680252219fc53bac00f94e918eb;hb=3521cee9644bd955fd053c5b4ea173efd1e78fe8;hp=4342c8ccf5cf78331167c1c5883fca4a14c9cef1;hpb=cf4f872e4a4d739408bd2f0d71887d27ebe598c9;p=matches%2FMCTX3420.git diff --git a/server/control.c b/server/control.c index 4342c8c..280a132 100644 --- a/server/control.c +++ b/server/control.c @@ -11,17 +11,25 @@ #include #include +/** + * Control state information (start/stop/pause etc) + */ typedef struct ControlData { - ControlModes current_mode; - pthread_mutex_t mutex; - struct timeval start_time; - char user_name[31]; // The user who owns the currently running experiment - char experiment_dir[BUFSIZ]; //Directory for experiment - char experiment_name[BUFSIZ]; + ControlModes current_mode; /** Current experiment mode **/ + pthread_mutex_t mutex; /** Mutex to serialise access to control methods **/ + struct timespec start_time; /** Start time of current experiment **/ + char user_name[31]; /** The user who owns the currently running experiment **/ + char experiment_dir[BUFSIZ]; /** Directory for experiment **/ + char experiment_name[BUFSIZ]; /** Name of the current experiment **/ } ControlData; ControlData g_controls = {CONTROL_STOP, PTHREAD_MUTEX_INITIALIZER, {0}}; +/** + * Determines if a directory exists or not. + * @param path The path to check + * @return true iff the path exists + */ bool DirExists(const char *path) { DIR *dir = opendir(path); @@ -32,19 +40,9 @@ bool DirExists(const char *path) return false; } -bool PathExists(const char *path) -{ - FILE *fp = fopen(path, "r"); - if (fp) { - fclose(fp); - return true; - } - return false; -} - /** * Lists all experiments for the current user. - * @param The context to work in + * @param context The context to work in */ void ListExperiments(FCGIContext *context) { @@ -197,7 +195,7 @@ void Control_Handler(FCGIContext *context, char *params) { "%s", name); } - FCGI_AcceptJSON(context, "Ok", NULL); + FCGI_AcceptJSON(context, "Ok"); } } @@ -225,7 +223,7 @@ const char* Control_SetMode(ControlModes desired_mode, void * arg) path, strerror(errno)); ret = "Couldn't create experiment directory."; } else { - gettimeofday(&(g_controls.start_time), NULL); + clock_gettime(CLOCK_MONOTONIC, &(g_controls.start_time)); } } else ret = "Cannot start when not in a stopped state."; @@ -260,7 +258,6 @@ const char* Control_SetMode(ControlModes desired_mode, void * arg) /** * Gets a string representation of the current mode - * @param mode The mode to get a string representation of * @return The string representation of the mode */ const char * Control_GetModeName() { @@ -280,6 +277,6 @@ const char * Control_GetModeName() { * Gets the start time for the current experiment * @return the start time */ -const struct timeval* Control_GetStartTime() { +const struct timespec * Control_GetStartTime() { return &g_controls.start_time; }