Esempio n. 1
0
/*!
 * \brief Create a text box
 * 
 * \param stringHandle Handle of the text string to display in the text box. 
 * \param prop Properties of the text box. See #MtrCreateTextBoxProperties.
 * \return SMTR_RESULT_OK on success, otherwise the proper error code.
 *****************************************************************************/
SmtrResult smtrCreateTextBox(MsfStringHandle stringHandle, 
    const SmtrCreateTextBoxProperties *prop, SmtrCreateRspData **rsp)
{
    SmtrInstance *inst;
    MSF_UINT32 flags;
    *rsp = NULL;

    /* We don't accept empty strings */
    if (MSF_WIDGET_STRING_GET_LENGTH(stringHandle, 0, MsfUtf8) <= 0) 
    {
        *rsp = NULL;
        return SMTR_RESULT_ERROR;
    }
    /* Create a new text box instance */
    if (NULL == (inst = createInstance(stringHandle, prop)))
    {
        return SMTR_RESULT_BUSY;
    }
    /* Save flags */
    flags = prop->flags;
    /* Only parse if user wants to */
    if (IS_SET(flags, SMTR_PROP_RENDER_LINKS) ||
        IS_SET(flags, SMTR_PROP_RETURN_LINKS)) 
    {
        if (smtrParse(inst) < 0) 
        {
            deleteInstance(&inst);
            return SMTR_RESULT_ERROR;
        }
    }
    /* Render screen */
    if (smtrRender(inst) < 0) 
    {
        deleteInstance(&inst);
        return SMTR_RESULT_ERROR;        
    }
    /* Create response data */
    *rsp = MSF_MEM_ALLOCTYPE(MSF_MODID_SMTR, SmtrCreateRspData);
    memset(*rsp, 0, sizeof(SmtrCreateRspData));
    (*rsp)->instance = inst->instance;
    (*rsp)->gadgetHandle = inst->gadgetHandle;
    memcpy(&(*rsp)->gadgetSize, &inst->actualSize, sizeof(MsfSize));
    if (IS_SET(flags, SMTR_PROP_RETURN_LINKS))
    {
        if (!smtrCopyLinkList(inst->parse, &(*rsp)->links))
        {
            return SMTR_RESULT_ERROR;
        }
    }
    return SMTR_RESULT_OK;
}
Esempio n. 2
0
// Response to all POST request
// 3 requests are correct : 
// - /CreateFactory --> Receive Faust code / Compile Data / Send back JSON Interface
// - /CreateInstance --> Receive factoryIndex / Create instance 
// - /DeleteFactory --> Receive factoryIndex / Delete factory
int DSPServer::answerPost(MHD_Connection* connection, const char* url, const char* upload_data, size_t* upload_data_size, void** con_cls)
{
    dsp_server_connection_info* info = (dsp_server_connection_info*)*con_cls;
    
    if (*upload_data_size != 0) {
        return info->postProcess(upload_data, upload_data_size);
    } else {
        
        if (strcmp(url, "/CreateFactory") == 0) {
            return createFactory(connection, info);
        } else if (strcmp(url, "/CrossCompileFactory") == 0) {
            return crossCompileFactory(connection, info);
        } else if (strcmp(url, "/GetFactoryFromSHAKey") == 0) {
            return getFactoryFromSHAKey(connection, info);
        } else if(strcmp(url, "/DeleteFactory") == 0) {
            return deleteFactory(connection, info);
        } else if (strcmp(url, "/CreateInstance") == 0) {
            return createInstance(connection, info);
        } else if (strcmp(url, "/DeleteInstance") == 0) {
            return deleteInstance(connection, info);
        } else if (strcmp(url, "/StartInstance") == 0) {
            return start(connection, info);
        } else if(strcmp(url, "/StopInstance") == 0) {
            return stop(connection, info);
        } else {
            return sendPage(connection, "", MHD_HTTP_BAD_REQUEST, "text/html"); 
        }
    }
}
Esempio n. 3
0
void SubscriptionSet::subscriptionEventCallback(
   const UtlString* earlyDialogHandle,
   const UtlString* dialogHandle,
   SipSubscribeClient::SubscriptionState newState,
   const UtlString* subscriptionState)
{
   OsSysLog::add(FAC_RLS, PRI_DEBUG,
                 "SubscriptionSet::subscriptionEventCallback newState = %d, earlyDialogHandle = '%s', dialogHandle = '%s', subscriptionState = '%s'",
                 newState, mSubscriptionEarlyDialogHandle.data(),
                 dialogHandle->data(), subscriptionState->data());

   switch (newState)
   {
   case SipSubscribeClient::SUBSCRIPTION_INITIATED:
      break;
   case SipSubscribeClient::SUBSCRIPTION_SETUP:
   {
      // Put the subscription into pending state, as we have no
      // content for it yet.
      addInstance(dialogHandle->data(), "pending");
   }
   break;
   case SipSubscribeClient::SUBSCRIPTION_TERMINATED:
   {
      deleteInstance(dialogHandle->data(), "terminated",
                     subscriptionState->data());
   }
   break;
   }
}
//==============================================================================
static Error deleteImageCallback(void* data)
{
	Image* image = reinterpret_cast<Image*>(data);
	auto alloc = image->getAllocator();
	alloc.deleteInstance(image);
	return ErrorCode::NONE;
}
Esempio n. 5
0
void SubscriptionSet::subscriptionEventCallback(
   const UtlString* earlyDialogHandle,
   const UtlString* dialogHandle,
   SipSubscribeClient::SubscriptionState newState,
   const UtlString* subscriptionState)
{
   Os::Logger::instance().log(FAC_RLS, PRI_DEBUG,
                 "SubscriptionSet::subscriptionEventCallback newState = %d, earlyDialogHandle = '%s', dialogHandle = '%s', subscriptionState = '%s'",
                 newState, mSubscriptionEarlyDialogHandle.data(),
                 dialogHandle->data(), subscriptionState->data());

   switch (newState)
   {
   case SipSubscribeClient::SUBSCRIPTION_INITIATED:
      break;
   case SipSubscribeClient::SUBSCRIPTION_SETUP:
   {
      // There may be duplicate 'active' subscription callbacks, so first
      // check whether we already know of the subscription.
      if (!getInstance(dialogHandle->data()))
      {
         // Put the subscription into pending state, as we have no
         // content for it yet.
         addInstance(dialogHandle->data(), "pending");
      }
   }
   break;
   case SipSubscribeClient::SUBSCRIPTION_TERMINATED:
   {
      deleteInstance(dialogHandle->data(), "terminated",
                     subscriptionState->data());
   }
   break;
   }
}
Esempio n. 6
0
/*!
 * \brief Deallocates a #SmtrInstance struct.
 * 
 * \param inst The instance to free. If inst is NULL then all instances will
 * be removed.
 *****************************************************************************/
static void deleteInstance(SmtrInstance **inst)
{
    int i;
    if (inst) 
    {
        if (*inst)
        {
            if ((*inst)->gadgetHandle > 0) 
            {
                (void)MSF_WIDGET_RELEASE((*inst)->gadgetHandle);
            }
            
            if ((*inst)->stringHandle > 0)
            {
                (void)MSF_WIDGET_RELEASE((*inst)->stringHandle);
            }
            
            smtrFreeParseResult(&((*inst)->parse));
            if ((*inst)->charBuffer) 
            {
                SMTR_FREE((*inst)->charBuffer);
            }
            SMTR_FREE(*inst);
            *inst = NULL;
        }
    }
    else
    {
        /* Remove all instances */
        for(i = 0; i < SMTR_MAX_INSTANCES; i++)
        {
            deleteInstance(&mtrTextBoxes[i]);
        }        
    }
}
Esempio n. 7
0
/*!
 * \brief Terminates the SMTR component
 *****************************************************************************/
void smtrCtrlTerminate(void)
{
    /* Delete all instances */
    deleteInstance(NULL);
    MSF_LOG_MSG_OFF((MSF_LOG_DETAIL_HIGH, MSF_MODID_SMTR, SMTRCTRL_6B94163C9F0D6A7B8C4849A0B7FBF142, "SMTR CTRL: terminated\n"));

}
Esempio n. 8
0
bool DSPServer::deleteInstance(MHD_Connection* connection, dsp_server_connection_info* info)
{
    if (deleteInstance(info->fInstanceKey)) {
        return sendPage(connection, "", MHD_HTTP_OK, "text/html");
    } else {
        return sendPage(connection, info->fAnswer, MHD_HTTP_BAD_REQUEST, "text/html");
    }
}
Esempio n. 9
0
//==============================================================================
Material::~Material()
{
	auto alloc = m_vars.get_allocator();

	for(auto it : m_vars)
	{
		alloc.deleteInstance(it);
	}
}
Esempio n. 10
0
/* SplashWindow::hide
 * Hides (destroys) the splash window
 *******************************************************************/
void SplashWindow::hide()
{
	// Close
	Show(false);
	Close(true);

	// Destroy instance
	deleteInstance();
}
Esempio n. 11
0
/*!
 * \brief Deletes a text box.
 * 
 * \param callerFsm Caller FSM
 * \param returnSignal The signal to return when done.
 * \param instance The text box instance.
 *****************************************************************************/
SmtrResult smtrDeleteTextBox(int instance)
{
    if (instance < 0 || instance >= SMTR_MAX_INSTANCES) 
    {
        return SMTR_RESULT_ERROR;
    }
    deleteInstance(&mtrTextBoxes[instance]);
    return SMTR_RESULT_OK;
}
    void removeWindow (TopLevelWindow* const w)
    {
        checkFocusAsync();

        if (currentActive == w)
            currentActive = nullptr;

        windows.removeFirstMatchingValue (w);

        if (windows.size() == 0)
            deleteInstance();
    }
Esempio n. 13
0
    void removeWindow (TopLevelWindow* const w)
    {
        startTimer (10);

        if (currentActive == w)
            currentActive = nullptr;

        windows.removeValue (w);

        if (windows.size() == 0)
            deleteInstance();
    }
Esempio n. 14
0
PortalSectorBase::~PortalSectorBase()
{
	auto alloc = getSceneAllocator();

	if(m_shape)
	{
		alloc.deleteInstance(m_shape);
		m_shape = nullptr;
	}

	m_shapeStorageLSpace.destroy(alloc);
	m_shapeStorageWSpace.destroy(alloc);
	m_vertIndices.destroy(alloc);
}
Esempio n. 15
0
//==============================================================================
Material::~Material()
{
	auto alloc = m_resources->_getAllocator();

	m_progs.destroy(alloc);

	for(auto it : m_vars)
	{
		MaterialVariable* mvar = &(*it);
		mvar->destroy(alloc);
		alloc.deleteInstance(mvar);
	}

	m_vars.destroy(alloc);
}
Esempio n. 16
0
//==============================================================================
SceneNode::~SceneNode()
{
	auto alloc = getSceneAllocator();

	auto it = m_components.begin();
	auto end = m_components.begin() + m_componentsCount;
	for(; it != end; ++it)
	{
		SceneComponent* comp = *it;
		if(comp->getAutomaticCleanup())
		{
			alloc.deleteInstance(comp);
		}
	}

	Base::destroy(alloc);
	m_name.destroy(alloc);
	m_components.destroy(alloc);
}
Esempio n. 17
0
//==============================================================================
Error Material::populateVariables(const MaterialProgramCreator& loader)
{
	Error err = ErrorCode::NONE;

	U varCount = 0;
	for(const auto& in : loader.getInputVariables())
	{
		if(!in.m_constant)
		{
			++varCount;
		}
	}

	ANKI_CHECK(m_vars.create(m_resources->_getAllocator(), varCount));

	varCount = 0;
	for(const auto& in : loader.getInputVariables())
	{
		if(in.m_constant)
		{
			continue;
		}

		MaterialVariable* mtlvar = nullptr;

		switch(in.m_type)
		{
		// samplers
		case ShaderVariableDataType::SAMPLER_2D:
		case ShaderVariableDataType::SAMPLER_CUBE:
			{
				TextureResourcePointer tp;
				
				if(in.m_value.getSize() > 0)
				{
					ANKI_CHECK(tp.load(
						in.m_value.getBegin()->toCString(), m_resources));
				}

				auto alloc = m_resources->_getAllocator();
				MaterialVariableTemplate<TextureResourcePointer>* tvar = 
					alloc.newInstance<
					MaterialVariableTemplate<TextureResourcePointer>>();

				if(tvar)
				{
					err = tvar->create(alloc, in.m_name.toCString(), &tp, 1);

					if(err)
					{
						alloc.deleteInstance(tvar);
						tvar = nullptr;
					}
				}

				mtlvar = tvar;
			}
			break;
		case ShaderVariableDataType::FLOAT:
			mtlvar = MaterialVariableTemplate<F32>::_newInstance(in,
				m_resources->_getAllocator(), m_resources->_getTempAllocator());
			break;
		case ShaderVariableDataType::VEC2:
			mtlvar = MaterialVariableTemplate<Vec2>::_newInstance(in,
				m_resources->_getAllocator(), m_resources->_getTempAllocator());
			break;
		case ShaderVariableDataType::VEC3:
			mtlvar = MaterialVariableTemplate<Vec3>::_newInstance(in,
				m_resources->_getAllocator(), m_resources->_getTempAllocator());
			break;
		case ShaderVariableDataType::VEC4:
			mtlvar = MaterialVariableTemplate<Vec4>::_newInstance(in,
				m_resources->_getAllocator(), m_resources->_getTempAllocator());
			break;
		case ShaderVariableDataType::MAT3:
			mtlvar = MaterialVariableTemplate<Mat3>::_newInstance(in,
				m_resources->_getAllocator(), m_resources->_getTempAllocator());
			break;
		case ShaderVariableDataType::MAT4:
			mtlvar = MaterialVariableTemplate<Mat4>::_newInstance(in,
				m_resources->_getAllocator(), m_resources->_getTempAllocator());
			break;
		// default is error
		default:
			ANKI_ASSERT(0);
		}

		if(mtlvar == nullptr)
		{
			return ErrorCode::USER_DATA;
		}

		m_vars[varCount++] = mtlvar;
	}

	return ErrorCode::NONE;
}
Esempio n. 18
0
/* SplashWindow::hide
 * Hides (destroys) the splash window
 *******************************************************************/
void SplashWindow::hide()
{
	// Destroy instance
	deleteInstance();
}
Esempio n. 19
0
void PortingRules::createInstance(QString xmlFilePath)
{
    deleteInstance();
    theInstance  = new PortingRules(xmlFilePath);
}
Esempio n. 20
0
//==============================================================================
static void deleteImageCallback(void* data)
{
	Image* image = reinterpret_cast<Image*>(data);
	auto alloc = image->getAllocator();
	alloc.deleteInstance(image);
}
Esempio n. 21
0
int main(int argc, char** argv)
{
    const char* arg0 = System::findBaseName(argv[0]);

#ifdef PEGASUS_OS_ZOS
    // for z/OS set stdout and stderr to EBCDIC
    setEBCDICEncoding(STDOUT_FILENO);
    setEBCDICEncoding(STDERR_FILENO);
#endif
 
#ifdef PEGASUS_OS_PASE
    // Allow user group name larger than 8 chars in PASE environemnt
    setenv("PASE_USRGRP_LIMITED","N",1);
#endif
    // If no arguments, simply print usage message and terminate.
    MessageLoader::_useProcessLocale = true;

    if (argc == 1)
    {
        showUsage();
        exit(0);
    }

    //****** Show the args diagnostic display
    if (strcmp(argv[1],"displayargs") == 0)
    {
        cout << "argc = " << argc << endl;
        for (int i = 0; i < argc; i++)
            cout << "argv[" << i << "] = " << argv[i] << endl;
    }

    // Get options (from command line and from configuration file); this
    // removes corresponding options and their arguments from the command
    // line.
    OptionManager om;
    Options opts;
    try
    {
        // assume that the config file is local to directory where called.
        String testHome = ".";
        om.setMessagePath("pegasus/pegasusCLI");
        GetOptions(om, argc, argv, testHome);

        // Initialize all of the function input parameters.
        opts.location =  String::EMPTY;
#ifdef PEGASUS_HAS_SSL
        opts.ssl = false;
        opts.clientCert = String::EMPTY;
        opts.clientKey = String::EMPTY;
#endif
        opts.nameSpace = "root/cimv2";
        opts.cimCmd = "unknown";
        opts.className = CIMName();
        opts.objectName = "unknown";

        opts.isXmlOutput = false;
        opts.outputFormatType = OUTPUT_MOF;
        opts.user = String::EMPTY;
        opts.password = String::EMPTY;
        opts.verboseTest = false;

        opts.localOnly = true;
        opts.deepInheritance = false;
        opts.includeQualifiers = true;
        opts.includeClassOrigin = false;
        opts.assocClassName = String::EMPTY;
        opts.assocClass = CIMName();
        opts.resultClassName = String::EMPTY;
        opts.resultClass = CIMName();
        opts.role = String::EMPTY;
        opts.resultRole = String::EMPTY;
        opts.propertyListText = String::EMPTY;
        opts.propertyList.clear();
        opts.propertyName = String::EMPTY;
        opts.methodName = CIMName("unknown");
        opts.delay = 0;
        opts.trace = 0;
        opts.count= 97832;
        opts.repeat = 0;
        opts.time = false;
        opts.termCondition = 0;
        opts.debug = false;
        opts.queryLanguage = "WQL";

        // move any other input parameters left to the extraParams List
        CheckCommonOptionValues(om, argv, opts);

        /* note that this is in error since it assumes a fixed
           number of parameters will be used for all of the commands
           It needs to be expanded to allow for a variable minimum
           number of commands before it picks up any extras
        */
        if (argc > 2)
        {
            for (int i = 2 ; i < argc ; i++ )
                opts.extraParams.append(argv[i]);
        }
    }

    catch(CIMException& e)
    {
        cerr << argv[0] << " Caught CIMException during init: "
             << "\n" << e.getMessage()
             << endl;
        exit(1);
    }

    catch (Exception& e)
    {
        cerr << argv[0] << ": " << e.getMessage() << endl;
        exit(1);
    }
    catch(...)
    {
        cerr << argv[0] << " Caught General Exception During Init:" << endl;
        exit(1);
    }

    // if there is still an arg1, assume it is the command name.
    if (argc > 1)
    {
        opts.cimCmd = argv[1];
    }
    else
    {
        cout << " Command name must be first parameter or --c parameter."
            << " \n  ex. " << argv[0] <<  " enumerateclasses\n"
            << "Enter " << argv[0] << " -h for help."
            << endl;
        exit(1);
    }

    // if the trace option was set initialize the trace function.
    if (opts.trace != 0)
    {
        const char* tmpDir = getenv ("PEGASUS_TMP");
            if (tmpDir == NULL)
            {
                tmpDir = ".";
            }
            String traceFile (tmpDir);
            traceFile.append("/cliTrace.trc");
            Tracer::setTraceFile (traceFile.getCString());
            Tracer::setTraceComponents("ALL");
            Tracer::setTraceLevel(opts.trace);
    }

    // Find the command and save index in cmdIndex
    Uint32 cmdIndex = 0;
    
    if (opts.verboseTest && opts.debug)
        cout << "TEST Command = " << opts.cimCmd << endl;

    // Find the command or the short cut name
    for( ; cmdIndex < NUM_COMMANDS; cmdIndex++ )
    {
        if ((String::equalNoCase(opts.cimCmd, 
                CommandTable[cmdIndex].CommandName)) 
                ||
                (opts.cimCmd == CommandTable[cmdIndex].ShortCut))
            // Break if found
                    break;
    }

    Stopwatch totalElapsedExecutionTime;

    totalElapsedExecutionTime.start();

    // Now try to open the connection to the cim server
    CIMClient client;
    try
    {
        if (CommandTable[cmdIndex].ID_Command != ID_ShowOptions)
        {
            String host;
            HostLocator addr;
            if (opts.location != String::EMPTY)
            { 
                addr.setHostLocator(opts.location);
                if (!addr.isValid())
                {
                    throw InvalidLocatorException(opts.location);
                }
                host = addr.getHost();
            } 

            Uint32 portNumber = System::lookupPort( WBEM_HTTP_SERVICE_NAME,
                              WBEM_DEFAULT_HTTP_PORT );

            // Set up SSL port and flag for verbose display
            // if SSL included in build
            String useSSL;
#ifdef PEGASUS_HAS_SSL
            if (opts.ssl)
            {
                portNumber = System::lookupPort( WBEM_HTTPS_SERVICE_NAME,
                              WBEM_DEFAULT_HTTPS_PORT );
            }
            useSSL = " ssl=";
            useSSL.append((opts.ssl)? "true" : "false");
#endif

            if (host != String::EMPTY && addr.isPortSpecified())
            {
                portNumber = addr.getPort();
            }

            //check whether we should use connect() or connectLocal()
            //an empty location option indicates to use connectLocal()
            if (String::equal(host, String::EMPTY))
            {
                if (opts.verboseTest)
                {
                    cout << "Connect with connectLocal" << endl;
                }
                client.connectLocal();

            }
            else
            {
                if (opts.verboseTest)
                {
                    cout << "Connect to " << host
                        << " port=" << portNumber
                        << useSSL
                         << " for User="******"SSL options " 
                                << "Cert = " << opts.clientCert
                                << "clientKey = "  << opts.clientKey << endl;
                        }
                        client.connect(host,
                                       portNumber,
                                       SSLContext("", 
                                           opts.clientCert, 
                                           opts.clientKey,
                                           NULL, "ssl.rnd"),
                                       opts.user,
                                       opts.password);
                    } else
                    {
                        client.connect(host,
                                       portNumber,
                                       SSLContext("", NULL, "ssl.rnd"),
                                       opts.user,
                                       opts.password);
                    }
                } else //connect over HTTP
                {
                    client.connect(host, portNumber, opts.user, opts.password);
                }
#else
                client.connect(host, portNumber, opts.user, opts.password);
#endif
            }
        }
    }    
    catch(Exception &e)
    {
        cerr << "Pegasus Exception: " << e.getMessage() <<
              " Trying to connect to " << opts.location << endl;
        exit(1);
    }

    // Register for Client statistics.
    ClientStatistics statistics = ClientStatistics();
    client.registerClientOpPerformanceDataHandler(statistics);

    if (opts.delay != 0)
    {
        // This was a test because of some delay caused problems.
        Threads::sleep(opts.delay * 1000);
    }

    // If the timeout is not zero, set the timeout for this connection.
    if (opts.connectionTimeout != 0)
    {
        client.setTimeout(opts.connectionTimeout * 1000);
    }

    // Save the total connect time.
    double totalConnectTime = opts.elapsedTime.getElapsed();

    double totalTime = 0;
    Uint32 repeatCount = opts.repeat;
    double maxTime = 0;
    double minTime = 10000000;

    Uint64 serverTotalTime = 0;
    Uint64 maxServerTime = 0;
    Uint64 minServerTime = 10000000;

    Uint64 rtTotalTime = 0;
    Uint64 maxRtTime = 0;
    Uint64 minRtTime = 10000000;

    // Process the input command within a try block.
    try
    {
        // Loop to repeat the command a number of times.
        do
        {
            // or exit with error through default of case logic
            switch(CommandTable[cmdIndex].ID_Command)
                {
                case ID_EnumerateInstanceNames :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    enumerateInstanceNames(client, opts);
                    break;

                case ID_EnumerateAllInstanceNames :
                    if (!_getClassNameInput(argc, argv, opts, false))
                        exit(1);
                    enumerateAllInstanceNames(client, opts);
                    break;

                case ID_EnumerateInstances :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    enumerateInstances(client, opts);
                    break;
                case ID_GetInstance :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    getInstance(client, opts);
                    break;

                case ID_EnumerateClassNames :
                    if (!_getClassNameInput(argc, argv, opts, false))
                        exit(1);
                    enumerateClassNames(client, opts);
                    break;

                case ID_EnumerateClasses :
                    if (!_getClassNameInput(argc, argv, opts, false))
                        exit(1);
                    enumerateClasses(client, opts);
                    break;

                case ID_GetClass :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    getClass(client, opts);
                    break;

                case ID_CreateInstance :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    createInstance(client, opts);
                    break;

                case ID_DeleteInstance :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    deleteInstance(client, opts);
                    break;

                case ID_CreateClass :
                    cerr << "CreateClass not implemented" << endl;
                    break;

                case ID_DeleteClass :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    deleteClass(client, opts);
                    break;

                case ID_GetProperty :
                    if (argc != 4)
                    {
                        cout << "Usage: " << arg0 <<
                            " getproperty <instancename> <propertyname>" << 
                            endl;
                        exit(1);
                    }

                    opts.instanceName = argv[2];
                    opts.inputObjectName = argv[2];
                    opts.propertyName = argv[3];

                    getProperty(client, opts);
                    break;

                case ID_SetProperty :
                    if (argc != 5)
                        cout <<"Usage: " << arg0 << 
                          " setproperty instancename propertyname value "
                           << endl;
                    setProperty(client, opts);
                    break;

                case ID_EnumerateQualifiers :
                    enumerateQualifiers(client, opts);
                    break;

                case ID_SetQualifier :
                    cerr << "SetQualifer not implemented" << endl;
                        exit(1);
                    break;

                case ID_GetQualifier :
                    if (!_getQualifierNameInput(argc, argv, opts))
                        exit(1);
                    getQualifier(client, opts);
                    break;

                case ID_DeleteQualifier :
                    if (!_getQualifierNameInput(argc, argv, opts))
                        exit(1);
                    deleteQualifier(client, opts);
                    break;

                /* Reference params are
                    [IN] <objectName> ObjectName,
                    [IN,OPTIONAL,NULL] <className> ResultClass = NULL,
                    [IN,OPTIONAL,NULL] string Role = NULL,
                    [IN,OPTIONAL] boolean IncludeQualifiers = false,
                    [IN,OPTIONAL] boolean IncludeClassOrigin = false,
                    [IN,OPTIONAL,NULL] string PropertyList [] = NULL
                */
                case ID_References  :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    references(client, opts);
                    break;

                case ID_ReferenceNames :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    referenceNames(client, opts);
                    break;

                case ID_Associators :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    associators(client, opts);
                    break;

                case ID_AssociatorNames :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    associatorNames(client,opts);
                    break;

                case ID_EnumerateNamespaces :
                    // Note that the following constants are fixed here.  We
                    // should be getting them from the environment to assure
                    // that others know that we are using them.
                    opts.className = CIMName("CIM_Namespace");
                    if (argc > 2)
                    {
                        opts.nameSpace = argv[2];
                        opts.inputObjectName = argv[2];
                    }
                    else
                        // set nameSpace to interop namespace name
                        opts.nameSpace = 
                            PEGASUS_NAMESPACENAME_INTEROP.getString();

                    enumerateNamespaces_Namespace(client,opts);
                    break;

                    /*
                        CIMValue invokeMethod(
                            const CIMNamespaceName& nameSpace,
                            const CIMObjectPath& instanceName,
                            const CIMName& methodName,
                            const Array<CIMParamValue>& inParameters,

                    Array<CIMParamValue>& outParameters
                    */
                case ID_InvokeMethod :
                    if (argc < 4)
                    {
                        cout << "Usage: InvokeMethod requires that object and"
                            " method names be specified.\n"
                            "Input parameters are optional and can be"
                            " specified with the -ip option or as"
                            " additional parameters to this call. "
                            "Enter each input parameter as name=value"
                            " (no spaces around equal sign)."
                            << endl;
                        exit(1);
                    }
                    opts.objectName = argv[2];
                    opts.inputObjectName = argv[2];
                    opts.methodName = CIMName(argv[3]);

                    // If there are any extra arguments they must be parameters
                    // These parameters  can be used in addtion to parameters
                    // ifrom the -ip option setting. Parameters found here must
                    // be key=value pairs or they will generate an exception.
                    if (argc > 4)
                    {
                        // get input params from command line
                        for (Sint32 i = 4 ; i < argc; i++)
                        {
                            CIMParamValue pv;
                            String s = argv[i];
                            pv = _createMethodParamValue(s, opts);
                            opts.inParams.append(pv);
                        }
                    }
                    invokeMethod(client, opts);
                    break;

                case ID_ShowOptions :
                    showUsage();
                    break;

                case ID_ExecQuery:
                    opts.query = argv[2];
                    if (argc==4)
                        opts.queryLanguage = argv[3];
                    executeQuery(client, opts);
                    break;

                case ID_StatisticsOn:
                    setObjectManagerStatistics(client, true);
                    break;

                case ID_StatisticsOff:
                    setObjectManagerStatistics(client, false);
                    break;

                //case ID_Unknown :
                default:
                    cout << "Invalid Command. Command name must be first parm"
                            " or --c parameter."
                        << " \n  ex. " << arg0 << " enumerateclasses\n"
                        << "Enter " << argv[0] << " -h for help."
                        << endl;
                    exit(1);
                    break;
            }
            if (opts.repeat > 0)
            {
                if (opts.verboseTest)
                {
                    cout << "Repetitition " << opts.repeat << endl;
                }
                opts.repeat--;
                if (opts.time)
                {
                    totalTime += opts.saveElapsedTime;
                    maxTime = LOCAL_MAX(maxTime, opts.saveElapsedTime);
                    minTime = LOCAL_MIN(minTime, opts.saveElapsedTime);
                    rtTotalTime += (returnedPerformanceData.roundTripTime);
                    maxRtTime = LOCAL_MAX(maxRtTime,
                            returnedPerformanceData.roundTripTime);
                    minRtTime = LOCAL_MIN(minRtTime,
                            returnedPerformanceData.roundTripTime);

                    if (returnedPerformanceData.serverTimeKnown)
                    {
                        serverTotalTime += (returnedPerformanceData.serverTime);
                        maxServerTime = LOCAL_MAX(maxServerTime,
                                returnedPerformanceData.serverTime);
                        minServerTime = LOCAL_MIN(minServerTime,
                                returnedPerformanceData.serverTime);
                    }
                }
            }
        } while (opts.repeat > 0  );

        if (opts.time)
        {
            if (repeatCount == 0)
            {
                cout << CommandTable[cmdIndex].CommandName
                    << " "
                    << opts.inputObjectName
                    << " Time= "
                    << opts.saveElapsedTime
                    << " Sec "
                    << " SvrTime= "
                    << CIMValue(returnedPerformanceData.serverTime).toString()
                    << " us "
                    << " RtTime= "
                    << CIMValue(returnedPerformanceData.roundTripTime).
                           toString()
                    << " us "
                    << "Req size= "
                    << CIMValue(returnedPerformanceData.requestSize).toString()
                    << " b Resp size= "
                    << CIMValue(returnedPerformanceData.responseSize).toString()
                    << " b"
                    << endl;
            }
            else
            {
                cout << CommandTable[cmdIndex].CommandName
                    << " "
                    << opts.inputObjectName
                    << " Total Time "
                    << totalTime
                    << " for "
                    << repeatCount
                    << " ops. Avg= "
                    << (totalTime * 1000000)/repeatCount
                    << " us min= "
                    << minTime * 1000000
                    << " us max= "
                    << (maxTime * 1000000) 
                    << " us SvrTime avg= "
                    << CIMValue(serverTotalTime/repeatCount).toString()
                    << " us SvrTime min= "
                    << CIMValue(minServerTime).toString()
                    << " us SvrTime max= "
                    << CIMValue(maxServerTime).toString()
                    << " us"
                    << " RtTime avg= "
                    << CIMValue(rtTotalTime/repeatCount).toString()
                    << " us RtTime min= "
                    << CIMValue(minRtTime).toString()
                    << " us RtTime max= "
                    << CIMValue(maxRtTime).toString()
                    << " us"
                    << endl;
            }
        }
    }
    catch(CIMException& e)
    {
        cerr << argv[0] << " CIMException: "<<" Cmd= " << opts.cimCmd
            << " Object= " << opts.inputObjectName
             << "\n" << e.getMessage()
             << endl;
        opts.termCondition = 1;
    }
    catch(Exception& e)
    {
        PEGASUS_STD(cerr) << argv[0] << " Pegasus Exception: " << e.getMessage()
                <<  ". Cmd = " << opts.cimCmd 
                << " Object = " << opts.inputObjectName
                << PEGASUS_STD(endl);
            opts.termCondition = 1;
    }
    catch(...)
    {
        cerr << argv[0] << " Caught General Exception:" << endl;
        opts.termCondition = 1;
    }

    totalElapsedExecutionTime.stop();

    if (opts.time)
    {
        // if abnormal term, dump all times
        if (opts.termCondition == 1)
        {
            cout << "Exception" << endl;
            cout << "Prev Time " << opts.saveElapsedTime << " Sec" << endl;
            opts.saveElapsedTime = opts.elapsedTime.getElapsed();
            cout << "Last Time " << opts.saveElapsedTime << " Sec" << endl;
            cout << "Total Time " << totalTime << " for "
                << repeatCount << " operations. Avg.= " << totalTime/repeatCount
                << " min= " << minTime << " max= " << maxTime << endl;
        }

        cout << "Total Elapsed Time= " << totalElapsedExecutionTime.getElapsed()
             << " Sec. Terminated at " << System::getCurrentASCIITime() << endl;
    }
    if (opts.delay != 0)
    {
        Threads::sleep(opts.delay * 1000);
    }
    return(opts.termCondition);
}
Esempio n. 22
0
int main(int , char** argv)
{
    verbose = getenv("PEGASUS_TEST_VERBOSE");

    const char* arg0 = argv[0];


    CIMClient client;
    if (!connectToHost(client))
    {
        cerr << "Connection to host failed. Terminating" << endl;
        exit(1);
    }

    Array<CIMObjectPath> paths;

    //
    //  Create instances that will have specified test properties in them
    //  that we can use for queries.  We used the class
    //  Test_CLITestProviderClass because it has a broad set of testable
    //  properties.
    //

    String id1 = "PropertyOpTest1";
    CIMInstance inst1 = buildInstance(client, id1);

    {
        setPropertyValue(inst1,"scalBool", CIMValue(true));
        setPropertyValue(inst1,"scalUint8",CIMValue(Uint8(12)));
        setPropertyValue(inst1,"scalSint8",CIMValue(Sint8(12)));
        setPropertyValue(inst1,"scalUint16",CIMValue(Uint16(500)));
        setPropertyValue(inst1,"scalSint16",CIMValue(Sint16(500)));

        setPropertyValue(inst1,"scalUint32",CIMValue(Uint32(9999)));
        setPropertyValue(inst1,"scalSint32",CIMValue(Sint32(9999)));

        setPropertyValue(inst1,"scalUint64",CIMValue(Uint64(9999)));
        setPropertyValue(inst1,"scalSint64",CIMValue(Sint64(9999)));

        setPropertyValue(inst1,"scalString",CIMValue(String("String1")));
        Array<Uint32> lArrayUint32;
        lArrayUint32.append(0);
        lArrayUint32.append(128);
        lArrayUint32.append(256);
        lArrayUint32.append(65536);
        lArrayUint32.append(4294967295);
        setPropertyValue(inst1,"arrayUint32",CIMValue(lArrayUint32));
    }

    CIMObjectPath p1 = createInstance(client, inst1);
    paths.append(p1);

    String id2 = "PropertyOpTest2";
    CIMInstance inst2 = buildInstance(client, id2);
    {
        setPropertyValue(inst2,"scalBool", CIMValue(false));
        setPropertyValue(inst2,"scalUint8",CIMValue(Uint8(20)));
        setPropertyValue(inst2,"scalSint8",CIMValue(Sint8(8)));
        setPropertyValue(inst2,"scalUint16",CIMValue(Uint16(1000)));
        setPropertyValue(inst2,"scalSint16",CIMValue(Sint16(500)));

        setPropertyValue(inst2,"scalUint32",CIMValue(Uint32(7698)));
        setPropertyValue(inst2,"scalSint32",CIMValue(Sint32(9999)));

        setPropertyValue(inst2,"scalUint64",CIMValue(Uint64(9999)));
        setPropertyValue(inst2,"scalSint64",CIMValue(Sint64(9999)));

        setPropertyValue(inst2,"scalString",CIMValue(String("String2")));
        Array<Uint32> lArrayUint32;
        lArrayUint32.append(0);
        lArrayUint32.append(128);
        lArrayUint32.append(256);
        lArrayUint32.append(165536);
        lArrayUint32.append(4294967295);
        lArrayUint32.append(876543);
        setPropertyValue(inst2,"arrayUint32",CIMValue(lArrayUint32));
    }

    CIMObjectPath p2 = createInstance(client, inst2);
    paths.append(p2);

    //
    //  Execute the query tests
    //

    testEnumerate(client, "scalBool = true", 2);
    testEnumerate(client,"scalUint32 = 7698", 1);
    testEnumerate(client, "scalString = 'String2'", 1);


    testEnumerate(client, "arrayUint32[5] = 876543", 1);
    testEnumerate(client, "ANY arrayUint32 = 876543", 1);
    testEnumerate(client, "scalString <> 'NoSuchString'", 3);
    testEnumerate(client, "scalString = 'String2'", 1);

    // the following are error tests

    testEnumerate(client, "scalUint32 = 'NotANumber'", 0, CIMStatusCode(15));
    testEnumerate(client, "scalUint32 = 123a", 0, CIMStatusCode(15));
    testEnumerate(client, "scalbool = 1234", 0, CIMStatusCode(15));

    // Test associator

    CIMObjectPath assoc =
        CIMObjectPath("Test_CLITestProviderClass.Id=\"Mike\"");
    testAssociators(client, "scalBool = true",assoc, 1);
    testAssociators(client, "scalBool = false",assoc, 0);

    // Cheap test because only possible comparison is cimobject path
    // and that means building correct object path for the query
    // KS_TODO create a valid CIMObjectPath and test it.
    testReferences(client, "scalBool = false", assoc,0);

    for (Uint32 i = 0; i < paths.size(); i++)
    {
        deleteInstance(client,paths[i]);
    }

cout << arg0 << " +++++ passed all tests.";

}