示例#1
0
void ContactView::keyhoteeIdEdited(const QString& id)
{
  _last_validate = fc::time_point::now();
  ui->id_status->setText(tr("Looking up id...") );

  fc::async( [ = ](){
      fc::usleep(fc::microseconds(500 * 1000) );
      if (fc::time_point::now() > (_last_validate + fc::microseconds(500 * 1000)))
        lookupId();
    }
    );
}
示例#2
0
 /** starts a lookup timer that will send a query one second
  * after the most recent edit unless another character is
  * entered.
  */
 void validateId(const QString& id)
 {
   _complete = false;
   completeChanged();
   _last_validate = fc::time_point::now();
   _profile_nym_ui.id_warning->setText(tr("Checking availability of ID...") );
   fc::async( [ = ](){
                fc::usleep(fc::microseconds(500 * 1000) );
                if (fc::time_point::now() > (_last_validate + fc::microseconds(500 * 1000)) )
                  lookupId();
              }
              );
 }
示例#3
0
void EditContactDialog::validateId( const QString& id )
{
   /** TODO
    if( is_address( id ) )
   {
      _complete = true;
   }
   else
   */
   {
      _complete = false;
      //completeChanged();
      _last_validate = fc::time_point::now();
      ui->id_status->setText( tr( "Looking up id..." ) );
      fc::async( [=](){ 
          fc::usleep( fc::microseconds(500*1000) );
          if( fc::time_point::now() > (_last_validate + fc::microseconds(500*1000)) )
          {
             lookupId();
          }
      } );
   }
}
示例#4
0
void encodeExpToTab(char *outExp, char *outSeries, char *outResults)
/* encodeExpToCvDb - Convert encode experiments table to a table more suitable for cvDb. */
{
struct hash *optHash = optionalFieldsHash();
struct mdbObj *mdbList = getMdbList(metaDbs, ArraySize(metaDbs));
struct hash *mdbHash = mdbHashKeyedByExpId(mdbList);
struct hash *seriesHash = hashNew(0);
struct series *seriesList = NULL;
verbose(1, "read %d mdb objects from %s in %d databases\n", mdbHash->elCount, metaTable, 
    (int)ArraySize(metaDbs));
struct sqlConnection *expDbConn = sqlConnect(expDb);
struct sqlConnection *cvDbConn = sqlConnect(cvDb);
char query[256];
sqlSafef(query, sizeof(query), "select * from %s", expTable);
struct sqlResult *sr = sqlGetResult(expDbConn, query);
FILE *f = mustOpen(outExp, "w");
char **row;
while ((row = sqlNextRow(sr)) != NULL)
    {
    /* Read in database structure. */
    struct encodeExp *ee = encodeExpLoad(row);
    
    /* Much of the data we're processing comes from lists of the form 
     * "a=aVal b=bVal c=cVal." We'll convert these to id's in the appropriate 
     * tables and store the IDs in the optCol array declared below.  */
    int optColCount = ArraySize(expOptionalFields);
    int optCol[optColCount];
    int i;
    for (i=0; i<optColCount; ++i)
	optCol[i] = 0;

    /* Convert var=val string in encodeExp.expVars into list of slPairs, and loop through it. */
    struct slPair *varList = slPairListFromString(ee->expVars, TRUE);
    struct slPair *var;
    for (var = varList; var != NULL; var = var->next)
	 {
	 /* Figure out name of table and the term within that table. */
	 char *table = var->name;
	 char *term = var->val;
	 if (sameString(table, "antibody")) // Deal with antibody special case
	    {
	    if (sameString(term, "Control") || sameString(term, "Input") 
	    || sameString(term, "RevXlinkChromatin") || sameString(term, "ripInput"))
		{
		table = "control";
		}
	    }

	 /* If it looks like we have a valid table and term, store result in
	  * optCol array we'll output soon. */
	 struct hashEl *hel;
	 if ((hel = hashLookup(optHash, table)) != NULL)
	     {
	     int id = lookupId(cvDbConn, table, term);
	     if (id == 0)
		  {
	          warn("No id in cvDb for %s=%s\n", table, term);
		  continue;
		  }
	     int optColIx = ptToInt(hel->val);
	     optCol[optColIx] = id;
	     }
	 else
	     verbose(2, "%s %s ?\n", table, term);
	 }

    /* Now we want to process metaDb, which has some info encodeExp does not. */
    char *composite = NULL;
    char ixAsString[16];
    safef(ixAsString, sizeof(ixAsString), "%d", ee->ix);
    struct mdbObj *mdb = hashFindVal(mdbHash, ixAsString);
    if (mdb != NULL)
	{
	struct mdbVar *v;
	for (v = mdb->vars; v != NULL; v = v->next)
	    {
	    /* Look up table and term and change table name if need be */
	    char *table = v->var;
	    char *term = v->val;
	    if (sameString(table, "antibody")) 
		 table = "ab";
	    else if (sameString(table, "grant"))
	         table = "grantee";

	    /* Squirrel away the ever-important composite term for later. */
	    if (sameString("composite", table))
	         composite = term;

	    struct hashEl *hel;
	    if ((hel = hashLookup(optHash, table)) != NULL)
		{
		int optColIx = ptToInt(hel->val);
		if (optCol[optColIx] == 0)  // Only use mdb if encodeExp has no data.
		    {
		    int id = lookupId(cvDbConn, table, term);
		    optCol[optColIx] = id;
		    }
		}
	    }
	}

    /* If we've got a composite, then make up a series record. */
    if (composite != NULL)
        {
	assert(mdb != NULL);
	struct series *series = hashFindVal(seriesHash, composite);
	if (series == NULL)
	    {
	    series = seriesFromMdb(mdb, composite);
	    hashAdd(seriesHash, composite, series);
	    slAddHead(&seriesList, series);
	    }
	}

    if (ee->accession != NULL)
	{
	/* Write out required fields.  Order of required fields
	 * here needs to follow order in expRequiredFields. */
	fprintf(f, "%u", ee->ix);
	fprintf(f, "\t%s", ee->updateTime);
	fprintf(f, "\t%s", naForNull(composite));
	fprintf(f, "\t%s", ee->accession);
	fprintf(f, "\t%d", lookupId(cvDbConn, "organism", ee->organism));
	fprintf(f, "\t%d", lookupId(cvDbConn, "lab", ee->lab));
	fprintf(f, "\t%d", lookupId(cvDbConn, "dataType", ee->dataType));
	fprintf(f, "\t%d", lookupId(cvDbConn, "cellType", ee->cellType));

	/* Now write out optional fields. */
	for (i=0; i<optColCount; ++i)
	    fprintf(f, "\t%d", optCol[i]);

	/* End output record. */
	fprintf(f, "\n");
	}
    }

/* Write out series list to a separate file. */
slReverse(&seriesList);
writeSeriesList(outSeries, seriesList);

/* Write out results to a separate file. */
writeMdbListAsResults(mdbList, outResults);

/* Clean up and go home. */
carefulClose(&f);
sqlFreeResult(&sr);
sqlDisconnect(&expDbConn);
sqlDisconnect(&cvDbConn);
}
示例#5
0
void runClient(int sockfd, const char* server, unsigned port)
{
  char input[BUFFER_SIZE];
  char output = CLI_EXIT_MSG;
  char* idStr = NULL;
  char* data = NULL;
  unsigned id = 0;
  unsigned countId = 0;
  int numDigits = 0;
  fd_set fds;
  
  if(sockfd == -1)
    return;

  FD_ZERO(&fds);

  printf(WELCOME_MSG, server, port);

  while(1) {
    FD_SET(sockfd, &fds);

    fgets(input, BUFFER_SIZE, stdin);

    if(strncasecmp("help", input, strlen("help")) == 0) {
      printf(HELP_MSG);
    } else if(strlen(input) > 6) {
      input[6] = '\0'; /* All commands should have a space here */
      idStr = input+7;
      id = atoi(idStr);
      countId = id;

      /* Count number of char's for id */
      numDigits = 0;
      while(countId) { /* In base 10 */
        countId /= 10;
        numDigits++;
      }

      data = idStr + numDigits + 1; /* If needed */

      /* Determine what we want to do */
      if(strncasecmp(input, "insert", strlen("insert")) == 0) {
        output = CLI_INS_MSG;
      } else if(strncasecmp(input, "remove", strlen("remove")) == 0) {
        output = CLI_REM_MSG;
      } else if(strncasecmp(input, "lookup", strlen("lookup")) == 0) {
        output = CLI_FIND_MSG;
      }

      select(sockfd+1, NULL, &fds, NULL, NULL);
      sendData(sockfd, &output, sizeof(output));

      switch(output)
      {
        default:
          /* Do nothing */
          break;
        case CLI_INS_MSG:
          insertId(sockfd, id, data);
          break;
        case CLI_REM_MSG:
          removeId(sockfd, id);
          break;
        case CLI_FIND_MSG:
          /* Need to actually display this information if valid */
          lookupId(sockfd, id);
          break;
      }

    } else if(strncasecmp("exit", input, strlen("exit")) == 0) {
      output = CLI_EXIT_MSG;
      sendData(sockfd, &output, sizeof(output));
      break;
    } else {
      fprintf(stderr, "Unknown command\n");
    }
  }
}