IM/MS/mmm/mapping.cpp

44 lines
1.3 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 UserProveController();
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 improve = new IMProveController();
map.insert({mp::MP_REQUEST_IM_ADD, improve});
}
}
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);
}