示例#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();
}
示例#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();
    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;
}
示例#3
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;
    }
}
示例#4
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
}
示例#5
0
ThreadReturnType PEGASUS_THREAD_CDECL funcSleepUntilCancelled(
    void* parm)
{
    AtomicInt* cancelled = static_cast<AtomicInt*>(parm);

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

    return 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);
}
示例#7
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);
   }
}