关闭

BussLogicProc

19人阅读 评论(0) 收藏 举报


/******************************************************************* 
 *  Copyright(c) 2016-2066 Simmake 
 *  All rights reserved. 
 *   
 *  File Name: 
 *  Description: 
 *   
 *  Create date: 
 *  Author: 
 ******************************************************************/  


#ifndef __BUSS_LOGIC_PROC_MASTER_SERVICE_H__
#define __BUSS_LOGIC_PROC_MASTER_SERVICE_H__


#include "BussLoginProc_global.h"
#include "CommandReqAndResp/CommandReqAndRespBase.h"
#include "TimerService.h"


namespace BussLogicProc
{


class BUSS_LOGIC_PROC_EXPORT MasterService
{
public:
    static MasterService* Instance();


public:
    void Start();
    void Stop();


private:
    MasterService();
    ~MasterService();


private:
    BasisFacility::ComandReqAndResp::CommandResponseBase* OnNotifyRequest( BasisFacility::ComandReqAndResp::CommandRequestBase* request );


    void ValidClientConnDataInfoMap();


private:
    static MasterService* pInstance; 


    BasisService::TimerService* timerService_clientConnDataInfoMap;
};


}


#endif      // __BUSS_LOGIC_PROC_MASTER_SERVICE_H__


// BussLogicProc.cpp : Defines the exported functions for the DLL application.
//


#include "stdafx.h"
#include "MasterService.h"
#include "RemoteCommService.h"
#include "DataBase/DbManager.h"
#include "CommandService/ICommandCreator.h"
#include "ServiceConfigManager.h"
#include "BussLogicServices/UsrSessionManager.h"
#include "BussLogicServices/ServiceRecordManager.h"
#include "RemoteCommService.h"
#include "LogManager.h"


using namespace BasisService;
using namespace BasisService::BussLogicService;
using namespace BasisFacility::ComandReqAndResp;
using namespace BasisService::CommandService;
using namespace RemoteComm;
using namespace BasisService::DataBase;
using namespace RemoteComm;


namespace BussLogicProc
{


MasterService* MasterService::pInstance = NULL;




MasterService* MasterService::Instance()
{
    if (!pInstance)
        pInstance = new MasterService;


    return pInstance;
}


MasterService::MasterService() : timerService_clientConnDataInfoMap(new TimerService)
{
    timerService_clientConnDataInfoMap->open( 60 * 1000, boost::bind(&MasterService::ValidClientConnDataInfoMap, this));
}


MasterService::~MasterService()
{


}


void MasterService::Start()
{
    // 启动运行日志记录模块
    LogManager::Instance()->SwithOn();
    LogManager::Instance()->Init();


    // 读取配置信息
    if ( !ServiceConfigManager::Instance()->Init() )
    {
        LogManager::Instance()->AppendLog( "服务配置文件读取失败\n数据中心站启动失败", LogManager::ERROR_LOG );
        return;
    }
    else
        LogManager::Instance()->AppendLog( "服务配置文件读取成功", LogManager::INFO_LOG );


    //  连接数据库,启动数据库模块
    LogManager::Instance()->AppendLog( "开始启动数据库模块...", LogManager::INFO_LOG );
    DbManager::Instance()->SetParam( ServiceConfigManager::Instance()->GetDbIp(),
                                                           ServiceConfigManager::Instance()->GetDbPort(), 
                                                           ServiceConfigManager::Instance()->GetDbUserName(),
                                                           ServiceConfigManager::Instance()->GetDbPassword(), 
                                                           ServiceConfigManager::Instance()->GetDbName() );


    if ( 0 != DbManager::Instance()->Init() )
    {
        LogManager::Instance()->AppendLog( "启动数据库模块失败\n数据中心站启动失败", LogManager::ERROR_LOG );
        return;
    }
    else
        LogManager::Instance()->AppendLog( "启动数据库模块成功", LogManager::INFO_LOG );


    // 启动Service Record 模块
    ServiceRecordManager::Instance()->Init();


    // 启动 UsrSessionManager  模块
    UsrSessionManager::Instance()->Init();


    // 然后启动通信服务,开启监听服务
    if (!RemoteCommService::Instance()->Init())
    {
        LogManager::Instance()->AppendLog( "初始化通信模块失败\n数据中心站启动失败", LogManager::ERROR_LOG );
        return;
    }
    else
        LogManager::Instance()->AppendLog( "初始化通信模块成功", LogManager::INFO_LOG );


    CommunicatorConfig cfg;
    cfg.commType = SERVER_COMMUNICATOR;
    cfg.portv4 = ServiceConfigManager::Instance()->GetMainServicePort();
    std::string serverCommunicatorId = RemoteCommService::Instance()->AddCommunicator(cfg);


    if (!RemoteCommService::Instance()->StartCommunicators())
    {
        LogManager::Instance()->AppendLog( "执行远程通信模块的StartCommunicators失败\n数据中心站启动失败", LogManager::ERROR_LOG );
        return;
    }
    else
        LogManager::Instance()->AppendLog( "执行远程通信模块的StartCommunicators成功", LogManager::INFO_LOG );


    RemoteCommService::Instance()->RegisterServerRequestNotify( serverCommunicatorId, boost::bind(&MasterService::OnNotifyRequest, this, _1));


    // 基本服务启动完毕
    LogManager::Instance()->AppendLog( "数据中心站启动成功", LogManager::INFO_LOG );
}


void MasterService::Stop()
{


}


CommandResponseBase* MasterService::OnNotifyRequest( CommandRequestBase* request )
{
    assert(request);
    
    if (!request)
        return NULL;


    ICommandCreator* pCommandCreator = CommandCreatorRegList::Instance()->GetCommandCreator(request->GetReqType());
    if (!pCommandCreator)
        return NULL;


     ICommand* pCommand = pCommandCreator->CreateCommand(request);
     if (!pCommand)
         return NULL;


     pCommand->Do();
     CommandResponseBase* response = pCommand->GetResponse();
     delete pCommand;


    return response;
}


void MasterService::ValidClientConnDataInfoMap()
{
    RemoteCommService::Instance()->ValidateClientConnDataInfoMap();
}


}

0
0

  相关文章推荐
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:49次
    • 积分:12
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档
    阅读排行
    评论排行