void test_simple_list()
{
    SimpleList<int> slist;
    for (int i = 0; i < 10; ++i) {
        slist.push_back(i);
    }
}
Exemple #2
0
int
SaveCredentialList() {
  priv_state priv = set_root_priv();
  FILE * fp = safe_fopen_wrapper(cred_index_file, "w");
  if (!fp) {
    set_priv (priv);
    dprintf (D_ALWAYS, "Unable to open credential index file %s!\n", cred_index_file);
    return FALSE;
  }


  classad::ClassAdXMLUnParser unparser;
  CredentialWrapper * pCred = NULL;

  // Clear the old list
  credentials.Rewind();
  while (credentials.Next(pCred)) {
    const classad::ClassAd * pclassad = pCred->cred->GetMetadata();
	classad::ClassAd temp_classad(*pclassad); // lame
    std::string buff;
    unparser.Unparse (buff, &temp_classad);
    fprintf (fp, "%s\n", buff.c_str());
  }

  fclose (fp);
  
  set_priv (priv);
  return TRUE;
}
int main()
{
    SimpleList l;
    char c;

    printf("testing insert/remove...");
    if (!l.insert(-1, 'a'))
        goto fail;
    if (!l.insert(-1, 'b'))
        goto fail;
    if (!l.insert(1, 'c'))
        goto fail;
    if (!l.remove(0, &c) || c != 'a')
        goto fail;
    if (!l.remove(1, &c) || c != 'b')
        goto fail;
    if (!l.remove(0, &c) || c != 'c')
        goto fail;
    printf("[ok]\n");

    printf("testing count...");
    if (l.get_count() != 0)
        goto fail;
    l.insert(-1, 'a');
    if (l.get_count() != 1)
        goto fail;
    printf("[ok]\n");

    return 0;

fail:
    printf("[failed]\n");
    return -1;
}
Exemple #4
0
void GenericQuery::
copyFloatCategory (SimpleList<float> &to, SimpleList<float> &from)
{
	float item;

	clearFloatCategory (to);
	while (from.Next (item))
		to.Append (item);
}
Exemple #5
0
void GenericQuery::
copyIntegerCategory (SimpleList<int> &to, SimpleList<int> &from)
{
	int item;

	clearIntegerCategory (to);
	while (from.Next (item))
		to.Append (item);
}
Exemple #6
0
void GenericQuery::
clearFloatCategory (SimpleList<float> &float_category)
{
    float item;

    float_category.Rewind ();
    while (float_category.Next (item))
        float_category.DeleteCurrent ();
}
Exemple #7
0
void GenericQuery::
clearIntegerCategory (SimpleList<int> &int_category)
{
    int item;

    int_category.Rewind ();
    while (int_category.Next (item))
        int_category.DeleteCurrent ();
}
Exemple #8
0
void simpleListSetFirst_base(SimpleList l, const Ptr data) {
    if(l->delFct)
        l->delFct((void *)l->first+sizeof(struct _SimpleListNode));

    if(l->copyFct)
        l->copyFct((void *)l->first+sizeof(struct _SimpleListNode), data);
    else
        memcpy((void *)l->first+sizeof(struct _SimpleListNode), data, l->elemSize);
}
Exemple #9
0
void
requestScheddUpdateNotification( int timer_id )
{
	if ( scheddUpdateNotifications.IsMember( timer_id ) == false ) {
		// A new request; add it to the list
		scheddUpdateNotifications.Append( timer_id );
		RequestContactSchedd();
	}
}
void
CollectorPluginManager::Shutdown()
{
	CollectorPlugin *plugin;
	SimpleList<CollectorPlugin *> plugins = getPlugins();
	plugins.Rewind();
	while (plugins.Next(plugin)) {
		plugin->shutdown();
	}
}
void
CollectorPluginManager::Invalidate(int command, const ClassAd &ad)
{
	CollectorPlugin *plugin;
	SimpleList<CollectorPlugin *> plugins = getPlugins();
	plugins.Rewind();
	while (plugins.Next(plugin)) {
		plugin->invalidate(command, ad);
	}
}
void
NegotiatorPluginManager::Update(const ClassAd &ad)
{
	NegotiatorPlugin *plugin;
	SimpleList<NegotiatorPlugin *> plugins = getPlugins();
	plugins.Rewind();
	while (plugins.Next(plugin)) {
		plugin->update(ad);
	}
}
void
NegotiatorPluginManager::Initialize()
{
	NegotiatorPlugin *plugin;
	SimpleList<NegotiatorPlugin *> plugins = getPlugins();
	plugins.Rewind();
	while (plugins.Next(plugin)) {
		plugin->initialize();
	}
}
void
NegotiatorPluginManager::Shutdown()
{
	NegotiatorPlugin *plugin;
	SimpleList<NegotiatorPlugin *> plugins = getPlugins();
	plugins.Rewind();
	while (plugins.Next(plugin)) {
		plugin->shutdown();
	}
}
void AbstractSequentialListTest::testSet() {

    SimpleList<int> list;

    try {
        list.set( 0, 12 );
        CPPUNIT_FAIL("should throw IndexOutOfBoundsException");
    } catch( IndexOutOfBoundsException& e ) {
        // expected
    }
}
void AbstractSequentialListTest::testAddAll() {

    LinkedList<int> collection;
    for( int i = 0; i < 50; ++i ) {
        collection.add( i );
    }

    SimpleList<int> list;
    list.addAll( collection );
    CPPUNIT_ASSERT_MESSAGE( "Should return true", list.addAll( 2, collection ) );
}
void AbstractListTest::testIterator() {

    SimpleList<int> list;
    list.add( 10 );
    list.add( 20 );
    std::auto_ptr< Iterator<int> > iter( list.iterator() );

    CPPUNIT_ASSERT_EQUAL( 10, iter->next() );
    iter->remove();
    CPPUNIT_ASSERT_EQUAL( 20, iter->next() );
}
int 
allAmazonCommands(StringList &output)
{
	AmazonGahpCommand *one_cmd = NULL;

	amazon_gahp_commands.Rewind();
	while( amazon_gahp_commands.Next(one_cmd) ) {
		output.append(one_cmd->command.c_str());
	}

	return amazon_gahp_commands.Number();
}
void AbstractListTest::testIndexOf() {

    SimpleList<int> array;
    for( int i = 1; i < 6; i++ ) {
        array.add(i);
    }

    MockArrayList<int> list;
    list.addAll( array );

    CPPUNIT_ASSERT_EQUAL_MESSAGE( "find 0 in the list do not contain 0", -1, list.indexOf( 0 ) );
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "did not return the right location of element 3", 2, list.indexOf( 3 ) );
}
void
flush_results()
{
	std::string *next_str;

	results_queue.Rewind();
	while ( results_queue.Next( next_str ) ) {
		daemonCore->Write_Pipe( RESULT_OUTBOX, next_str->c_str(),
								next_str->length() );
		delete next_str;
	}
	results_queue.Clear();
}
void AbstractSequentialListTest::testRemove() {

    SimpleList<int> list;
    list.add(1);

    CPPUNIT_ASSERT_EQUAL( 1, list.removeAt( 0 ) );

    list.add( 2 );
    CPPUNIT_ASSERT_EQUAL( 2, list.removeAt( 0 ) );

    // remove index is out of bounds
    try {
        list.removeAt( list.size() );
        CPPUNIT_FAIL("Should throw IndexOutOfBoundsException.");
    } catch( IndexOutOfBoundsException& e ) {
        // expected
    }
    try {
        list.removeAt( -1 );
        CPPUNIT_FAIL("Should throw IndexOutOfBoundsException.");
    } catch( IndexOutOfBoundsException& e ) {
        // expected
    }

    // list dont't support remove operation
    try {
        MockAbstractSequentialList<int> mylist;
        mylist.removeAt( 0 );
        CPPUNIT_FAIL("Should throw UnsupportedOperationException.");
    } catch( UnsupportedOperationException& e ) {
        // expected
    }
}
Exemple #22
0
void CondorResource::DoUpdateLeases( time_t& update_delay,
									 bool& update_complete,
									 SimpleList<PROC_ID>& update_succeeded )
{
	int rc;
	BaseJob *curr_job;
	SimpleList<PROC_ID> jobs;
	SimpleList<int> expirations;
	SimpleList<PROC_ID> updated;

dprintf(D_FULLDEBUG,"*** DoUpdateLeases called\n");
	if ( lease_gahp->isStarted() == false ) {
		dprintf( D_ALWAYS,"gahp server not up yet, delaying lease update\n" );
		update_delay = 5;
		return;
	}

	update_delay = 0;

	if ( updateLeasesCmdActive == false ) {
		leaseUpdates.Rewind();
		while ( leaseUpdates.Next( curr_job ) ) {
				// TODO When remote-job-id is homogenized and stored in 
				//   BaseJob, BaseResource can skip jobs that don't have a
				//   a remote-job-id yet
			if ( ((CondorJob*)curr_job)->remoteJobId.cluster != 0 ) {
				int exp = 0;
				jobs.Append( ((CondorJob*)curr_job)->remoteJobId );
				curr_job->jobAd->LookupInteger( ATTR_JOB_LEASE_EXPIRATION,
												exp );
				expirations.Append( exp );
			}
		}
	}

	rc = lease_gahp->condor_job_update_lease( scheddName, jobs, expirations,
											  updated );

	if ( rc == GAHPCLIENT_COMMAND_PENDING ) {
		update_complete = false;
	} else if ( rc != 0 ) {
dprintf( D_FULLDEBUG, "*** Lease update failed!\n" );
		update_complete = true;
	} else {
dprintf( D_FULLDEBUG, "*** Lease udpate succeeded!\n" );
		update_complete = true;

		PROC_ID curr_id;
		std::string id_str;
		updated.Rewind();
		while ( updated.Next( curr_id ) ) {
			sprintf( id_str, "condor %s %s %d.%d", scheddName, poolName,
							curr_id.cluster, curr_id.proc );
			if ( BaseJob::JobsByRemoteId.lookup( HashKey( id_str.c_str() ),
												 curr_job ) == 0 ) {
				update_succeeded.Append( curr_job->procID );
			}
		}
	}
}
void
enqueue_result (int req_id, const char ** results, const int argc)
{
	std::string *buffer = new std::string();

	sprintf( *buffer, "%d", req_id );

	for ( int i = 0; i < argc; i++ ) {
		*buffer += ' ';
		if ( results[i] == NULL ) {
			*buffer += "NULL";
		} else {
			for ( int j = 0; results[i][j] != '\0'; j++ ) {
				switch ( results[i][j] ) {
				case ' ':
				case '\\':
				case '\r':
				case '\n':
					*buffer += '\\';
				default:
					*buffer += results[i][j];
				}
			}
		}
	}

	*buffer += '\n';
	results_queue.Append( buffer );
}
Exemple #24
0
int TcpClient::GetListPeerId(SimpleList<unsigned int>& listId)
{
  unsigned int pid = MsgSocket::GetPeerPid();
  if(pid != 0)
	{
	  listId.Add(pid);
	  return 1;
	}
  return 0;
}
Exemple #25
0
u32int Ressource::doCall(u8int id, u32int a, u32int b, u32int c, u32int d, u32int e) {
	for (SimpleList<call_t*> *iter = m_callTables; iter != 0; iter = iter->next()) {
		call_t* ct = iter->v();
		u32int i = 0;
		while (ct[i].id != 0) {
			call_t &ce = ct[i];
			if (ce.id == id) {
				if (ce.params == 0) return (this->*(ce.c0))();
				if (ce.params == 1) return (this->*(ce.c1))(a);
				if (ce.params == 2) return (this->*(ce.c2))(a, b);
				if (ce.params == 3) return (this->*(ce.c3))(a, b, c);
				if (ce.params == 4) return (this->*(ce.c4))(a, b, c, d);
				if (ce.params == 5) return (this->*(ce.c5))(a, b, c, d, e);
			}
			i++;
		}
	}
	return (u32int) - 1;
}
bool
executeWorkerFunc(const char* cmd, char **argv, int argc, std::string &output_string)
{
	if(!cmd) {
		return false;
	}

	AmazonGahpCommand *one_cmd = NULL;

	amazon_gahp_commands.Rewind();
	while( amazon_gahp_commands.Next(one_cmd) ) {
		if( !strcasecmp(one_cmd->command.c_str(), cmd) && 
			one_cmd->workerfunction ) {
			return one_cmd->workerfunction(argv, argc, output_string);
		}
	}
	dprintf (D_ALWAYS, "Unknown command %s\n", cmd);
	return false;
}
bool
executeIOCheckFunc(const char* cmd, char **argv, int argc)
{
	if(!cmd) {
		return false;
	}

	AmazonGahpCommand *one_cmd = NULL;

	amazon_gahp_commands.Rewind();
	while( amazon_gahp_commands.Next(one_cmd) ) {
		if( !strcasecmp(one_cmd->command.c_str(), cmd) && 
		 	one_cmd->iocheckfunction ) {
			return one_cmd->iocheckfunction(argv, argc);
		}
	}

	dprintf (D_ALWAYS, "Unknown command %s\n", cmd);
	return false;
}
Exemple #28
0
void simpleListRemoveFirst(SimpleList l) {
    SimpleListNode node = l->first;

    l->first = node->next;

    if(l->delFct)
        l->delFct((void *)node+sizeof(struct _SimpleListNode));

    free(node);

    l->length--;
}
Exemple #29
0
bool simpleListContains(const SimpleList l, const Ptr data) {
    SimpleListNode node = l->first;

    while(node) {
        if(l->cmpFct((void *)node+sizeof(struct _SimpleListNode), data) == 0)
            return true;

        node = node->next;
    }

    return false;
}
void
registerAmazonGahpCommand(const char* command, ioCheckfn iofunc, workerfn workerfunc)
{
	if( !command ) {
		return;
	}

	AmazonGahpCommand* newcommand = new AmazonGahpCommand(command, iofunc, workerfunc);
	ASSERT(newcommand);

	amazon_gahp_commands.Append(newcommand);
}