55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
//
|
|
// Created by dongl on 23-5-29.
|
|
//
|
|
|
|
#include "Storage.h"
|
|
#include "template/MsgTemplate.h"
|
|
|
|
#include <utility>
|
|
#include <thread>
|
|
|
|
MSG::Storage::Storage(TimeLine<StorageMsg *> *timeLine, db_base* db)
|
|
: m_timeLine(timeLine), m_db(db), m_db_name(""), m_table("") {}
|
|
|
|
MSG::Storage::Storage(std::string&& db_name, std::string&& table) : m_db_name(db_name), m_table(table) {
|
|
m_timeLine = new TimeLine<StorageMsg *>();
|
|
m_db = new db_base();
|
|
}
|
|
|
|
// 储存库 push
|
|
void MSG::Storage::push(StorageMsg* msg) {
|
|
// 添加至信箱 同步库
|
|
m_timeLine->push(msg);
|
|
}
|
|
|
|
void MSG::Storage::pull() {
|
|
auto coll = m_db->hit_db_coll(m_db_name, m_table);
|
|
}
|
|
|
|
|
|
void MSG::Storage::storage_push_queue() {
|
|
// 取mongo链接
|
|
auto coll = m_db->hit_db_coll(m_db_name, m_table);
|
|
|
|
std::function<void()> fun = [&] {
|
|
while (true) {
|
|
while (!m_timeLine->value().empty()) {
|
|
// 弹出msg队列 此cpp只负责储存库 不负责同步库
|
|
auto msg = m_timeLine->pull();
|
|
// 执行插入
|
|
coll.insert_one(MsgTemplate::session_msg(msg->msg_type, msg->session_type,
|
|
msg->message_id, msg->time, msg->account, msg->im_msg_data));
|
|
}
|
|
}
|
|
};
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
std::thread t(fun);
|
|
printf("%ld", t.get_id());
|
|
t.detach();
|
|
}
|
|
}
|
|
|
|
|
|
|