Exemplo n.º 1
0
int pull_all_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc)
{
    assert(cdata != NULL);
    assert(argc == 0 || argv != NULL);
    run_result_stream_t *results = (run_result_stream_t *)cdata;

    if (type == NEO4J_RECORD_MESSAGE)
    {
        if (append_result(results, argv, argc))
        {
            neo4j_log_trace_errno(results->logger, "append_result failed");
            set_failure(results, errno);
            return -1;
        }
        return 1;
    }

    --(results->refcount);
    results->streaming = false;

    // not a record, so keep this memory along with the result stream
    if (neo4j_mpool_merge(&(results->mpool), &(results->record_mpool)) < 0)
    {
        neo4j_log_trace_errno(results->logger, "neo4j_mpool_merge failed");
        set_failure(results, errno);
        return -1;
    }

    return stream_end(results, type, "PULL_ALL", argv, argc);
}
Exemplo n.º 2
0
void start_a()
{
    while (1)
    {
        append_result();
        MsgEnv *env;
        switch(append_i)
        {
            case 1:
                env = receive_message();
                release_msg_env(env);
                break;
            case 10:
                trace(ALWAYS,"10");
                release_processor();
                break;
            default:
                trace_uint(ALWAYS,"append_i ", append_i);
                utest_assert(0, "b process append_i not recongized");
                break;
        }
        trace(ALWAYS,"end of loop");
        release_processor();
    }
}
Exemplo n.º 3
0
void start_c()
{
    while (1)
    {
        append_result();
        MsgEnv * env = receive_message();
        release_msg_env(env);
        utest_assert(0, "C should not run for a second time");
        release_processor();
    }
}
static void
cb_searchdone (gboolean result,
               gpointer user_data)
{
    search_dialog *dialog = (search_dialog *) user_data;
    xmlDoc *doc;
    xmlNode *cur_node;
    
    if (!result || dialog->recv_buffer == NULL)
        return;       

    doc = xmlParseMemory(dialog->recv_buffer, strlen(dialog->recv_buffer));
    g_free(dialog->recv_buffer);
    dialog->recv_buffer = NULL;

    if (!doc)           
        return;

    cur_node = xmlDocGetRootElement(doc);

    if (cur_node)
    {
        for (cur_node = cur_node->children; 
                cur_node; 
                cur_node = cur_node->next)
        {
            if (NODE_IS_TYPE(cur_node, "loc"))
            {
                gchar *id = (gchar *) xmlGetProp(cur_node, (const xmlChar *) "id");
                gchar *city;

                if (!id)
                    continue;

                city = DATA(cur_node);

                if (!city)
                { 
                    g_free(id);
                    continue;
                }
                append_result(dialog->result_mdl, id, city);
                g_free(id);
                g_free(city);
            }
        }
    }

    xmlFreeDoc(doc);

    return;
}
Exemplo n.º 5
0
void GameStateParsed( void ) {
  int i;
  char *configString;

  for( i=0 ; i<MAX_CONFIGSTRINGS ; i++ ) {
    configString = Com_GetStringFromGameState( &ds.gameState, i );
    if( configString[0] ) {
      if( i < RESERVED_CONFIGSTRINGS ) {
        append_result( "%s_info:\n", (i == CS_SERVERINFO) ? "server" : "system" );
        Info_Print( configString );
        append_result( "\n" );
      }/* else {
        Com_Printf( "configString %i: \"%s\"\n", i, configString );
      }*/
    }
  }

  for( i=0 ; i<MAX_CLIENTS ; i++ ) {
    configString = Com_GetStringFromGameState( &ds.gameState, CS_PLAYERS + i );
    UpdateClientInfo( i, configString );
  }
}
Exemplo n.º 6
0
void start_f()
{
    while (1)
    {
        append_result();
        MsgEnv *env = request_msg_env();
        utest_assert(send_message(0, env) == CODE_SUCCESS, 
                "F could not send an env to A");
        env = request_msg_env();
        utest_assert(send_message(1, env) == CODE_SUCCESS, 
                "F could not send an env to B");
        release_processor();
    }
}
Exemplo n.º 7
0
void NewFrameParsed( void ) {
  int i;
  entityState_t *es;
  char *serverCommand;
  char *args;

  for( i=ds.currentServerCommandNum+1 ; i<=ds.lastServerCommandNum ; i++ ) {
    serverCommand = ds.serverCommands[i & SERVERCMD_MASK];
    Cmd_TokenizeString( serverCommand );

    if( !Q_stricmp( Cmd_Argv( 0 ), "print" ) || !Q_stricmp( Cmd_Argv( 0 ), "cp" ) ) {
      args = Cmd_Args();
      args[strlen(args)-2] = 0;
      args++;

      append_result("  - \"%s\"\n", args);
    } else if( !Q_stricmp( Cmd_Argv( 0 ), "cs" ) ) {
      UpdateConfigString( atoi( Cmd_Argv( 1 ) ), Cmd_Argv( 2 ) );
    }

//    Com_Printf( "serverCommand: %i \"%s\"\n", i, Com_TranslateLinefeeds(  ) );
  }
  ds.currentServerCommandNum = ds.lastServerCommandNum;

  if( !ds.snap || !ds.snap->valid ) {
    return;
  }

  for( i=0 ; i<MAX_GENTITIES ; i++ ) {
    centities[i].currentValid = qfalse;
  }

  for( i=0 ; i<ds.snap->numEntities ; i++ ) {
    es = &ds.parseEntities[(ds.snap->firstEntity+i) & PARSE_ENTITIES_MASK];
    memcpy( &centities[es->number].currentState, es, sizeof( entityState_t ) );
    centities[es->number].currentValid = qtrue;
    CG_CheckEvents( &centities[es->number] );
  }

  for( i=0 ; i<MAX_GENTITIES ; i++ ) {
    if( !centities[i].currentValid ) {
      centities[i].previousEvent = 0;
    }
  }
}
Exemplo n.º 8
0
void start_b()
{
    while (1)
    {
        append_result();
        MsgEnv *env;
        switch (append_i)
        {
            case 2:
                break;
            case 3:
                env = receive_message();
                release_msg_env(env);
                break;
            case 11:
                trace(ALWAYS,"doneee !!!");
                trace_ptr(ALWAYS,"rtx_strcmp ", rtx_strcmp);
                trace_ptr(ALWAYS,"result ", result);
                trace_ptr(ALWAYS,"expected ", expected);
                trace(ALWAYS,"result");
                trace(ALWAYS,result);
                trace(ALWAYS,"expected");
                trace(ALWAYS,expected);
                if (rtx_strcmp(result, expected) == 0)
                {
                    trace(ALWAYS,"YAY IT WORKS!!!");
                }
                utest_assert(rtx_strcmp(result, expected) == 0, "Result did not match expected sequence");
                if (rtx_strcmp(result, expected) != 0)
                {
                    trace_str(ALWAYS, "expected : ", expected);
                    trace_str(ALWAYS, "got      : ", result);
                }
                trace(ALWAYS,"test result timeee");

                utest_test_results();
                break;
            default:
                trace_uint(ALWAYS,"append_i ", append_i);
                utest_assert(0, "b process append_i not recongized");
                break;
        }
        release_processor();
    }
}
Exemplo n.º 9
0
void start_e()
{
    while (1)
    {
        append_result();
        MsgEnv *env;
        switch (append_i)
        {
            case 6:
                break;
            case 8:
                env = receive_message();
                release_msg_env(env);
                utest_assert(0, "D should not run for a second time");
                break;
            default:
                trace_uint(ALWAYS,"append_i ", append_i);
                utest_assert(0, "d process append_i not recongized");
                break;
        }
        release_processor();
    }
}
Exemplo n.º 10
0
/*
 * This method implements the main body of the hdu get subcommand.
 * If filename arg is not NULL, the contents of the current HDU are
 * written to the file as a local catalog. Otherwise, the contents
 * of the current HDU are returned as a Tcl list or rows. If the
 * entry arg is not null and a filename was specified, it specifies
 * the catalog config entry for the file's header, in Tcl list format
 * {{key value} {key value} ...}.
 */
int RtdImage::getHDU(FitsIO* fits, const char* filename, const char* entry)
{
    const char* type = fits->getHDUType();
    if (!type || *type == 'i')
	return error("HDU is not a FITS table");

    long nrows = 0;
    int ncols = 0;
    if (fits->getTableDims(nrows, ncols) != 0)
	return TCL_ERROR;

    if (filename == NULL) {
	// return the contents of the table as a tcl list of rows
	reset_result();
	for(int row = 1; row <= nrows; row++) {
	    append_result(" {");
	    for(int col = 1; col <= ncols; col++) {
		char* s = fits->getTableValue(row, col);
		if (!s)
		    return TCL_ERROR;
		append_element(s);
	    }
	    append_result("}");
	}
	return TCL_OK;
    }

    // Otherwise write the contents of the table to a local catalog file
    ofstream os(filename);
    if (! os)
	return sys_error("can't open file: ", filename);

    // output the catalog header
    os << "QueryResult\n\n";

    //  PWD: locate special columns and their conversion factors (to degrees
    //  from radians).
    int idcol = -1;
    int racol = -1;
    double rascale = 1.0;
    int deccol = -1;
    double decscale = 1.0;

    // output the catalog config entry, if there is one
    if (entry != NULL) {
	os << "# Config entry\n";
	int nkeys = 0;
	char** keys = NULL;
        const char *p;
        const char *t;
        char buf[20];
	if (Tcl_SplitList(interp_, (char*)entry, &nkeys, &keys) != TCL_OK)
	    return TCL_ERROR;
	for(int i = 0; i < nkeys; i++) {
	    int n = 0;
	    char** v = NULL;
	    if (Tcl_SplitList(interp_, keys[i], &n, &v) != TCL_OK) {
		Tcl_Free((char *)keys);
		return TCL_ERROR;
	    }
	    if (n != 2) {
		Tcl_Free((char *)keys);
		Tcl_Free((char *)v);
		return fmt_error("Invalid catalog config entry: '%s': Expected {key value}", keys[i]);
	    }

            //  PWD: record ra_col, dec_col and id_col columns.
            p = v[0];
            while ( p && *p && *p == ' ' ) p++;  // Trim leading blanks.
            if ( strncasecmp( p, "ra_col", 6 ) == 0 ) {
                sscanf( v[1], "%d", &racol );

                //  If these are radians we need to convert to degrees.
                sprintf( buf, "TUNIT%d", racol + 1 );
                t = fits->get( buf );
                while ( t && *t && *t == ' ' ) t++;  // Trim leading blanks.
                if ( t && strncasecmp( t, "radian", 6 ) == 0 ) {
                    rascale = r2d_;
                }
            }
            else if ( strncasecmp( p, "dec_col", 7 ) == 0 ) {
                sscanf( v[1], "%d", &deccol );

                //  If these are radians we need to convert to degrees.
                sprintf( buf, "TUNIT%d", deccol + 1 );
                t = fits->get( buf );
                while ( t && *t && *t == ' ' ) t++;  // Trim leading blanks.
                if ( t && strncasecmp( t, "radian", 6 ) == 0 ) {
                    decscale = r2d_;
                }
            }
            else if ( strncasecmp( p, "id_col", 6 ) == 0 ) {
                sscanf( v[1], "%d", &idcol );
            }
	    os << v[0] << ": " << v[1] << endl;
	    Tcl_Free((char *)v);
	}
        
        //  No id_col, so we fake an index at the end.
        if ( idcol == -1 ) {
            os << "id_col: " << ncols << endl;
        }

	Tcl_Free((char *)keys);
	os << "# End config entry\n\n";
    }

    // PWD: add any comment cards so that context is preserved.
    const char *c;
    while ( ( c = fits->getComments() ) != NULL ) {
        os << "#C" << c << endl;
    }

    // output the column headings, if id_col is undefined then create a fake
    // column at the end (to keep ra_col & dec_col at current settings, which
    // are written out, could also be x_col and y_col to keep happy).
    int col;
    for(col = 1; col <= ncols; col++) {
	char* s = fits->getTableHead(col);
	if (!s)
	    return TCL_ERROR;
	os << s;
	if (col < ncols)
	    os << '\t';
    }
    if ( idcol == -1 && entry != NULL ) {
        os << '\t' << "ID";
    }

    os << "\n---\n";    // heading separator (dashed line)

    // output the data
    for(long row = 1; row <= nrows; row++) {
	for(col = 1; col <= ncols; col++) {
            char* s;
            if ( col == ( racol + 1 ) ) {
                s = fits->getTableValue(row, col, rascale);
            }
            else if ( col == ( deccol + 1 ) ) {
                s = fits->getTableValue(row, col, decscale);
            }
            else {
                s = fits->getTableValue(row, col, 1.0);
            }
	    if (!s)
		return TCL_ERROR;
	    os << s;
	    if (col < ncols)
		os << '\t';
	}
        if ( idcol == -1 && entry != NULL ) {
            os << '\t' << row;
        }
	os << endl;
    }
    return TCL_OK;
}
Exemplo n.º 11
0
/**
 * Recursive iteration for file finding
 *
 * @param __dir - directory to search file in
 * @param __rel_dir - relative director name to search file in
 * @param __options - finding options
 * @param __res_wnd - window with results
 * @return zero on success, non-zero otherwise
 */
static int
find_iteration (const wchar_t *__dir, const wchar_t *__rel_dir,
                const action_find_options_t *__options,
                action_find_res_wnd_t *__res_wnd)
{
  int i, j, count;
  vfs_dirent_t **eps = NULL;
  size_t fn_len;
  wchar_t *format, *full_name;
  vfs_stat_t stat;
  vfs_stat_proc stat_proc;
  deque_t *dirs;
  wchar_t **dir_data;

  __res_wnd->dir_opened = FALSE;

  /* Get listing of directory */

  /*
   * TODO: Add separately displaying of directories and files
   */

  count = vfs_scandir (__dir, &eps, 0, vfs_alphasort);

  if (count < 0)
    {
      /* Error getting listing */
      return ACTION_ERR;
    }

  if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY))
    {
      dirs = deque_create ();
    }

  /* Get function for stat'ing */
  if (TEST_FLAG(__options->flags, AFF_FOLLOW_SYMLINKS))
    {
      stat_proc = vfs_stat;
    }
  else
    {
      stat_proc = vfs_lstat;
    }

  /* Allocate memory for full file name */
  fn_len = wcslen (__dir) + MAX_FILENAME_LEN + 1;
  full_name = malloc ((fn_len + 1) * sizeof (wchar_t));

  /* Get format mask for correct directory drilling */
  if (__dir[wcslen (__dir) - 1] == '/')
    {
      format = L"%ls%ls";
    }
  else
    {
      format = L"%ls/%ls";
    }

  for (i = 0; i < count; ++i)
    {
      if (IS_PSEUDODIR (eps[i]->name))
        {
          vfs_free_dirent (eps[i]);
          continue;
        }

      set_searching_status (__res_wnd, L"Searching in", __rel_dir);

      /* Get full file name */
      swprintf (full_name, fn_len, format, __dir, eps[i]->name);

      /* Stat current node of FS */
      if (!stat_proc (full_name, &stat) == VFS_OK)
        {
          /* Error getting status of file */
          vfs_free_dirent (eps[i]);
          continue;
        }

      if (S_ISREG (stat.st_mode))
        {
          if (check_regular_file (eps[i]->name, full_name,
                                  __options, __res_wnd))
            {
              append_result (__rel_dir, eps[i]->name, stat, __res_wnd);
              ++__res_wnd->found_files;
            }
        }
      else if (S_ISDIR (stat.st_mode))
        {
          /* Of user wants directories to be found... */
          if (TEST_FLAG(__options->flags, AFF_FIND_DIRECTORIES))
            {
              if (check_directory (eps[i]->name, full_name,
                                   __options, __res_wnd))
                {
                  append_result (__rel_dir, eps[i]->name, stat, __res_wnd);
                  ++__res_wnd->found_dirs;
                }
            }

          if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY))
            {
              dir_data = malloc (2 * sizeof (wchar_t));
              dir_data[0] = wcsdup (eps[i]->name);
              dir_data[1] = wcsdup (full_name);
              deque_push_back (dirs, (void*)dir_data);
            }
        }
      else
        {
          if (check_special_file (eps[i]->name, full_name,
                                  __options, __res_wnd))
            {
              append_result (__rel_dir, eps[i]->name, stat, __res_wnd);
              ++__res_wnd->found_files;
            }
        }

      vfs_free_dirent (eps[i]);

      hook_call (L"switch-task-hook", NULL);

      if (ACTION_PERFORMED (__res_wnd))
        {
          /* Free remain dirents */
          for (j = i + 1; j < count; ++j)
            {
              vfs_free_dirent (eps[j]);
            }
          break;
        }
    }

  SAFE_FREE (eps);
  free (full_name);

  if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY) &&
      !ACTION_PERFORMED (__res_wnd))
    {
      void *data;
      wchar_t *rel_name;

      if (__rel_dir[wcslen (__rel_dir) - 1] == '/')
        {
          format = L"%ls%ls";
        }
      else
        {
          format = L"%ls/%ls";
        }

      fn_len = wcslen (__dir) + MAX_FILENAME_LEN + 1;
      rel_name = malloc ((fn_len + 1) * sizeof (wchar_t));

      deque_foreach (dirs, data);
        /* Drill relative file name */

        dir_data = data;
        if (!ACTION_PERFORMED (__res_wnd))
          {
            swprintf (rel_name, fn_len, format, __rel_dir, dir_data[0]);
            find_iteration (dir_data[1], rel_name, __options, __res_wnd);
          }
        free (dir_data);
      deque_foreach_done
    }