Ejemplo n.º 1
0
/*
    Builds the DynamicRoutingTable from Control Provider and Services
    definition tables in this file:
      - SvcsRegDefinitionTable defines OpenPegasus services to be registered
      - CtlProviderRegDefinitionTable defines Control Providers

    This is a static method.
*/
void DynamicRoutingTable::buildRoutingTable()
{
    // Lock during table build
    static AtomicInt _initialized(0);
    static Mutex _monitor;

    // Get the address of the routing table
    DynamicRoutingTable * routingTable =
        DynamicRoutingTable::getRoutingTable();

    // Assure table built only once
    if (_initialized.get() == 0)
    {
        // lock and retest
        AutoMutex autoMut(_monitor);
        if (_initialized.get() == 0)
        {
            const Uint32 NUM_SVCS = sizeof(SvcsRegDefinitionTable) /
                    sizeof(SvcsRegDefinitionTable[0]);

            // Insert a record into the table for each entry in the
            // SvcsDefinitionTable
            for (Uint32 i = 0; i < NUM_SVCS; i++)
            {
                Uint32 serviceId = MessageQueue::lookup(
                    SvcsRegDefinitionTable[i].serviceName)->getQueueId();

                routingTable->_insertRecord(
                    SvcsRegDefinitionTable[i].className,
                    SvcsRegDefinitionTable[i].namespaceName,
                    String::EMPTY,
                    serviceId);
            }

            // Add Control Providers from CtlProviderRegDefintionTable
            const Uint32 NUM_CTL_PROVIDERS =
                sizeof(CtlProviderRegDefinitionTable) /
                 sizeof(CtlProviderRegDefinitionTable[0]);

            // all Control provider routing is through controlService
            Uint32 controlServiceId = MessageQueue::lookup(
                PEGASUS_QUEUENAME_CONTROLSERVICE)->getQueueId();

            for (Uint32 i = 0; i < NUM_CTL_PROVIDERS; i++)
            {
                routingTable->_insertRecord(
                    CtlProviderRegDefinitionTable[i].className,
                    CtlProviderRegDefinitionTable[i].namespaceName,
                    CtlProviderRegDefinitionTable[i].providerName,
                    controlServiceId);
            }
            // set initialized flag
            _initialized = 1;
#ifdef PEGASUS_DEBUG
            _tableInitialized = true;
#endif
        }
    }
    //// routingTable->dumpRegTable();
}
Ejemplo n.º 2
0
// Test Thread and AtomicInt
void test02()
{
    const Uint32 numThreads = 64;
    AtomicInt * atom = new AtomicInt(0);
    Thread* threads[numThreads];

    (*atom)++;
    Boolean zero = atom->DecAndTestIfZero();
    assert(zero);

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i] = new Thread(atomicIncrement, atom, false);
    }

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i]->run();
    }

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i]->join();
        delete threads[i];
    }

    assert(atom->value() == numThreads);
    delete atom;
}
Ejemplo n.º 3
0
// Test Thread and AtomicInt
void test02()
{
    const Uint32 numThreads = 64;
    AtomicInt * atom = new AtomicInt(0);
    Thread* threads[numThreads];

    (*atom)++;
    Boolean zero = atom->decAndTestIfZero();
    PEGASUS_TEST_ASSERT(zero);

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i] = new Thread(atomicIncrement, atom, false);
    }

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i]->run();
    }

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i]->join();
        delete threads[i];
    }

    PEGASUS_TEST_ASSERT(atom->get() == numThreads);
    delete atom;
}
Ejemplo n.º 4
0
ThreadReturnType PEGASUS_THREAD_CDECL funcSleepUntilCancelled(
    void* parm)
{
    AtomicInt* cancelled = static_cast<AtomicInt*>(parm);

    while (cancelled->get() == 0)
    {
        Threads::sleep(1);
    }

    return 0;
}
Ejemplo n.º 5
0
ThreadReturnType PEGASUS_THREAD_CDECL atomicIncrement(void * parm)
{
    Thread* my_thread  = (Thread *)parm;
    AtomicInt * atom = (AtomicInt *)my_thread->get_parm();

    (*atom)++;
    (*atom)++; (*atom)++; (*atom)++; (*atom)++;
    (*atom)--; (*atom)--;
    (*atom)--;
    Boolean zero = atom->decAndTestIfZero();
    PEGASUS_TEST_ASSERT(zero == false);

    return ThreadReturnType(0);
}
Ejemplo n.º 6
0
PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL atomicIncrement(void * parm)
{
    Thread* my_thread  = (Thread *)parm;
    AtomicInt * atom = (AtomicInt *)my_thread->get_parm();

    (*atom)++;
    (*atom)+=4;
    (*atom)-=2;
    (*atom)--;
    Boolean zero = atom->DecAndTestIfZero();
    assert(zero == false);

    my_thread->exit_self(0);
    return 0;
}
Ejemplo n.º 7
0
FAKE_MESSAGE *get_next_msg(void *key)
{
   AutoPtr<FAKE_MESSAGE> msg;

   AutoMutex autoMut(msg_mutex);
   if(requests.value() < NUMBER_MSGS)
   {
      msg.reset(PEGASUS_NEW(FAKE_MESSAGE, dq_handle) FAKE_MESSAGE(key, 0));

/*****
      check for corrupted memory 
      char *p = (char *)msg;
      p += sizeof(FAKE_MESSAGE);

      *p = 0x00;
      
      if(peg_suballocator::CheckMemory(msg))
	 abort();
******/      
      
      
      
      requests++;
   }
    
   return msg.release();  
}
Ejemplo n.º 8
0
void testReadWriteThreads()
{
    if (verbose)
    {
        cout << "testReadWriteThreads" << endl;
    }
    ReadWriteSem *rwSem = new ReadWriteSem();
    Thread *readers[READER_COUNT];
    Thread *writers[WRITER_COUNT];

    for(int i = 0; i < READER_COUNT; i++)
    {
       readers[i] = new Thread(reading_thread, rwSem, false);
       readers[i]->run();
    }

    for( int i = 0; i < WRITER_COUNT; i++)
    {
       writers[i] = new Thread(writing_thread, rwSem, false);
       writers[i]->run();
    }
    Threads::sleep(20000);
    die = true;

    for( int i = 0; i < 40; i++)
    {
      readers[i]->join();
       delete readers[i];
    }

    for( int i = 0; i < 10; i++)
    {
       writers[i]->join();
       delete writers[i];
    }

    delete rwSem;
    if (verbose)
    {
        cout << endl
             << "read operations: " << read_count.get() << endl
             << "write operations: " << write_count.get() << endl;
    }
}
Ejemplo n.º 9
0
int _beginTest(CIMClient& workClient,
               Uint32 indicationSendCount,
               Uint32 runClientThreadCount,
               const String& processIdFile,
               const String& logFile)
{

#ifdef PEGASUS_USE_NET_SNMP

    // Stop snmptrapd process if it is running
    _stopSnmptrapd(processIdFile);

    // if trapLogFile exists, remove it
    _removeTrapLogFile(logFile);

    FILE * trapInfo;

    try
    {
        _startSnmptrapd(&trapInfo, processIdFile, logFile);
    }
    catch (Exception & e)
    {
        cerr << e.getMessage() << endl;
        return (-1);
    }

    // Extended for all snmp implementation
    _receiveExpectedTraps(workClient, indicationSendCount,
                          runClientThreadCount, logFile);

    // Stop snmptrapd process if it is running and remove procIdFile
    _stopSnmptrapd(processIdFile);

    pclose(trapInfo);

    // if error encountered then fail the test.
    if (errorsEncountered.get())
    {
        cout << "+++++ test failed" << endl;
        return (-1);
    }
    else
    {
        cout << "+++++ passed all tests" << endl;
    }

    return (0);

#else
    cerr << "Cannot create a trap receiver." << endl;
    return (-1);
#endif
}
Ejemplo n.º 10
0
void ThreadPool::notify(int inIndex)
{
#ifdef POOL_DEBUG
	printf("ThreadPool notified for index %d\n", inIndex);
#endif
	if (mRequestCount.decrementAndTest()) {
#if defined(POOL_DEBUG) || defined(THREAD_DEBUG)
		printf("ThreadPool posting to wait semaphore\n");
#endif
		mWaitSema.post();
	}
}
Ejemplo n.º 11
0
void	AtomicIntOp::exec_both (AtomicInt <T> &atom, F &ftor, T &val_old, T &val_new)
{
	assert (&atom != 0);
	assert (&ftor != 0);

	T					val_cur;
	do
	{
		val_cur = atom;
		val_new = ftor (val_cur);
		val_old = atom.cas (val_new, val_cur);
	}
	while (val_old != val_cur);
}
Ejemplo n.º 12
0
static void Initialize()
{
   static AtomicInt s_initialized;
   static Mutex s_mutex;

   if ( !s_initialized )
   {
      volatile AutoLock lock( s_mutex );
      if ( s_initialized.Load() == 0 )
      {
         uint32 M, m, r, b, beta, conf, le;
         char lang[ 8 ];

         (*API->Global->GetPixInsightVersion)( &M, &m, &r, &b, &beta, &conf, &le, lang );

         s_major = int( M );
         s_minor = int( m );
         s_release = int( r );
         s_build = int( b );
         s_beta = int( beta );
         s_confidential = conf != 0;
         s_le = le != 0;
         s_language = lang;

#if ( PCL_API_Version >= 0x0126 )
         char16_type* s = (*API->Global->GetPixInsightCodename)( ModuleHandle() );
         if ( s != nullptr )
         {
            s_codename = String( s );
            if ( Module != nullptr )
               Module->Deallocate( s );
         }
#endif
         s_initialized.Store( 1 );
      }
   }
}
Ejemplo n.º 13
0
ThreadReturnType PEGASUS_THREAD_CDECL _idleThd(void *parm)
{
    Thread *my_thread = (Thread *)parm;
    AutoPtr<T_Parms> parms((T_Parms *)my_thread->get_parm());
    Uint32 durationSeconds = parms->durationSeconds;
    const char * testUserid = parms->testUserid;
    const char * testPasswd = parms->testPasswd;

    CIMClient client;

    try
    {
        if (testUserid == NULL)
        {
            client.connectLocal();
        }
        else
        {
            client.connect(System::getHostName(), 5988,
                String(testUserid), String(testPasswd));
        }

        CIMClass tmpClass =
            client.getClass (OSINFO_NAMESPACE, OSINFO_CLASSNAME);

        cout << "Test 2 of 2: Begin " << durationSeconds
            << " second idle period..." << endl;

        while (sleepIterations.get() < durationSeconds)
        {
            Threads::sleep(1000);
        }
        //the client shall reconnect if the connection was closed and 
        //so the operation should succeed.
        CIMClass tmpClass2 =
            client.getClass (OSINFO_NAMESPACE, OSINFO_CLASSNAME);
    }
    catch(Exception& e)
    {
        test2CaughtException = true;
        cerr << "Error: " << e.getMessage() << endl;
    }
    client.disconnect();

    return ThreadReturnType(0);
}
Ejemplo n.º 14
0
//
// Tests subscription creation by sending the similar concurrent subscription
// creation requests .
//
void _testConcurrent(CIMClient &client)
{
    CIMObjectPath filterPath;
    CIMObjectPath handlerPath;
    CIMObjectPath subscriptionPath;
    try
    {
        HandlerPath = CreateHandler1Instance(client,
            PEGASUS_NAMESPACENAME_INTEROP);
        FilterPath = CreateFilterInstance(client,
            QUERY1, "WQL", "Filter1",
            PEGASUS_NAMESPACENAME_INTEROP);

        Thread thread1(createSubscriptionFunc, (void *)0, false);
        Thread thread2(createSubscriptionFunc, (void *)0, false);
        Thread thread3(createSubscriptionFunc, (void *)0, false);
        Thread thread4(createSubscriptionFunc, (void *)0, false);

        thread1.run();
        thread2.run();
        thread3.run();
        thread4.run();

        thread1.join();
        thread2.join();
        thread3.join();
        thread4.join();

        _checkSubscriptionCount(client);

        PEGASUS_TEST_ASSERT(exceptionCount.get() == 3);

        DeleteInstance(client, SubscriptionPath, PEGASUS_NAMESPACENAME_INTEROP);
        DeleteInstance(client, FilterPath, PEGASUS_NAMESPACENAME_INTEROP);
        DeleteInstance(client, HandlerPath, PEGASUS_NAMESPACENAME_INTEROP);
   }
   catch(const CIMException &e)
   {
      PEGASUS_STD(cerr) << "Exception: " << e.getMessage()
                        << PEGASUS_STD (endl);
      PEGASUS_TEST_ASSERT(0);
   }
}
Ejemplo n.º 15
0
// _test2 verifies that a CIM Operation on a client connection will still
// succeed when the idleConnectionTimeout period is exceeded (_idleThd) *and*
// there is concurrent server activity (_runningThd) so that the Monitor
// will wake up and check for timeouts and close the connection.
// In this case, the second call to getClass() in _idleThd() will reconnect 
// and send the request.
Boolean _test2(
    int durationSeconds, const char * testUserid, const char * testPasswd)
{
    try
    {
        sleepIterations.set(0);
        // run tests
        Array<Thread *> clientThreads;

        test2CaughtException = false;

        clientThreads.append(
            _runTestThreads(
                _runningThd, durationSeconds, testUserid, testPasswd));

        clientThreads.append(
            _runTestThreads(
                _idleThd, durationSeconds, testUserid, testPasswd));

        // wait for threads to terminate
        for(Uint32 i=0; i< clientThreads.size(); i++)
        {
            clientThreads[i]->join();
        }

        // clean up threads
        for(Uint32 i=0; i < clientThreads.size(); i++)
        {
            if(clientThreads[i])
                delete clientThreads[i];
        }
    }
    catch(Exception& e)
    {
        cerr << "Error: " << e.getMessage() << endl;
        return TEST_FAILED;
    }

    // We do not expect exception in this case.
    return (test2CaughtException == false);
}
Ejemplo n.º 16
0
PEGASUS_NAMESPACE_END

int main(int argc, char **argv)
{
    PEGASUS_START_LEAK_CHECK();
   
    const char* tmpDir = getenv ("PEGASUS_TMP");
    if (tmpDir == NULL)
    {
        tmpDir = ".";
    }
    String traceFile (tmpDir);
    traceFile.append("/dq_memory_trace");

   Tracer::setTraceFile (traceFile.getCString()); 
   Tracer::setTraceComponents("Memory");  
   Tracer::setTraceLevel(Tracer::LEVEL4); 
   AutoPtr<dq_handle>(new peg_suballocator::SUBALLOC_HANDLE());

   read_write rw =
      { 
	 new AsyncDQueue<FAKE_MESSAGE>(true, 100), 
	 new AsyncDQueue<FAKE_MESSAGE>(true, 100)
      };

   Thread *client_sender[20];
   Thread *server[10];
   int i;
   FAKE_MESSAGE *test = PEGASUS_ARRAY_NEW(FAKE_MESSAGE, 10, dq_handle.get());
   PEGASUS_ARRAY_DELETE(test);
   
   
   for( i = 0; i < NUMBER_CLIENTS; i++)
   {
      client_sender[i] = new Thread(client_sending_thread, &rw, false );
      client_sender[i]->run();
   }

   for( i = 0; i < NUMBER_SERVERS; i++)
   {
      server[i] = new Thread(server_thread, &rw, false);
      server[i]->run();
   }

   while( requests.value() < NUMBER_MSGS || replies.value() < NUMBER_MSGS )
   {
      pegasus_sleep(1000);
   }

   rw.incoming->shutdown_queue();
   rw.outgoing->shutdown_queue();

   PEGASUS_STOP_LEAK_CHECK();
   PEGASUS_CHECK_FOR_LEAKS(dq_handle.get());

   for( i = 0; i < NUMBER_CLIENTS; i++)
   {
      client_sender[i]->join();
      delete client_sender[i];
   }

   for( i = 0; i < NUMBER_SERVERS; i++)
   {
      server[i]->join();
      delete server[i];
   }

   cout << NUMBER_MSGS << " messages using " << NUMBER_CLIENTS << " clients and " << NUMBER_SERVERS << " servers" << endl;
   cout << endl << "total requests: " << requests.value() << "; total replies: " << replies.value() << endl;
   cout << "unclaimed requests: " <<  rw.outgoing->count() << endl;
   delete rw.incoming;
   delete rw.outgoing;


   
   return 0;
}