⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimom.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        else if (type == async_messages::REGISTERED_MODULE)            _registered_module_in_service(static_cast<RegisteredModule *>(msg));        else if (type == async_messages::DEREGISTERED_MODULE)            _deregistered_module_in_service(                static_cast<DeRegisteredModule *>(msg));    }    if (accepted == false)    {        _make_response(msg, async_results::CIM_NAK);    }}void cimom::register_module(RegisterCimService *msg){    // first see if the module is already registered    Uint32 result = async_results::OK;    if (0 != get_module_q(msg->name))        result = async_results::MODULE_ALREADY_REGISTERED;    else    {        AutoPtr<message_module> new_mod(new message_module(            msg->name,            msg->capabilities,            msg->mask,            msg->queue));        if (new_mod.get() == 0)            result = async_results::INTERNAL_ERROR;        else        {            try            {                _modules.insert_front(new_mod.get());            }            catch (IPCException&)            {                result = async_results::INTERNAL_ERROR;                new_mod.reset();            }        }        new_mod.release();    }    AutoPtr<AsyncReply> reply(new AsyncReply(        async_messages::REPLY,        0,        msg->op,        result,        msg->resp,        msg->block));    _completeAsyncResponse(        static_cast<AsyncRequest *>(msg),        reply.get(),        ASYNC_OPSTATE_COMPLETE,        0);    reply.release();    return;}void cimom::deregister_module(Uint32 quid){    _modules.lock();    message_module *temp = _modules.front();    while (temp != 0)    {        if (temp->_q_id == quid)        {            _modules.remove(temp);            break;        }        temp = _modules.next_of(temp);    }    _modules.unlock();}void cimom::update_module(UpdateCimService* msg){    Uint32 result = async_results::MODULE_NOT_FOUND;    _modules.lock();    message_module *temp = _modules.front();    while (temp != 0)    {        if (temp->_q_id == msg->queue )        {            temp->_capabilities = msg->capabilities;            temp->_mask = msg->mask;            Time::gettimeofday(&(temp->_heartbeat));            result = async_results::OK;            break;        }        temp = _modules.next_of(temp);    }    _modules.unlock();    AutoPtr<AsyncReply> reply(new AsyncReply(        async_messages::REPLY,        0,        msg->op,        result,        msg->resp,        msg->block));    _completeAsyncResponse(        static_cast<AsyncRequest *>(msg),        reply.get(),        ASYNC_OPSTATE_COMPLETE,        0);    reply.release();    return;}void cimom::ioctl(AsyncIoctl* msg){    switch(msg->ctl)    {        case AsyncIoctl::IO_CLOSE:        {            // save my bearings            Thread *myself = msg->op->_thread_ptr;            cimom *service = static_cast<cimom *>(msg->op->_service_ptr);            // respond to this message.            AutoPtr<AsyncReply> reply(new AsyncReply( async_messages::REPLY,                                             0,                                             msg->op,                                             async_results::OK,                                             msg->resp,                                             msg->block));            _completeAsyncResponse(static_cast<AsyncRequest *>(msg),                                reply.get(),                                ASYNC_OPSTATE_COMPLETE,                                0);            reply.release();            // ensure we do not accept any further messages            // ensure we don't recurse on IO_CLOSE            if (_routed_queue_shutdown.get() > 0)                break;            // set the closing flag            service->_routed_queue_shutdown = 1;            // empty out the queue            while (1)            {                AsyncOpNode *operation;                try                {                    operation = service->_routed_ops.dequeue();                }                catch (IPCException&)                {                    break;                }                if (operation)                {                    service->_handle_cimom_op(operation, myself, service);                }                else                    break;            } // message processing loop            // shutdown the AsyncQueue            service->_routed_ops.close();            // exit the thread !            _die++;            return;        }        default:        {            Uint32 result = _ioctl(msg->ctl, msg->intp, msg->voidp);            AutoPtr<AsyncReply> reply(new AsyncReply(                async_messages::REPLY,                0,                msg->op,                result,                msg->resp,                msg->block));            _completeAsyncResponse(static_cast<AsyncRequest *>(msg),                                reply.get(),                                ASYNC_OPSTATE_COMPLETE,                                0);            reply.release();        }    }}Uint32 cimom::_ioctl(Uint32 code, Uint32 int_param, void *pointer_param){    return async_results::OK;}// fill an array with queue IDs of as many registered services// as match the request message parametersvoid cimom::find_service_q(FindServiceQueue* msg){    Array<Uint32> found;    _modules.lock();    message_module *ret = _modules.front();    while (ret != 0)    {        if (msg->name.size() > 0)        {            if (msg->name != ret->_name)            {                ret = _modules.next_of(ret);                continue;            }        }        if (msg->capabilities != 0)        {            if (! msg->capabilities & ret->_capabilities)            {                ret = _modules.next_of(ret);                continue;            }        }        if (msg->mask != 0)        {            if (! msg->mask & ret->_mask)            {                ret = _modules.next_of(ret);                continue;            }        }        // if we get to here, we "found" this service        found.append(ret->_q_id);        ret = _modules.next_of(ret);    }    _modules.unlock();    AutoPtr<FindServiceQueueResult> reply(new FindServiceQueueResult(        msg->op,        async_results::OK,        msg->resp,        msg->block,        found));    _completeAsyncResponse(        static_cast<AsyncRequest *>(msg),        reply.get(),        ASYNC_OPSTATE_COMPLETE,        0);    reply.release();    return;}// given a service Queue ID, return all registation data for// that servicevoid cimom::enumerate_service(EnumerateService* msg){    AutoPtr<EnumerateServiceResponse> reply;    _modules.lock();    message_module *ret = _modules.front();    while (ret != 0)    {        if (ret->_q_id == msg->qid)        {            reply.reset(new EnumerateServiceResponse(                msg->op,                async_results::OK,                msg->resp,                msg->block,                ret->_name,                ret->_capabilities,                ret->_mask,                ret->_q_id));            break;        }        ret = _modules.next_of(ret);    }    _modules.unlock();    if (reply.get() == 0)    {        reply.reset(new EnumerateServiceResponse(            msg->op,            async_results::MODULE_NOT_FOUND,            msg->resp,            msg->block,            String(),            0, 0, 0));    }    _completeAsyncResponse(        static_cast<AsyncRequest *>(msg),        reply.get(),        ASYNC_OPSTATE_COMPLETE,        0);    reply.release();    return;}Uint32 cimom::get_module_q(const String& name){    _modules.lock();    message_module *ret = _modules.front();    while (ret != 0)    {        if (ret->_name == name)            break;        ret = _modules.next_of(ret);    }    _modules.unlock();    if (ret != 0)        return ret->_q_id;    else        return 0;}// returns true if the list of registered modules changes since the parameterBoolean cimom::moduleChange(struct timeval last){    if (last.tv_sec >= _last_module_change.tv_sec)        if (last.tv_usec >= _last_module_change.tv_usec)            return false;    return true;}Uint32 cimom::getModuleCount(){    return _modules.size();}Uint32 cimom::getModuleIDs(Uint32* ids, Uint32 count){    if (ids == 0)        return 0;    message_module *temp = 0;    _modules.lock();    temp = _modules.front();    while (temp != 0 && count > 0)    {        *ids = temp->_q_id;        ids++;        count--;        temp = _modules.next_of(temp);    }    _modules.unlock();    while (count > 0)    {        *ids = 0;        ids++;        count--;    }    return _modules.size();}AsyncOpNode* cimom::get_cached_op(){    AutoPtr<AsyncOpNode> op(new AsyncOpNode());    op->_state = ASYNC_OPSTATE_UNKNOWN;    op->_flags = ASYNC_OPFLAGS_SINGLE | ASYNC_OPFLAGS_NORMAL |        ASYNC_OPFLAGS_META_DISPATCHER;    return op.release();}void cimom::cache_op(AsyncOpNode* op){    PEGASUS_ASSERT(op->_state & ASYNC_OPSTATE_RELEASED);    delete op;}void cimom::set_default_op_timeout(const struct timeval* buffer){    if (buffer != 0)    {        _default_op_timeout.tv_sec = buffer->tv_sec;        _default_op_timeout.tv_usec = buffer->tv_usec;    }}void cimom::get_default_op_timeout(struct timeval* timeout) const{    if (timeout != 0)    {        timeout->tv_sec = _default_op_timeout.tv_sec;        timeout->tv_usec = _default_op_timeout.tv_usec;    }}void cimom::_registered_module_in_service(RegisteredModule* msg){    Uint32 result = async_results::MODULE_NOT_FOUND;    _modules.lock();    message_module *ret = _modules.front();    while (ret != 0)    {        if (ret->_q_id == msg->resp)        {            // see if the module is already registered            Uint32 i = 0;            for (; i < ret->_modules.size(); i++)            {                if (ret->_modules[i] == msg->_module)                {                    result = async_results::MODULE_ALREADY_REGISTERED;                    break;                }            }            if (result != async_results::MODULE_ALREADY_REGISTERED)            {                ret->_modules.append(msg->_module);                result = async_results::OK;            }            break;        }        ret = _modules.next_of(ret);    }    _modules.unlock();    _make_response(msg, result);}void cimom::_deregistered_module_in_service(DeRegisteredModule* msg){    Uint32 result = async_results::MODULE_NOT_FOUND;    _modules.lock();    message_module *ret = _modules.front();    while (ret != 0)    {        if (ret->_q_id == msg->resp)        {            Uint32 i = 0;            for (; i < ret->_modules.size(); i++)            {                if (ret->_modules[i] == msg->_module)                {                    ret->_modules.remove(i);                    result = async_results::OK;                    break;                }            }        }        ret = _modules.next_of(ret);    }    _modules.unlock();    _make_response(msg, result);}void cimom::_find_module_in_service(FindModuleInService* msg){    Uint32 result = async_results::MODULE_NOT_FOUND;    Uint32 q_id = 0;    _modules.lock();    message_module *ret = _modules.front();    while (ret != 0)    {        if (ret->get_capabilities() & module_capabilities::module_controller)        {            // see if the module is in this service            Uint32 i = 0;            for (; i < ret->_modules.size(); i++)            {                if (ret->_modules[i] == msg->_module)                {                    result = async_results::OK;                    q_id = ret->_q_id;                    break;                }            }        }        ret = _modules.next_of(ret);    }    _modules.unlock();    FindModuleInServiceResponse *response = new FindModuleInServiceResponse(        msg->op,        result,        msg->resp,        msg->block,        q_id);    _complete_op_node(        msg->op,        ASYNC_OPSTATE_COMPLETE,        0,        result);}PEGASUS_NAMESPACE_END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -