Exemplo n.º 1
0
int main () {

    /* char *path1 = "/home/andy/mydir"; */
    /* char *path2 = "/home/andy/thoughts"; */

    int path1Len = strlen("/home/andy/mydir");
    int path2Len = strlen("/home/andy/thoughts");
    char *path1 = (char *)malloc(path1Len + 1);
    char *path2 = (char *)malloc(path2Len + 1);
    path1[path1Len] = '\0';
    path2[path2Len] = '\0';

    memcpy(path1,"/home/andy/mydir", path1Len);
    memcpy(path2,"/home/andy/thoughts", path2Len);

    int wd1 = 5;
    int wd2 = 7;

    add_tracker(wd1, path1);
    add_tracker(wd2, path2);

    printf("Second path: %s\n", get_tracker(wd2));

    char *path = delete_tracker(wd2);
    printf("returned path = %s\n", path);

    printf("first path: %s\n", get_tracker(wd1));

    delete_tracker(wd1);

    free(path2);

    return 0;

}
Exemplo n.º 2
0
int add_to_queue(list_t *list, uint8_t *buf, const int buf_size, ssize_t bytes_read) {

  struct inotify_event *event = NULL;
  const static int event_size = sizeof(struct inotify_event);
  uint32_t name_length = 0;
  uint8_t *pos = buf;
  int num_events = 0;
  
  ssize_t processed_bytes = 0;

  if (event_size * (bytes_read / event_size) != bytes_read)
    fprintf(log_file, "Sanity check failed: The number of bytes in the queue contains a partial event. Bytes = %zd\n", bytes_read);

  while (processed_bytes < bytes_read) {
    name_length = ((struct inotify_event *)pos)->len;
    event = (struct inotify_event *) malloc (event_size + name_length);

    print("event struct + length = %d\n", event_size + name_length);
    memcpy(event, pos, event_size + name_length);
    
    pos += event_size + name_length;
    processed_bytes += event_size + name_length;
    print("processed_bytes = %zd, bytes_read = %zd, event_size = %d\n", processed_bytes, bytes_read, event_size);

    append_item(list, event);

    num_events++;

    if (event->mask & IN_MODIFY)
      print("Inotify: Modify event.\n");
    else if (event->mask & IN_ATTRIB)
      print("Inotify: Attribute event.\n");
    else if (event->mask & IN_MOVED_FROM) {
      print("Inotify: Move out event.\n");
      print("Event name length: %d\n", event->len);
      print("Event: %s\n", event->name);
      print("Tracker path: %s, wd = %d\n", get_tracker(event->wd), event->wd);
    }
    else if (event->mask & IN_MOVED_TO) {
      print("Inotify: Move in event.\n");
      print("Event name length: %d\n", event->len);
      print("Event: %s\n", event->name);
      print("Tracker path: %s, wd = %d\n", get_tracker(event->wd), event->wd);
    }
    else if (event->mask & IN_CREATE) {
      print("Inotify: Create event.\n");
      print("Event name length: %d\n", event->len);
      print("Event: %s\n", event->name);
    }
    else if (event->mask & IN_DELETE) {
      print("Inotify: Delete event.\n");
    }
    else {
      print("Unknown event.\n");
    }
  }

  return num_events;
}
Exemplo n.º 3
0
void download(){
    
    /***1.we need to where our file's tracker should be stored***/
    query();
    //printf("Step 1 finished\n");
    
    if(rep_flag==0){
        /***2.we need to query from chord to get tracker information***/
        get_tracker();
        //printf("Step 2 finished\n");
        //debug_info();
    
        /***3.contact to the peers to get different pieces***/
        request_pieces();
        //printf("Step 3 finished\n");
        
        /***4.combine different pieces to a whole***/
        combine_pieces();
        //printf("Step 4 finished\n");
        
        /***5.update tracker information***/
        update_tracker();
        //printf("Step 5 finished\n");
    }
    else{
        printf("You have already downloaded this file. You don't need to download it again!\n");
    }
    
    /***6.garbage collection***/
    reset();
    //printf("Step 6 finished\n");
}
Exemplo n.º 4
0
void vrpn_Tracker_ViewPoint::get_report()
{
    // Get a time stamp
    struct timeval current_time;
    vrpn_gettimeofday(&current_time, NULL);

    // Set the time stamp for each device type
    vrpn_Tracker::timestamp = current_time;
    vrpn_Analog::timestamp = current_time;

	// Get tracker and analog data
	get_tracker();
	get_analog();	
}
Exemplo n.º 5
0
static void foreach_enum_trackers(gpointer data, gpointer user)
{
    enum_trackers_state_t *state = user;
    GArray *str = g_array_new (FALSE, FALSE, sizeof (data));
    g_array_append_vals(str, data, 5);
    fitbitd_tracker_t *tracker;
    GValue *val_serial;
    GValue *val_state;
    GValue *val_sync_age;
    GValue *val_tracker_id;
    GValue *val_user_id;
    guint tracker_state;
    guint sync_age;
    GDateTime *time_now;

    val_serial = g_array_index(str, GValue *, 0);
    val_state = g_array_index(str, GValue *, 1);
    val_sync_age = g_array_index(str, GValue *, 2);
    val_tracker_id = g_array_index(str, GValue *, 3);
    val_user_id = g_array_index(str, GValue *, 4);

    if (!val_serial || !val_state || !val_sync_age || !val_tracker_id || !val_user_id) {
        g_printerr("Missing tracker values\n");
        return;
    }

    tracker = get_tracker(g_value_get_string(val_serial));
    if (!tracker) {
        g_printerr("No tracker record\n");
        return;
    }

    tracker_state = g_value_get_uint(val_state);
    tracker->sync_active = !!(tracker_state & (1 << 0));

    sync_age = g_value_get_uint(val_sync_age);
    time_now = g_date_time_new_now_local();
    if (tracker->sync_time)
        g_date_time_unref(tracker->sync_time);
    tracker->sync_time = g_date_time_add_seconds(time_now, -(gdouble)sync_age);
    g_date_time_unref(time_now);

    strncpy(tracker->id, g_value_get_string(val_tracker_id), sizeof(tracker->id));
    strncpy(tracker->user_id, g_value_get_string(val_user_id), sizeof(tracker->user_id));

    state->callback(tracker, state->user);
}
Exemplo n.º 6
0
/*
 * Process a program configuration message
 */
boolean ProgramManager::handle_msg(msg_program_t *msg) {
  DEBUG4_VALUE("handle_msg: program=", msg->type);
  DEBUG4_VALUELN(" output=", msg->hdr.output);

  /* Find the program to be executed */
  byte program = lookup_function(msg->type);
  if (program == NO_PROGRAM) {
    DEBUG1_VALUELN("handle_msg: invalid type: ", msg->type);
    return false;
  }

  /* Setup the tracker */
  int starting_output, stop_output;

  if (msg->hdr.output == HMTL_ALL_OUTPUTS) {
    /* This should be applied to all outputs that can handle the message type */
    starting_output = 0;
    stop_output = num_outputs;
  } else if (msg->hdr.output > num_outputs) {
    DEBUG1_VALUELN("handle_msg: invalid output: ",
                   msg->hdr.output);
    return false;
  } else if (outputs[msg->hdr.output] == NULL) {
    DEBUG1_VALUELN("handle_msg: NULL output: ", msg->hdr.output);
    return false;
  } else {
    /* Only apply to the specified output */
    starting_output = msg->hdr.output;
    stop_output = starting_output + 1;
  }

  for (int output = starting_output; output < stop_output; output++) {

    if (outputs[output] == NULL)
      continue;

    if (msg->type == HMTL_PROGRAM_NONE) {
      /* This is a message to clear the existing program so free the tracker */
      DEBUG3_VALUELN("handle_msg: clear ", output);
      free_tracker(output);
      continue;
    }

    program_tracker_t *tracker;
    if (functions[program].program == NULL) {
      /*
       * This is an initialization-only command, set tracker to null
       */
      DEBUG4_PRINTLN("handle_msg: trackerless")
      tracker = NULL;
    } else {
      /* If there was an active program on this output then clear the tracker */
      free_tracker(output);

      /* Setup a tracker for this program */
      tracker = get_tracker(output);
      tracker->program_index = program;
      tracker->flags = 0x0;
    }

    if (tracker) {
      // Record the output and object in the tracker
      tracker->output = outputs[output];
      tracker->object = objects[output];
    }

    /* Attempt to setup the program */


    boolean success = functions[program].setup(msg, tracker, outputs[output],
                                               objects[output], this);

    if (!success) {
      if (tracker) {
        DEBUG4_VALUELN("handle_msg: NA on ", output);
        free_tracker(output);
      }
      continue;
    }
    DEBUG4_VALUELN("handle_msg: setup on ", output);
  }

  return true;
}