Esempio n. 1
0
void
on_message_recived(orfs_message_t *message)
{

	orfs_metadata_t metadata;
	locker_t *locker;

	locker = lock_acquire(message->file_name, LOCK_STATE | LOCK_EXISTS | LOCK_OPEN_RW );
	metadata_get(message->file_name, &metadata);

	if (message->type == ORFS_MESSAGE_CREATE_MODIFY) {
		if(metadata.state == ORFS_STATE_EMPTY) {
			if(!metadata.exists) {
				enque_action(ORFS_ACTION_RECEIVE, message);
			} else {
				if(!metadata.is_open && compare_ts(metadata.ts, message->ts)<0) {
					enque_action(ORFS_ACTION_RECEIVE, message);
				} else if(metadata.is_open && compare_ts(metadata.ts, message->ts)<0) {
					enque_action(ORFS_ACTION_COC, message);
				}
			}
		} else if(metadata.state == ORFS_STATE_RECEIVE && compare_ts(metadata.message.ts, message->ts)<0) {
			remove_action(message->file_name);
			enque_action(ORFS_ACTION_RECEIVE, message);
		} else if(metadata.state == ORFS_STATE_COC && compre_ts(metadata.message.ts, message->ts)<0) {
			remove_action(metadata);
			enqueue_action(ORFS_ACTION_COC, message);
		}
	} else { // message->type = ORFS_MESSAGE_DELETE
		if ( metadata.exists) {
			if (!metadata.is_open && compare_ts(metadata.ts, message->ts)<0) {
				if (metadata.state == ORFS_STATE_EMPTY || compare_ts(metadata.message.ts, message->ts)<0) {
					remove_file(metadata);
				}
			} else if (metadata.is_open ) {
				if (metadata.state == ORFS_STATE_EMPTY && compare_ts(metadata.ts, message->ts) <0) {
					enqueue_action(ORFS_ACTION_COC, message);
				} else if (metadata.state == ORFS_STATE_COC && compare_ts(metadata.message.ts, message->ts)<0) {
					remove_action(metadata);
					enqueue_action(ORFS_ACTION_COC, message);
				} else if (!metadata.is_open && metadata.state == ORFS_STATE_RECEIVE && compare_ts(metadata.message.ts, message->ts) <0) {
					remove_action(metadata);
					remove_file(metadata);
				}
			}
		}
	}

	lock_release(locker);
}
Esempio n. 2
0
void f_remove_action (void)
{
    long success;

    success = remove_action((sp - 1)->u.string, sp->u.string);
    free_string_svalue(sp--);
    free_string_svalue(sp);
    put_number(success);
}
Esempio n. 3
0
int do_cmd(string str) {
  object tp = this_player();
  int ret;

  if (cleaning) return 0;
  if (query_verb() == "quit") return 0;
  if (wizardp(tp) && query_verb() == "dest") return 0;

  if (environment(this_object()) != tp) return 0;

  if (!cmdob) return 0;
  if (!strlen(cmdfun)) return 0;

  ret = call_other(cmdob, cmdfun, str);

  if (ret == 0) return 0;

  if (!this_object()) return 1; // something removed us

  if (ret == -1 || (uses != -1 && --uses < 1)) {
    if (catchall)
      remove_action("do_cmd", "");
    else if (cmdword) {
      if (stringp(cmdword))
        remove_action("do_cmd", cmdword);
      else
        foreach (string word in cmdword)
          remove_action("do_cmd", word);
    }
    // can't remove the ob that defines the add_action you're running
    call_out("removeme", 0);
  }

  if (ret == -2) {
    cleaning = 1;
    return 0;
  }

  return 1;
}
Esempio n. 4
0
void do_tests() {
#ifndef __NO_ADD_ACTION__
    object tp;

    SAVETP;
    enable_commands();
    add_action( "func", "bar" );
    ASSERT(remove_action( "func", "bar" ));
    RESTORETP;
    command("bar");
    ASSERT(!called);
#endif
}
Esempio n. 5
0
int main_loop(Goods **m_t, pall **m_p){
  printf("\n\n========Warehouse1337 v1.0========\n");
  printf("Choose what action to perform;\n");
  printf("(A)dd an item.\n");
  printf("(R)emove an item.\n");
  printf("(L)ist all the items currently in the warehouse.\n");
  printf("(E)dit an item in the warehouse.\n");
  printf("(P)ut something in basket\n");
  printf("E(x)it the program.\n");
  char action;
  scanf("%s", &action);
  
  if (action == 'a' || action == 'A'){
    add_action(m_t);
    return main_loop(m_t, m_p);    
  }
  if (action == 'r' || action == 'R'){
    puts("You've chosen to Remove an item. To proceed, please;");
    remove_action(m_t);
    return main_loop(m_t, m_p);    
  }
  if (action == 'l' || action == 'L'){
    list_action(*m_t, 1);
    return main_loop(m_t, m_p);
    }
  if (action == 'e' || action == 'E'){
      edit_action(m_t);
      return main_loop(m_t, m_p);
  }
  if (action == 'p' || action == 'P'){
    pal_action(m_t, m_p);
    return main_loop(m_t, m_p);
  }
  if ((action == 'x' || action == 'X') && (quit_action() == false)){
    printf("Thank you for using the warehouse1337 v1.2 software.\n");
    free_loop(*m_t);
    free_loop_pall(*m_p);
    return 0;
  }
  else {
    puts("\nThat's not a valid option, please try again.");
    return main_loop(m_t, m_p);
  }
  return 0;
}
Esempio n. 6
0
/* Called when delete key is pressed */
static void delete_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
  /* Check if DEL key was pressed (keyval: 65535) */
  if (event->keyval == 65535)
    remove_action(NULL, NULL);
}