IM/MS/mmm/mapping.cpp

54 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Created by dongl on 23-4-23.
//
#include "mapping.h"
#include "SimpleIni.h"
#include "EnumMapping.h"
#include <fstream>
std::map<mp::MP_TYPE, handler*> mapping::map;
mapping::mapping() {
if (map.empty()) {
// CSimpleIniA ini;
// ini.SetUnicode();
// ini.LoadFile("/home/dongl/code/网络编程/IMS/config/db.ini");
// auto key_value = ini.GetSection("server-mapping");
// 用户验证证明
auto userProve = new UserController();
map.insert( std::pair<mp::MP_TYPE, handler*>(mp::MP_REQUEST_LOGIN, userProve));
map.insert( std::pair<mp::MP_TYPE, handler*>(mp::MP_REQUEST_REGISTER, userProve));
map.insert( std::pair<mp::MP_TYPE, handler*>(mp::MP_REQUEST_LOGOUT, userProve));
// 获取邮件验证码
auto peVerifCode = new CodeController();
map.insert( std::pair<mp::MP_TYPE, handler*>(mp::MP_REQUEST_CODE, peVerifCode));
// 用户添加好友群组类操作
auto improve = new UserFriendsController();
map.insert({mp::MP_TYPE::MP_REQUEST_FRIENDS, improve});
map.insert({mp::MP_TYPE::MP_REQUEST_GROUPS, improve});
///im controller
auto imController = new IMController();
map.insert({mp::MP_TYPE::MP_IM_MSG, imController});
map.insert({mp::MP_TYPE::MP_IM_PUSH_MSG, imController});
}
}
void mapping::run(const mp::MP_TYPE mpTYpe, std::shared_ptr<agreement_request>& request, std::shared_ptr<agreement_response>& response) {
mapping();
printf("[packet type]%s\n", myenumToString(mpTYpe));
// 取出需要的执行对象
auto fun = map.find(mpTYpe)->second;
// 开始执行 处理请求的数据
fun->run(request, response);
// 发送 响应数据
handler::resp(request, response);
}