Merge branch 'master' of github:szmoore/MCTX3420
authorSam Moore <[email protected]>
Sat, 19 Oct 2013 15:40:22 +0000 (23:40 +0800)
committerSam Moore <[email protected]>
Sat, 19 Oct 2013 15:40:22 +0000 (23:40 +0800)
Conflicts:
server/control.c

1  2 
server/actuator.c
server/common.h
server/control.c
server/control.h
server/fastcgi.c
server/main.c
server/options.h
server/sensor.c

Simple merge
diff --cc server/common.h
  #include "control.h"
  
  /**Converts a timeval to a double**/
 -#define TIMEVAL_TO_DOUBLE(tv) ((tv).tv_sec + 1e-6 * ((tv).tv_usec))
 +#define TIMEVAL_TO_DOUBLE(tv) ((tv).tv_sec + 1e-9 * ((tv).tv_nsec))
  /**Takes the tv1-tv2 between two timevals and returns the result as a double*/
 -#define TIMEVAL_DIFF(tv1, tv2) ((tv1).tv_sec - (tv2).tv_sec + 1e-6 * ((tv1).tv_usec - (tv2).tv_usec))
 -
 +#define TIMEVAL_DIFF(tv1, tv2) ((tv1).tv_sec - (tv2).tv_sec + 1e-9 * ((tv1).tv_nsec - (tv2).tv_nsec))
 +/** Converts a double time value (in seconds) to a timespec **/
 +#define DOUBLE_TO_TIMEVAL(value, tv) {        \
 +                                                                              (tv)->tv_sec = (int)(value); \
 +                                                                              (tv)->tv_nsec = ((value) - (int)(value))*1e9; \
 +                                                                      }
  
  extern bool PathExists(const char * path);
+ extern bool DirExists(const char * path);
  
  
  
  typedef struct ControlData {
        ControlModes current_mode;
        pthread_mutex_t mutex;
 -      struct timeval start_time;
 +      struct timespec 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];
  } ControlData;
  
  ControlData g_controls = {CONTROL_STOP, PTHREAD_MUTEX_INITIALIZER, {0}};
@@@ -192,18 -219,13 +219,13 @@@ const char* Control_SetMode(ControlMode
        else switch (desired_mode) {
                case CONTROL_START:
                        if (g_controls.current_mode == CONTROL_STOP) {
-                               const char * name = arg;
-                               if (!*name)
-                                       ret = "An experiment name must be specified";
-                               else if (strpbrk(name, INVALID_CHARACTERS))
-                                       ret = "The experiment name must not contain: " INVALID_CHARACTERS_JSON;
-                               else {
-                                       FILE *fp = fopen((const char*) arg, "a");
-                                       if (fp) {
-                                               fclose(fp);
-                                               clock_gettime(CLOCK_MONOTONIC, &(g_controls.start_time));
-                                       } else
-                                               ret = "Cannot open experiment name marker";
+                               const char * path = arg;
+                               if (mkdir(path, 0777) != 0 && errno != EEXIST) {
+                                       Log(LOGERR, "Couldn't create experiment directory %s - %s", 
+                                               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.";
Simple merge
@@@ -540,10 -554,10 +559,10 @@@ void * FCGI_RequestLoop (void *data
                
                if (module_handler) 
                {
 -                      if (module_handler != Login_Handler && module_handler != IdentifyHandler && module_handler)
 -                      //if (false) // Testing
 +                      //if (module_handler != Login_Handler && module_handler != IdentifyHandler && module_handler)
 +                      if (false) // Testing
                        {
-                               if (!FCGI_HasControl(&context, cookie))
+                               if (!FCGI_HasControl(&context, control_key))
                                {
                                        FCGI_RejectJSON(&context, "Please login. Invalid control key.");
                                        continue;       
diff --cc server/main.c
@@@ -39,12 -32,10 +39,10 @@@ void ParseArguments(int argc, char ** a
        g_options.program = argv[0]; // program name
        g_options.verbosity = LOGDEBUG; // default log level
        // Set the main directory
-       if (getcwd(g_options.root_dir, sizeof(g_options.root_dir)) == NULL)
-               Fatal("Couldn't get current working directory - %s", strerror(errno));
+       //if (getcwd(g_options.root_dir, sizeof(g_options.root_dir)) == NULL)
+       //      Fatal("Couldn't get current working directory - %s", strerror(errno));
  
 -      gettimeofday(&(g_options.start_time), NULL); // Start time
 +      clock_gettime(CLOCK_MONOTONIC, &(g_options.start_time)); // Start time
  
  
        g_options.auth_method = AUTH_NONE;  // Don't use authentication
Simple merge
diff --cc server/sensor.c
@@@ -303,10 -292,9 +307,9 @@@ void Sensor_EndResponse(FCGIContext * c
   */
  void Sensor_Handler(FCGIContext *context, char * params)
  {
 -      struct timeval now;
 -      gettimeofday(&now, NULL);
 +      struct timespec now;
 +      clock_gettime(CLOCK_MONOTONIC, &now);
        double current_time = TIMEVAL_DIFF(now, *Control_GetStartTime());
        int id = 0;
        const char * name = "";
        double start_time = 0;

UCC git Repository :: git.ucc.asn.au