Пример #1
0
//called by virtual void CLProgram::createKernels();
//those routines build the default arguments list;
CLKernel::CLKernel(CLProgram* owningProgram, String kernelName,
		CLKernelWorkLoadParams* defaultKernelWorkLoadParams,
		CLKernelArguments* kernelArguments) throw(SimulatorException)
:
	mKernelName(kernelName),
	mDefaultKernelWorkLoadParams(defaultKernelWorkLoadParams),
	mCLKernelArguments(kernelArguments)

{
	try
	{
		mKernel = cl::Kernel(
			owningProgram->mCLProgram,
			kernelName.c_str(),
			PARA_COMP_MANAGER->getLastCLErrorPtr()
		);
	}
	catch(cl::Error)
	{
		throw(SimulatorException(String("something went wrong when creating the CL kernel ") + kernelName));
	}

	validate();

}
Пример #2
0
cl::Event CLKernel::run(const EventVector& eventsToWaitFor) throw(SimulatorException)
{
	mCLKernelArguments->passArgsToKernel(this);

	if( (mDefaultKernelWorkLoadParams->mNumTotalWorkItems == 0 )
		|| (mDefaultKernelWorkLoadParams->mNumWorkItemsPerWorkGroup == 0 )
	)
	{
		throw(SimulatorException("mDefaultKernelWorkLoadParams to be used are invalid! provide custom params!"));
	}


	*(PARA_COMP_MANAGER->getLastCLErrorPtr())
		=
		PARA_COMP_MANAGER->getCommandQueue().enqueueNDRangeKernel(
			mKernel,
			cl::NullRange,
			cl::NDRange( (size_t) ( mDefaultKernelWorkLoadParams->mNumTotalWorkItems) ),
			cl::NDRange( (size_t) ( mDefaultKernelWorkLoadParams->mNumWorkItemsPerWorkGroup) ),
			& eventsToWaitFor,
			//PARA_COMP_MANAGER->getLastEventPtr()
			& mEventOfLastKernelExecution
		);

	//assign this event to global last event, if anyone is interested in it (don't know yet ;( );
	*(PARA_COMP_MANAGER->getLastEventPtr()) = mEventOfLastKernelExecution;

	return mEventOfLastKernelExecution;
;
}
void SimulatorRemoteResourceImpl::observe(ObserveType type,
        ObserveNotificationCallback callback)
{
    if (!callback)
    {
        OC_LOG(ERROR, TAG, "Invalid callback!");
        throw InvalidArgsException(SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
    }

    std::lock_guard<std::mutex> lock(m_observeMutex);
    if (m_observeState)
    {
        OC_LOG(WARNING, TAG, "Resource already in observe state !");
        throw SimulatorException(SIMULATOR_ERROR, "Resource is already being observed!");
    }

    OC::ObserveCallback observeCallback = [this, callback](const OC::HeaderOptions & headerOptions,
                                          const OC::OCRepresentation & rep, const int errorCode,
                                          const int sequenceNum)
    {
        // Convert OCRepresentation to SimulatorResourceModel
        SimulatorResourceModelSP repModel = SimulatorResourceModel::create(rep);
        callback(m_id, static_cast<SimulatorResult>(errorCode), repModel, sequenceNum);
    };

    OC::ObserveType observeType = OC::ObserveType::Observe;
    if (type == ObserveType::OBSERVE_ALL)
    {
        observeType = OC::ObserveType::ObserveAll;
    }

    try
    {
        OCStackResult ocResult = m_ocResource->observe(observeType, OC::QueryParamsMap(), observeCallback);
        if (OC_STACK_OK != ocResult)
        {
            throw SimulatorException(static_cast<SimulatorResult>(ocResult), OC::OCException::reason(ocResult));
        }
    }
    catch (OC::OCException &e)
    {
        throw SimulatorException(static_cast<SimulatorResult>(e.code()), e.reason());
    }

    m_observeState = true;
}
void SimulatorRemoteResourceImpl::cancelObserve()
{
    try
    {
        OCStackResult ocResult = m_ocResource->cancelObserve(OC::QualityOfService::HighQos);
        if (OC_STACK_OK != ocResult)
            throw SimulatorException(static_cast<SimulatorResult>(ocResult), OC::OCException::reason(ocResult));

        SIM_LOG(ILogger::INFO, "OBSERVE CANCEL request sent");
    }
    catch (OC::OCException &e)
    {
        throw SimulatorException(static_cast<SimulatorResult>(e.code()), e.reason());
    }

    std::lock_guard<std::mutex> lock(m_observeLock);
    m_observeState = false;
}
void SimulatorRemoteResourceImpl::cancelObserve()
{
    try
    {
        OCStackResult ocResult = m_ocResource->cancelObserve(OC::QualityOfService::HighQos);
        if (OC_STACK_OK != ocResult)
        {
            throw SimulatorException(static_cast<SimulatorResult>(ocResult), OC::OCException::reason(ocResult));
        }
    }
    catch (OC::OCException &e)
    {
        throw SimulatorException(static_cast<SimulatorResult>(e.code()), e.reason());
    }

    std::lock_guard<std::mutex> lock(m_observeMutex);
    m_observeState = false;
}
void SimulatorRemoteResourceImpl::observe(ObserveType type,
        ObserveNotificationCallback callback)
{
    VALIDATE_CALLBACK(callback)

    std::lock_guard<std::mutex> lock(m_observeLock);
    if (m_observeState)
    {
        throw SimulatorException(SIMULATOR_ERROR, "Resource is already being observed!");
    }

    OC::ObserveCallback observeCallback = std::bind(
            [](const OC::HeaderOptions & headerOptions, const OC::OCRepresentation & ocRep,
               const int errorCode, const int sqNum, std::string id, ObserveNotificationCallback callback)
    {
        SIM_LOG(ILogger::INFO, "Observe response received..." << "\n" << getPayloadString(ocRep));

        SimulatorResourceModelSP resourceModel(
            new  SimulatorResourceModel(SimulatorResourceModel::build(ocRep)));
        callback(id, static_cast<SimulatorResult>(errorCode), resourceModel, sqNum);
    }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4,
    m_id, callback);

    OC::ObserveType observeType = OC::ObserveType::Observe;
    if (type == ObserveType::OBSERVE_ALL)
        observeType = OC::ObserveType::ObserveAll;

    try
    {
        OCStackResult ocResult = m_ocResource->observe(observeType, OC::QueryParamsMap(), observeCallback);
        if (OC_STACK_OK != ocResult)
            throw SimulatorException(static_cast<SimulatorResult>(ocResult), OC::OCException::reason(ocResult));

        SIM_LOG(ILogger::INFO, "OBSERVE request sent");
    }
    catch (OC::OCException &e)
    {
        throw SimulatorException(static_cast<SimulatorResult>(e.code()), e.reason());
    }

    m_observeState = true;
}
Пример #7
0
std::shared_ptr<SimulatorResource> SimulatorManager::createResource(
    const std::string &configPath)
{
    VALIDATE_INPUT(configPath.empty(), "Empty path!")

    std::shared_ptr<SimulatorResource> resource =
        SimulatorResourceFactory::getInstance()->createResource(configPath);
    if (!resource)
        throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!");
    return resource;
}
Пример #8
0
std::vector<std::shared_ptr<SimulatorResource>> SimulatorManager::createResource(
            const std::string &configPath, unsigned int count)
{
    VALIDATE_INPUT(configPath.empty(), "Empty path!")
    VALIDATE_INPUT(!count, "Count is zero!")

    std::vector<std::shared_ptr<SimulatorResource>> resources =
                SimulatorResourceFactory::getInstance()->createResource(configPath, count);
    if (!resources.size())
        throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!");
    return resources;
}
void SimulatorSingleResourceImpl::setInterface(const std::string &interfaceType)
{
    VALIDATE_INPUT(interfaceType.empty(), "Interface type list is empty!")

    std::lock_guard<std::recursive_mutex> lock(m_objectLock);
    if (m_resourceHandle)
    {
        throw SimulatorException(SIMULATOR_OPERATION_NOT_ALLOWED,
                                 "Resource interface can not be reset when resource is started!");
    }

    m_interfaces = {interfaceType};
}
void SimulatorSingleResourceImpl::setURI(const std::string &uri)
{
    VALIDATE_INPUT(uri.empty(), "Uri is empty!")

    std::lock_guard<std::recursive_mutex> lock(m_objectLock);
    if (m_resourceHandle)
    {
        throw SimulatorException(SIMULATOR_OPERATION_NOT_ALLOWED,
                                 "URI can not be set when resource is started!");
    }

    m_uri = uri;
}
void SimulatorSingleResourceImpl::setName(const std::string &name)
{
    VALIDATE_INPUT(name.empty(), "Name is empty!")

    std::lock_guard<std::recursive_mutex> lock(m_objectLock);
    if (m_resourceHandle)
    {
        throw SimulatorException(SIMULATOR_OPERATION_NOT_ALLOWED,
                                 "Name can not be set when resource is started!");
    }

    m_name = name;
}
void SimulatorSingleResourceImpl::setInterface(const std::vector<std::string> &interfaceTypes)
{
    VALIDATE_INPUT(interfaceTypes.empty(), "Interface type list is empty!")

    std::lock_guard<std::recursive_mutex> lock(m_objectLock);
    if (m_resourceHandle)
    {
        throw SimulatorException(SIMULATOR_OPERATION_NOT_ALLOWED,
                                 "Resource interface can not be reset when resource is started!");
    }

    m_interfaces.clear();
    for (auto &interfaceType : interfaceTypes)
    {
        if (m_interfaces.end() ==
            std::find(m_interfaces.begin(), m_interfaces.end(), interfaceType))
        {
            m_interfaces.push_back(interfaceType);
        }
    }
}
Пример #13
0
void POSTRequestGenerator::startSending()
{
    // Check the representation
    if (!m_rep)
    {
        OC_LOG(ERROR, TAG, "Invalid Representation given!");
        throw SimulatorException(SIMULATOR_ERROR, "Invalid representation detected!");
    }

    // Check if the operation is already in progress
    std::lock_guard<std::mutex> lock(m_statusLock);
    if (m_status)
    {
        OC_LOG(ERROR, TAG, "Operation already in progress !");
        throw OperationInProgressException("Another POST request generation session is already in progress!");
    }

    // Create thread and start sending requests in dispatched thread
    m_thread = std::make_shared<std::thread>(&POSTRequestGenerator::SendAllRequests, this);
    m_status = true;
    m_thread->detach();
}