1
This commit is contained in:
parent
bef63f6cb5
commit
53a2b20896
@ -9,11 +9,11 @@ else()
|
||||
message("debug mode")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-Wall -g -fmodules-ts -std=c++20 -DNDEBUG -DDT_VIRTUAL_QUERYFILTER")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-Wall -g -std=c++17-DNDEBUG -DDT_VIRTUAL_QUERYFILTER")
|
||||
if (${ASAN})
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -fmodules-ts -std=c++20 -DMYDEBUG -DDT_VIRTUAL_QUERYFILTER -fsanitize=address -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=c++17 -DMYDEBUG -DDT_VIRTUAL_QUERYFILTER -fsanitize=address -fno-omit-frame-pointer")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -fmodules-ts -std=c++20 -DMYDEBUG -DDT_VIRTUAL_QUERYFILTER")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=c++17 -DMYDEBUG -DDT_VIRTUAL_QUERYFILTER")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
|
@ -1,8 +1,6 @@
|
||||
import a8m.constant;
|
||||
#include "pch.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
auto a = a8m::INVALID_SOCKET;
|
||||
//a8m::INVALID_SOCKET = 100;
|
||||
return 0;
|
||||
}
|
||||
|
64
third_party/a8/a8/a8.h
vendored
Normal file
64
third_party/a8/a8/a8.h
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <any>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <a8/args.h>
|
||||
#include <a8/result.h>
|
||||
#include <a8/types.h>
|
||||
#include <a8/list.h>
|
||||
#include <a8/xvalue.h>
|
||||
#include <a8/xobject.h>
|
||||
#include <a8/timer_attacher.h>
|
||||
#include <a8/singleton.h>
|
||||
|
||||
#include <a8/strutils.h>
|
||||
#include <a8/sysutils.h>
|
||||
|
||||
#define A8_SAFE_DELETE(p) { if(p){delete(p); (p)=nullptr;} }
|
||||
#define A8_DEFINE_RANGE_BIT(type, begin, end) ((((type)1) << (end + 1)) - 1) & (~((((type)1) << (begin + 0)) - 1))
|
||||
|
||||
#define A8_ABORT() do{printf("abort file:%s line:%d func:%s\n", __FILE__, __LINE__, __func__);fflush(stdout);fflush(stderr);abort();}while(0);
|
||||
|
||||
#define A8_DECLARE_ENUM(E, ...) \
|
||||
enum E \
|
||||
{ \
|
||||
__VA_ARGS__ \
|
||||
}; \
|
||||
template<> constexpr const char* GetEnumString<E>() { return #__VA_ARGS__; };
|
||||
|
||||
#define A8_DECLARE_CLASS_ENUM(E, T, ...) \
|
||||
enum class E : T \
|
||||
{ \
|
||||
__VA_ARGS__ \
|
||||
}; \
|
||||
template<> constexpr const char* GetEnumString<E>() { return #__VA_ARGS__; };
|
||||
|
||||
#define A8_MAKE_ANON_STRUCT_SHARED(...) \
|
||||
[] () \
|
||||
{ \
|
||||
struct Context \
|
||||
{ \
|
||||
__VA_ARGS__ \
|
||||
}; \
|
||||
return std::make_shared<Context>();}()
|
||||
|
||||
#define A8_MAKE_SMART_ANON_STRUCT_SHARED(...) \
|
||||
[] () \
|
||||
{ \
|
||||
struct Context : public std::enable_shared_from_this<Context> \
|
||||
{ \
|
||||
__VA_ARGS__; \
|
||||
std::function<void()> _destory_cb; \
|
||||
std::weak_ptr<Context> GetWp() { return shared_from_this();}; \
|
||||
~Context() { if (_destory_cb) { _destory_cb(); };}; \
|
||||
}; \
|
||||
return std::make_shared<Context>();}()
|
@ -1,11 +1,10 @@
|
||||
module;
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <any>
|
||||
|
||||
export module a8m.args;
|
||||
namespace a8 {
|
||||
|
||||
export namespace a8m {
|
||||
class Args
|
||||
{
|
||||
public:
|
||||
@ -13,7 +12,7 @@ export namespace a8m {
|
||||
Args(std::vector<std::any> args):args_(std::move(args)) {};
|
||||
|
||||
template <typename T>
|
||||
T Get(size_t index) const { /*return std::any_cast<T>(args_.at(index));*/ return T(); };
|
||||
T Get(size_t index) const { return std::any_cast<T>(args_.at(index)); };
|
||||
|
||||
private:
|
||||
std::vector<std::any> args_;
|
1
third_party/a8/a8/basehttpsession.cc
vendored
1
third_party/a8/a8/basehttpsession.cc
vendored
@ -2,6 +2,7 @@
|
||||
|
||||
#include <a8/basehttpsession.h>
|
||||
#include <a8/strutils.h>
|
||||
#include <a8/args.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
|
16
third_party/a8/a8/constant.cc
vendored
16
third_party/a8/a8/constant.cc
vendored
@ -1,16 +0,0 @@
|
||||
module;
|
||||
|
||||
export module a8m.constant;
|
||||
|
||||
export namespace a8m {
|
||||
constexpr int INVALID_FD() { return -1; }
|
||||
constexpr int INVALID_SOCKET() { return -1; }
|
||||
constexpr int INVALID_SOCKET_HANDLE() { return 0; }
|
||||
|
||||
constexpr int TIMER_EXEC_EVENT() { return 1; }
|
||||
constexpr int TIMER_DELETE_EVENT() { return 2; }
|
||||
constexpr int TIMER_DESTORY_EVENT() { return 3; }
|
||||
constexpr int TIMER_USER_EVENT() { return 66; }
|
||||
|
||||
constexpr float A8_PI() { return 3.1415926f; }
|
||||
}
|
14
third_party/a8/a8/tcpclient.cc
vendored
14
third_party/a8/a8/tcpclient.cc
vendored
@ -15,8 +15,6 @@
|
||||
|
||||
const int MAX_RECV_BUFFERSIZE = 1024 * 64;
|
||||
|
||||
import a8m.constant;
|
||||
|
||||
namespace a8
|
||||
{
|
||||
TcpClient::TcpClient(const std::string& remote_ip, int remote_port)
|
||||
@ -55,7 +53,7 @@ namespace a8
|
||||
|
||||
bool TcpClient::IsActive()
|
||||
{
|
||||
return socket_ != a8m::INVALID_SOCKET();
|
||||
return socket_ != a8::INVALID_SOCKET;
|
||||
}
|
||||
|
||||
bool TcpClient::Connected()
|
||||
@ -105,7 +103,7 @@ namespace a8
|
||||
bool TcpClient::ActiveStart()
|
||||
{
|
||||
socket_ = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (a8m::INVALID_SOCKET() == socket_) {
|
||||
if (a8::INVALID_SOCKET == socket_) {
|
||||
if (on_error) {
|
||||
on_error(this, errno);
|
||||
}
|
||||
@ -121,7 +119,7 @@ namespace a8
|
||||
on_error(this, errno);
|
||||
}
|
||||
::close(socket_);
|
||||
socket_ = a8m::INVALID_SOCKET();
|
||||
socket_ = a8::INVALID_SOCKET;
|
||||
return false;
|
||||
}
|
||||
//set nodelay
|
||||
@ -147,7 +145,7 @@ namespace a8
|
||||
void TcpClient::ActiveStop()
|
||||
{
|
||||
connected_ = false;
|
||||
if (socket_ != a8m::INVALID_SOCKET()) {
|
||||
if (socket_ != a8::INVALID_SOCKET) {
|
||||
shutdown(socket_, 2);
|
||||
::close(socket_);
|
||||
}
|
||||
@ -157,7 +155,7 @@ namespace a8
|
||||
delete worker_thread_;
|
||||
worker_thread_ = nullptr;
|
||||
}
|
||||
socket_ = a8m::INVALID_SOCKET();
|
||||
socket_ = a8::INVALID_SOCKET;
|
||||
}
|
||||
|
||||
void TcpClient::WorkerThreadProc()
|
||||
@ -195,7 +193,7 @@ namespace a8
|
||||
senderthread->join();
|
||||
delete senderthread;
|
||||
senderthread = nullptr;
|
||||
socket_ = a8m::INVALID_SOCKET();
|
||||
socket_ = a8::INVALID_SOCKET;
|
||||
}
|
||||
|
||||
void TcpClient::SenderThreadProc()
|
||||
|
4
third_party/a8/a8/tcpclient.h
vendored
4
third_party/a8/a8/tcpclient.h
vendored
@ -12,8 +12,6 @@ namespace std
|
||||
|
||||
#include <a8/types.h>
|
||||
|
||||
import a8m.constant;
|
||||
|
||||
namespace a8
|
||||
{
|
||||
class TcpClient
|
||||
@ -39,7 +37,7 @@ namespace a8
|
||||
std::string remote_address_;
|
||||
int remote_port_ = 0;
|
||||
|
||||
volatile int socket_ = a8m::INVALID_SOCKET();
|
||||
volatile int socket_ = a8::INVALID_SOCKET;
|
||||
volatile bool connected_ = false;
|
||||
volatile bool sender_thread_shutdown_ = false;
|
||||
volatile bool worker_thread_shutdown_ = false;
|
||||
|
35
third_party/a8/a8/tcplistener.cc
vendored
35
third_party/a8/a8/tcplistener.cc
vendored
@ -15,7 +15,6 @@
|
||||
#include <a8/tcpsessionpool.h>
|
||||
#include <a8/types.h>
|
||||
|
||||
import a8m.constant;
|
||||
|
||||
namespace a8
|
||||
{
|
||||
@ -23,7 +22,7 @@ namespace a8
|
||||
struct TcpListenerImpl
|
||||
{
|
||||
a8::TcpListener* master = nullptr;
|
||||
int listen_socket = a8m::INVALID_SOCKET();
|
||||
int listen_socket = a8::INVALID_SOCKET;
|
||||
std::thread* accept_thread = nullptr;
|
||||
std::thread* worker_thread = nullptr;
|
||||
volatile bool accept_thread_shutdown = false;
|
||||
@ -35,7 +34,7 @@ namespace a8
|
||||
unsigned short curr_socket_handle = 1000;
|
||||
unsigned short max_clients = 0xEFFF;
|
||||
a8::TcpSessionPool free_client_pool;
|
||||
volatile int epoll_fd = a8m::INVALID_FD();
|
||||
volatile int epoll_fd = a8::INVALID_FD;
|
||||
#if 0
|
||||
list_head session_list;
|
||||
#endif
|
||||
@ -45,7 +44,7 @@ namespace a8
|
||||
|
||||
bool IsActive()
|
||||
{
|
||||
return listen_socket != a8m::INVALID_SOCKET();
|
||||
return listen_socket != a8::INVALID_SOCKET;
|
||||
}
|
||||
|
||||
void SetActive(bool active)
|
||||
@ -68,7 +67,7 @@ namespace a8
|
||||
bool ActiveStart()
|
||||
{
|
||||
listen_socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if(listen_socket == a8m::INVALID_SOCKET()){
|
||||
if(listen_socket == a8::INVALID_SOCKET){
|
||||
if (master->on_error){
|
||||
master->on_error(master, a8::TCPLISTENER_E::TE_CREATE_ERR, errno);
|
||||
}
|
||||
@ -85,7 +84,7 @@ namespace a8
|
||||
master->on_error(master, a8::TCPLISTENER_E::TE_SETSOCKOPT_ERR, errno);
|
||||
}
|
||||
::close(listen_socket);
|
||||
listen_socket = a8m::INVALID_SOCKET();
|
||||
listen_socket = a8::INVALID_SOCKET;
|
||||
return false;
|
||||
}
|
||||
sockaddr_in sa;
|
||||
@ -100,7 +99,7 @@ namespace a8
|
||||
master->on_error(master, a8::TCPLISTENER_E::TE_BIND_ERR, errno);
|
||||
}
|
||||
::close(listen_socket);
|
||||
listen_socket = a8m::INVALID_SOCKET();
|
||||
listen_socket = a8::INVALID_SOCKET;
|
||||
return false;
|
||||
}
|
||||
if (::listen(listen_socket, max_clients) < 0) {
|
||||
@ -108,11 +107,11 @@ namespace a8
|
||||
master->on_error(master, a8::TCPLISTENER_E::TE_LISTEN_ERR, errno);
|
||||
}
|
||||
::close(listen_socket);
|
||||
listen_socket = a8m::INVALID_SOCKET();
|
||||
listen_socket = a8::INVALID_SOCKET;
|
||||
return false;
|
||||
}
|
||||
epoll_fd = ::epoll_create(max_clients);
|
||||
assert(epoll_fd != a8m::INVALID_FD());
|
||||
assert(epoll_fd != a8::INVALID_FD);
|
||||
accept_thread_shutdown = false;
|
||||
accept_thread = new std::thread(&a8::TcpListenerImpl::AcceptThreadProc, this);
|
||||
return true;
|
||||
@ -120,14 +119,14 @@ namespace a8
|
||||
|
||||
void ActiveStop()
|
||||
{
|
||||
if (listen_socket != a8m::INVALID_SOCKET()) {
|
||||
if (listen_socket != a8::INVALID_SOCKET) {
|
||||
::shutdown(listen_socket, SHUT_RDWR);
|
||||
::close(listen_socket);
|
||||
listen_socket = a8m::INVALID_SOCKET();
|
||||
listen_socket = a8::INVALID_SOCKET;
|
||||
}
|
||||
if(epoll_fd != a8m::INVALID_FD()) {
|
||||
if(epoll_fd != a8::INVALID_FD) {
|
||||
::close(epoll_fd);
|
||||
epoll_fd = a8m::INVALID_FD();
|
||||
epoll_fd = a8::INVALID_FD;
|
||||
}
|
||||
if (accept_thread) {
|
||||
accept_thread_shutdown = true;
|
||||
@ -305,13 +304,13 @@ namespace a8
|
||||
sockaddr_in addr;
|
||||
socklen_t addr_len = sizeof(sockaddr_in);
|
||||
while (!accept_thread_shutdown) {
|
||||
if (listen_socket == a8m::INVALID_SOCKET()) {
|
||||
if (listen_socket == a8::INVALID_SOCKET) {
|
||||
break;
|
||||
}
|
||||
addr_len = sizeof(sockaddr_in);
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
int sock = ::accept(listen_socket, (sockaddr*)&addr, (socklen_t*)&addr_len);
|
||||
if (sock != a8m::INVALID_SOCKET()) {
|
||||
if (sock != a8::INVALID_SOCKET) {
|
||||
if (accept_thread_shutdown) {
|
||||
::close(sock);
|
||||
} else {
|
||||
@ -362,7 +361,7 @@ namespace a8
|
||||
list_del_init(&session->session_entry);
|
||||
#endif
|
||||
client_hash.erase(itr);
|
||||
if (session->Socket() != a8m::INVALID_SOCKET()) {
|
||||
if (session->Socket() != a8::INVALID_SOCKET) {
|
||||
session->_ForceClose();
|
||||
}
|
||||
client_handle_hash.erase(session->socket_handle);
|
||||
@ -428,7 +427,7 @@ namespace a8
|
||||
|
||||
bool TcpListener::IsActive()
|
||||
{
|
||||
return impl_->listen_socket != a8m::INVALID_SOCKET();
|
||||
return impl_->listen_socket != a8::INVALID_SOCKET;
|
||||
}
|
||||
|
||||
bool TcpListener::SendClientMsg(unsigned short sockhandle, const char *buff, int buffLen)
|
||||
@ -458,7 +457,7 @@ namespace a8
|
||||
impl_->clients_mutex.lock();
|
||||
a8::TcpSession *p = GetClientSession(sockhandle);
|
||||
if(p){
|
||||
if(p->Socket() != a8m::INVALID_SOCKET()){
|
||||
if(p->Socket() != a8::INVALID_SOCKET){
|
||||
p->_ForceClose();
|
||||
}
|
||||
}
|
||||
|
27
third_party/a8/a8/types.h
vendored
27
third_party/a8/a8/types.h
vendored
@ -2,16 +2,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
import a8m.args;
|
||||
|
||||
namespace google
|
||||
{
|
||||
namespace protobuf
|
||||
{
|
||||
class Message;
|
||||
}
|
||||
}
|
||||
#include <a8/args.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
@ -26,14 +17,26 @@ namespace a8
|
||||
SendQueueNode* next;
|
||||
};
|
||||
|
||||
typedef std::function<void(const a8m::Args&)> CommonCbProc;
|
||||
typedef std::function<void(const a8m::Args*)> CommonCbProcEx;
|
||||
typedef std::function<void(const a8::Args&)> CommonCbProc;
|
||||
typedef std::function<void(const a8::Args*)> CommonCbProcEx;
|
||||
typedef std::weak_ptr<struct XTimerPtr> XTimerWp;
|
||||
typedef std::function<void(int, const a8::Args*)> TimerCb;
|
||||
|
||||
namespace reflect
|
||||
{
|
||||
class Class;
|
||||
}
|
||||
|
||||
const int INVALID_FD = -1;
|
||||
const int INVALID_SOCKET = -1;
|
||||
const int INVALID_SOCKET_HANDLE = 0;
|
||||
|
||||
const int TIMER_EXEC_EVENT = 1;
|
||||
const int TIMER_DELETE_EVENT = 2;
|
||||
const int TIMER_DESTORY_EVENT = 3;
|
||||
const int TIMER_USER_EVENT = 66;
|
||||
|
||||
const float A8_PI = 3.1415926f;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
4
third_party/a8/a8/udplistener.cc
vendored
4
third_party/a8/a8/udplistener.cc
vendored
@ -18,8 +18,6 @@
|
||||
#include <f8/udplog.h>
|
||||
#endif
|
||||
|
||||
import a8m.constant;
|
||||
|
||||
namespace a8
|
||||
{
|
||||
|
||||
@ -77,7 +75,7 @@ namespace a8
|
||||
master->on_error(errno);
|
||||
}
|
||||
::close(listen_socket);
|
||||
listen_socket = a8m::INVALID_SOCKET();
|
||||
listen_socket = a8::INVALID_SOCKET;
|
||||
return false;
|
||||
}
|
||||
sockaddr_in sa;
|
||||
|
16
third_party/a8/a8/xtimer.cc
vendored
16
third_party/a8/a8/xtimer.cc
vendored
@ -2,8 +2,6 @@
|
||||
#include <a8/macro.h>
|
||||
#include <a8/timer_attacher.h>
|
||||
|
||||
import a8m.constant;
|
||||
|
||||
enum TimerType_e
|
||||
{
|
||||
kTimeOutTimer = 0,
|
||||
@ -143,9 +141,9 @@ namespace a8
|
||||
base_->timer_tick = get_tick_count_func_(context_);
|
||||
InternalSetInterval
|
||||
(gc_time_,
|
||||
[this] (int event, const a8m::Args* args)
|
||||
[this] (int event, const a8::Args* args)
|
||||
{
|
||||
if (a8m::TIMER_EXEC_EVENT() == event) {
|
||||
if (a8::TIMER_EXEC_EVENT == event) {
|
||||
int i = 0;
|
||||
while (!list_empty(&base_->free_timer) &&
|
||||
base_->free_timer_num > cache_timer_num_ && i < 1000) {
|
||||
@ -210,7 +208,7 @@ namespace a8
|
||||
}
|
||||
}
|
||||
|
||||
void InternalFireEvent(xtimer_list* timer, int event, a8m::Args* args)
|
||||
void InternalFireEvent(xtimer_list* timer, int event, a8::Args* args)
|
||||
{
|
||||
if (timer->cb) {
|
||||
timer->cb(event, args);
|
||||
@ -245,11 +243,11 @@ namespace a8
|
||||
#endif
|
||||
if (is_destory) {
|
||||
if (timer->cb) {
|
||||
timer->cb(a8m::TIMER_DESTORY_EVENT(), nullptr);
|
||||
timer->cb(a8::TIMER_DESTORY_EVENT, nullptr);
|
||||
}
|
||||
} else {
|
||||
if (timer->cb) {
|
||||
timer->cb(a8m::TIMER_DELETE_EVENT(), nullptr);
|
||||
timer->cb(a8::TIMER_DELETE_EVENT, nullptr);
|
||||
}
|
||||
}
|
||||
timer->cb = nullptr;
|
||||
@ -344,7 +342,7 @@ namespace a8
|
||||
timer = list_first_entry(head, struct xtimer_list,entry);
|
||||
base->running_timer = timer;
|
||||
if (timer->cb) {
|
||||
timer->cb(a8m::TIMER_EXEC_EVENT(), nullptr);
|
||||
timer->cb(a8::TIMER_EXEC_EVENT, nullptr);
|
||||
}
|
||||
if (base_->running_timer) {
|
||||
switch (timer->timer_type) {
|
||||
@ -556,7 +554,7 @@ namespace a8
|
||||
return result;
|
||||
}
|
||||
|
||||
void XTimer::FireEvent(XTimerWp& timer_wp, int event, a8m::Args* args)
|
||||
void XTimer::FireEvent(XTimerWp& timer_wp, int event, a8::Args* args)
|
||||
{
|
||||
if (timer_wp.expired()) {
|
||||
abort();
|
||||
|
5
third_party/a8/a8/xtimer.h
vendored
5
third_party/a8/a8/xtimer.h
vendored
@ -4,11 +4,8 @@
|
||||
|
||||
#include <a8/types.h>
|
||||
|
||||
import a8m.args;
|
||||
|
||||
namespace a8
|
||||
{
|
||||
typedef std::function<void(int, const a8m::Args*)> TimerCb;
|
||||
typedef long long (*XGetTickCountFunc)(void*);
|
||||
|
||||
class Attacher;
|
||||
@ -31,7 +28,7 @@ namespace a8
|
||||
XTimerWp SetIntervalWp(int expire_time, TimerCb cb);
|
||||
XTimerWp SetIntervalWpEx(int expire_time, TimerCb cb, Attacher* attacher);
|
||||
|
||||
void FireEvent(XTimerWp& timer_wp, int event, a8m::Args* args);
|
||||
void FireEvent(XTimerWp& timer_wp, int event, a8::Args* args);
|
||||
void ModifyTime(XTimerWp& timer_wp, int expire_time);
|
||||
void ResetTimer(XTimerWp& timer_wp);
|
||||
void Delete(XTimerWp& timer_wp);
|
||||
|
511
third_party/f8/f8/app.cc
vendored
511
third_party/f8/f8/app.cc
vendored
@ -1,23 +1,21 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
|
||||
#include <a8/uuid.h>
|
||||
#include <a8/strutils.h>
|
||||
#include <a8/sysutils.h>
|
||||
#include <a8/xobject.h>
|
||||
|
||||
#include <f8/udplog.h>
|
||||
#include <f8/types.h>
|
||||
#include <f8/app.h>
|
||||
#include <f8/msgqueue.h>
|
||||
#include <f8/timer.h>
|
||||
#include <f8/protoutils.h>
|
||||
#include <f8/tglog.h>
|
||||
#include <f8/httpclientpool.h>
|
||||
#include <a8/queue.h>
|
||||
|
||||
static const int MAX_ZONE_ID = 100;
|
||||
static const int MAX_NODE_ID = 8;
|
||||
@ -34,227 +32,321 @@ static const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log";
|
||||
namespace f8
|
||||
{
|
||||
|
||||
bool App::Init()
|
||||
class AppImpl
|
||||
{
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
srand(time(nullptr));
|
||||
nowtime_ = time(nullptr);
|
||||
private:
|
||||
UserApp* user_app_ = nullptr;
|
||||
int argc_ = 0;
|
||||
char** argv_ = nullptr;
|
||||
int exit_code_ = 0;
|
||||
volatile bool terminated_ = false;
|
||||
int nowtime_ = 0;
|
||||
long long max_run_delay_time_ = 0;
|
||||
|
||||
if (!ParseOpt()) {
|
||||
exit_code_ = 1;
|
||||
return false;
|
||||
int zone_id_ = 0;
|
||||
int node_id_ = 0;
|
||||
int instance_id_ = 0;
|
||||
std::set<int> flags_;
|
||||
|
||||
a8::Queue queue_;
|
||||
std::atomic<long long> msgnode_size_ = {0};
|
||||
std::atomic<long long> working_msgnode_size_ = {0};
|
||||
|
||||
std::shared_ptr<a8::uuid::SnowFlake> uuid_;
|
||||
std::mutex *loop_mutex_ = nullptr;
|
||||
std::condition_variable *loop_cond_ = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
srand(time(nullptr));
|
||||
nowtime_ = time(nullptr);
|
||||
|
||||
if (!ParseOpt()) {
|
||||
exit_code_ = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
uuid_ = std::make_shared<a8::uuid::SnowFlake>();
|
||||
loop_mutex_ = new std::mutex();
|
||||
loop_cond_ = new std::condition_variable();
|
||||
|
||||
uuid_->SetMachineId((node_id_ - 1) * MAX_NODE_ID + instance_id_);
|
||||
InitLog();
|
||||
f8::MsgQueue::Instance()->Init();
|
||||
f8::Timer::Instance()->Init();
|
||||
f8::TGLog::Instance()->Init(user_app_->GetPkgName(), false, 0);
|
||||
f8::HttpClientPool::Instance()->Init(MAX_ALL_HTTP_NUM, MAX_SYS_HTTP_NUM, MAX_USER_HTTP_NUM);
|
||||
user_app_->Init();
|
||||
return true;
|
||||
}
|
||||
|
||||
uuid_ = std::make_shared<a8::uuid::SnowFlake>();
|
||||
loop_mutex_ = new std::mutex();
|
||||
loop_cond_ = new std::condition_variable();
|
||||
void UnInit()
|
||||
{
|
||||
user_app_->UnInit();
|
||||
f8::TGLog::Instance()->UnInit();
|
||||
f8::HttpClientPool::Instance()->UnInit();
|
||||
f8::Timer::Instance()->UnInit();
|
||||
f8::MsgQueue::Instance()->UnInit();
|
||||
UnInitLog();
|
||||
|
||||
uuid_->SetMachineId((node_id_ - 1) * MAX_NODE_ID + instance_id_);
|
||||
InitLog();
|
||||
f8::MsgQueue::Instance()->Init();
|
||||
f8::Timer::Instance()->Init();
|
||||
f8::TGLog::Instance()->Init(user_app_->GetPkgName(), false, 0);
|
||||
f8::HttpClientPool::Instance()->Init(MAX_ALL_HTTP_NUM, MAX_SYS_HTTP_NUM, MAX_USER_HTTP_NUM);
|
||||
user_app_->Init();
|
||||
return true;
|
||||
}
|
||||
delete loop_cond_;
|
||||
loop_cond_ = nullptr;
|
||||
delete loop_mutex_;
|
||||
loop_mutex_ = nullptr;
|
||||
}
|
||||
|
||||
void App::UnInit()
|
||||
{
|
||||
user_app_->UnInit();
|
||||
f8::TGLog::Instance()->UnInit();
|
||||
f8::HttpClientPool::Instance()->UnInit();
|
||||
f8::Timer::Instance()->UnInit();
|
||||
f8::MsgQueue::Instance()->UnInit();
|
||||
UnInitLog();
|
||||
int Run(int argc, char* argv[], UserApp* user_app)
|
||||
{
|
||||
argc_ = argc;
|
||||
argv_ = argv;
|
||||
user_app_ = user_app;
|
||||
int delta_time = 0;
|
||||
if (Init()) {
|
||||
a8::tick_t last_stat_tick = a8::XGetTickCount();
|
||||
while (!Terminated()) {
|
||||
a8::tick_t begin_tick = a8::XGetTickCount();
|
||||
nowtime_ = time(nullptr);
|
||||
f8::Timer::Instance()->Update();
|
||||
f8::MsgQueue::Instance()->Update();
|
||||
DispatchNetMsg();
|
||||
user_app->Update(delta_time);
|
||||
a8::tick_t end_tick = a8::XGetTickCount();
|
||||
if (end_tick - begin_tick > max_run_delay_time_) {
|
||||
max_run_delay_time_ = end_tick - begin_tick;
|
||||
}
|
||||
Schedule();
|
||||
end_tick = a8::XGetTickCount();
|
||||
if (end_tick - last_stat_tick > 0) {
|
||||
delta_time = end_tick - last_stat_tick;
|
||||
last_stat_tick = end_tick;
|
||||
} else {
|
||||
delta_time = 0;
|
||||
}
|
||||
}
|
||||
UnInit();
|
||||
}
|
||||
return exit_code_;
|
||||
}
|
||||
|
||||
delete loop_cond_;
|
||||
loop_cond_ = nullptr;
|
||||
delete loop_mutex_;
|
||||
loop_mutex_ = nullptr;
|
||||
}
|
||||
bool HasFlag(int flag)
|
||||
{
|
||||
return flags_.find(flag) != flags_.end();
|
||||
}
|
||||
|
||||
void NotifyLoopCond()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
loop_cond_->notify_all();
|
||||
}
|
||||
|
||||
long long NewNodeUuid()
|
||||
{
|
||||
return uuid_->Generate();
|
||||
}
|
||||
|
||||
const std::string NewGlobalUuid()
|
||||
{
|
||||
std::string id = a8::Format("%d%d", {100 + zone_id_, uuid_->Generate()});
|
||||
return id;
|
||||
}
|
||||
|
||||
void Schedule()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
bool has_task = false;
|
||||
{
|
||||
queue_.Fetch();
|
||||
if (!list_empty(queue_.GetWorkList())) {
|
||||
has_task = true;
|
||||
}
|
||||
}
|
||||
if (!has_task) {
|
||||
has_task = user_app_->HasTask();
|
||||
}
|
||||
if (!has_task) {
|
||||
int sleep_time = f8::Timer::Instance()->GetIdleTime();
|
||||
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
|
||||
} else {
|
||||
int sleep_time = 1;
|
||||
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
|
||||
}
|
||||
}
|
||||
|
||||
void DispatchNetMsg()
|
||||
{
|
||||
queue_.Fetch();
|
||||
list_head* work_list = queue_.GetWorkList();
|
||||
while (!list_empty(work_list)){
|
||||
MsgHdr* hdr = list_first_entry(work_list, MsgHdr, entry);
|
||||
list_del_init(&hdr->entry);
|
||||
user_app_->DispatchSocketMsg(hdr);
|
||||
--msgnode_size_;
|
||||
MsgHdr::Destroy(hdr);
|
||||
}
|
||||
}
|
||||
|
||||
void AddSocketMsg(int sockfrom,
|
||||
int sockhandle,
|
||||
long ip_saddr,
|
||||
unsigned short msgid,
|
||||
unsigned int seqid,
|
||||
const char *msgbody,
|
||||
int bodylen,
|
||||
int tag)
|
||||
{
|
||||
char *p = (char*)malloc(sizeof(MsgHdr) + bodylen);
|
||||
MsgHdr* hdr = (MsgHdr*)p;
|
||||
hdr->sockfrom = sockfrom;
|
||||
hdr->seqid = seqid;
|
||||
hdr->msgid = msgid;
|
||||
hdr->socket_handle = sockhandle;
|
||||
hdr->ip_saddr = ip_saddr;
|
||||
hdr->buf = p + sizeof(MsgHdr);
|
||||
hdr->buflen = bodylen;
|
||||
hdr->offset = 0;
|
||||
hdr->hum = nullptr;
|
||||
hdr->user_data = nullptr;
|
||||
hdr->tag = tag;
|
||||
if (bodylen > 0) {
|
||||
memmove((void*)hdr->buf, msgbody, bodylen);
|
||||
}
|
||||
++msgnode_size_;
|
||||
queue_.Push(&hdr->entry);
|
||||
NotifyLoopCond();
|
||||
}
|
||||
|
||||
bool ParseOpt()
|
||||
{
|
||||
int ch = 0;
|
||||
while ((ch = getopt(argc_, argv_, "z:n:i:f:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'z':
|
||||
{
|
||||
zone_id_ = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
{
|
||||
node_id_ = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
{
|
||||
instance_id_ = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(optarg, strings, ',');
|
||||
for (auto& str : strings) {
|
||||
flags_.insert(a8::XValue(str).GetInt());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (zone_id_ <= 0) {
|
||||
a8::XPrintf("启动失败,缺少-z参数\n", {});
|
||||
return false;
|
||||
} else if (node_id_ > MAX_ZONE_ID) {
|
||||
a8::XPrintf("启动失败,-z参数不能大于%d\n", {MAX_ZONE_ID});
|
||||
return false;
|
||||
} else if (node_id_ <= 0) {
|
||||
a8::XPrintf("启动失败,缺少-n参数\n", {});
|
||||
return false;
|
||||
} else if (node_id_ > MAX_NODE_ID) {
|
||||
a8::XPrintf("启动失败,-n参数不能大于%d\n", {MAX_NODE_ID});
|
||||
return false;
|
||||
} else if (instance_id_ <= 0) {
|
||||
a8::XPrintf("启动失败,缺少-i参数\n", {});
|
||||
return false;
|
||||
} else if (instance_id_ > MAX_INSTANCE_ID) {
|
||||
a8::XPrintf("启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
|
||||
return false;
|
||||
}
|
||||
a8::XPrintf("starting zone_id:%d node_id:%d instance_id:%d pid:%d\n",
|
||||
{
|
||||
zone_id_,
|
||||
node_id_,
|
||||
instance_id_,
|
||||
GetPid()
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
int GetPid()
|
||||
{
|
||||
return getpid();
|
||||
}
|
||||
|
||||
void InitLog()
|
||||
{
|
||||
std::string filename_fmt = PROJ_LOG_FILENAME_FMT;
|
||||
a8::ReplaceString(filename_fmt, "$pid",
|
||||
a8::XValue(f8::App::Instance()->GetPid()));
|
||||
|
||||
std::string proj_root_dir = a8::Format
|
||||
(PROJ_ROOT_FMT, {user_app_->GetPkgName()});
|
||||
std::string proj_log_root_dir = a8::Format
|
||||
(PROJ_LOG_ROOT_FMT, {user_app_->GetPkgName()});
|
||||
std::string log_file_name = a8::Format
|
||||
(PROJ_LOG_ROOT_FMT, {user_app_->GetPkgName()}) + "/" + filename_fmt;
|
||||
|
||||
a8::MkDir(proj_root_dir);
|
||||
a8::MkDir(proj_log_root_dir);
|
||||
a8::XPrintf("log_file_name:%s\n", {log_file_name});
|
||||
f8::UdpLog::Instance()->SetLogFileName(log_file_name);
|
||||
f8::UdpLog::Instance()->Init();
|
||||
f8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
|
||||
f8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
|
||||
f8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
|
||||
}
|
||||
|
||||
void UnInitLog()
|
||||
{
|
||||
f8::UdpLog::Instance()->UnInit();
|
||||
}
|
||||
|
||||
bool Terminated()
|
||||
{
|
||||
return terminated_;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
int App::Run(int argc, char* argv[], UserApp* user_app)
|
||||
{
|
||||
argc_ = argc;
|
||||
argv_ = argv;
|
||||
user_app_ = user_app;
|
||||
int delta_time = 0;
|
||||
if (Init()) {
|
||||
a8::tick_t last_stat_tick = a8::XGetTickCount();
|
||||
while (!Terminated()) {
|
||||
a8::tick_t begin_tick = a8::XGetTickCount();
|
||||
nowtime_ = time(nullptr);
|
||||
f8::Timer::Instance()->Update();
|
||||
f8::MsgQueue::Instance()->Update();
|
||||
DispatchNetMsg();
|
||||
user_app->Update(delta_time);
|
||||
a8::tick_t end_tick = a8::XGetTickCount();
|
||||
if (end_tick - begin_tick > max_run_delay_time_) {
|
||||
max_run_delay_time_ = end_tick - begin_tick;
|
||||
}
|
||||
Schedule();
|
||||
end_tick = a8::XGetTickCount();
|
||||
if (end_tick - last_stat_tick > 0) {
|
||||
delta_time = end_tick - last_stat_tick;
|
||||
last_stat_tick = end_tick;
|
||||
} else {
|
||||
delta_time = 0;
|
||||
}
|
||||
}
|
||||
UnInit();
|
||||
}
|
||||
return exit_code_;
|
||||
}
|
||||
|
||||
bool App::ParseOpt()
|
||||
{
|
||||
int ch = 0;
|
||||
while ((ch = getopt(argc_, argv_, "z:n:i:f:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'z':
|
||||
{
|
||||
zone_id_ = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
{
|
||||
node_id_ = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
{
|
||||
instance_id_ = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(optarg, strings, ',');
|
||||
for (auto& str : strings) {
|
||||
flags_.insert(a8::XValue(str).GetInt());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (zone_id_ <= 0) {
|
||||
a8::XPrintf("启动失败,缺少-z参数\n", {});
|
||||
return false;
|
||||
} else if (node_id_ > MAX_ZONE_ID) {
|
||||
a8::XPrintf("启动失败,-z参数不能大于%d\n", {MAX_ZONE_ID});
|
||||
return false;
|
||||
} else if (node_id_ <= 0) {
|
||||
a8::XPrintf("启动失败,缺少-n参数\n", {});
|
||||
return false;
|
||||
} else if (node_id_ > MAX_NODE_ID) {
|
||||
a8::XPrintf("启动失败,-n参数不能大于%d\n", {MAX_NODE_ID});
|
||||
return false;
|
||||
} else if (instance_id_ <= 0) {
|
||||
a8::XPrintf("启动失败,缺少-i参数\n", {});
|
||||
return false;
|
||||
} else if (instance_id_ > MAX_INSTANCE_ID) {
|
||||
a8::XPrintf("启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
|
||||
return false;
|
||||
}
|
||||
a8::XPrintf("starting zone_id:%d node_id:%d instance_id:%d pid:%d\n",
|
||||
{
|
||||
zone_id_,
|
||||
node_id_,
|
||||
instance_id_,
|
||||
GetPid()
|
||||
});
|
||||
return true;
|
||||
impl_ = std::make_unique<AppImpl>();
|
||||
return impl_->Run(argc, argv, user_app);
|
||||
}
|
||||
|
||||
bool App::HasFlag(int flag)
|
||||
{
|
||||
return flags_.find(flag) != flags_.end();
|
||||
return impl_->HasFlag(flag);
|
||||
}
|
||||
|
||||
void App::NotifyLoopCond()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
loop_cond_->notify_all();
|
||||
impl_->NotifyLoopCond();
|
||||
}
|
||||
|
||||
long long App::NewNodeUuid()
|
||||
{
|
||||
return uuid_->Generate();
|
||||
return impl_->NewNodeUuid();
|
||||
}
|
||||
|
||||
const std::string App::NewGlobalUuid()
|
||||
{
|
||||
std::string id = a8::Format("%d%d", {100 + zone_id_, uuid_->Generate()});
|
||||
return id;
|
||||
return impl_->NewGlobalUuid();
|
||||
}
|
||||
|
||||
int App::GetPid()
|
||||
{
|
||||
return getpid();
|
||||
}
|
||||
|
||||
void App::InitLog()
|
||||
{
|
||||
std::string filename_fmt = PROJ_LOG_FILENAME_FMT;
|
||||
a8::ReplaceString(filename_fmt, "$pid",
|
||||
a8::XValue(f8::App::Instance()->GetPid()));
|
||||
|
||||
std::string proj_root_dir = a8::Format
|
||||
(PROJ_ROOT_FMT, {user_app_->GetPkgName()});
|
||||
std::string proj_log_root_dir = a8::Format
|
||||
(PROJ_LOG_ROOT_FMT, {user_app_->GetPkgName()});
|
||||
std::string log_file_name = a8::Format
|
||||
(PROJ_LOG_ROOT_FMT, {user_app_->GetPkgName()}) + "/" + filename_fmt;
|
||||
|
||||
a8::MkDir(proj_root_dir);
|
||||
a8::MkDir(proj_log_root_dir);
|
||||
a8::XPrintf("log_file_name:%s\n", {log_file_name});
|
||||
f8::UdpLog::Instance()->SetLogFileName(log_file_name);
|
||||
f8::UdpLog::Instance()->Init();
|
||||
f8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
|
||||
f8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
|
||||
f8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
|
||||
}
|
||||
|
||||
void App::UnInitLog()
|
||||
{
|
||||
f8::UdpLog::Instance()->UnInit();
|
||||
}
|
||||
|
||||
void App::Schedule()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
bool has_task = false;
|
||||
{
|
||||
queue_.Fetch();
|
||||
if (!list_empty(queue_.GetWorkList())) {
|
||||
has_task = true;
|
||||
}
|
||||
}
|
||||
if (!has_task) {
|
||||
has_task = user_app_->HasTask();
|
||||
}
|
||||
if (!has_task) {
|
||||
int sleep_time = f8::Timer::Instance()->GetIdleTime();
|
||||
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
|
||||
} else {
|
||||
int sleep_time = 1;
|
||||
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
|
||||
}
|
||||
}
|
||||
|
||||
void App::DispatchNetMsg()
|
||||
{
|
||||
queue_.Fetch();
|
||||
list_head* work_list = queue_.GetWorkList();
|
||||
while (!list_empty(work_list)){
|
||||
MsgHdr* hdr = list_first_entry(work_list, MsgHdr, entry);
|
||||
list_del_init(&hdr->entry);
|
||||
user_app_->DispatchSocketMsg(hdr);
|
||||
--msgnode_size_;
|
||||
MsgHdr::Destroy(hdr);
|
||||
}
|
||||
return impl_->GetPid();
|
||||
}
|
||||
|
||||
void App::AddSocketMsg(int sockfrom,
|
||||
@ -266,25 +358,14 @@ namespace f8
|
||||
int bodylen,
|
||||
int tag)
|
||||
{
|
||||
char *p = (char*)malloc(sizeof(MsgHdr) + bodylen);
|
||||
MsgHdr* hdr = (MsgHdr*)p;
|
||||
hdr->sockfrom = sockfrom;
|
||||
hdr->seqid = seqid;
|
||||
hdr->msgid = msgid;
|
||||
hdr->socket_handle = sockhandle;
|
||||
hdr->ip_saddr = ip_saddr;
|
||||
hdr->buf = p + sizeof(MsgHdr);
|
||||
hdr->buflen = bodylen;
|
||||
hdr->offset = 0;
|
||||
hdr->hum = nullptr;
|
||||
hdr->user_data = nullptr;
|
||||
hdr->tag = tag;
|
||||
if (bodylen > 0) {
|
||||
memmove((void*)hdr->buf, msgbody, bodylen);
|
||||
}
|
||||
++msgnode_size_;
|
||||
queue_.Push(&hdr->entry);
|
||||
NotifyLoopCond();
|
||||
impl_->AddSocketMsg(sockfrom,
|
||||
sockhandle,
|
||||
ip_saddr,
|
||||
msgid,
|
||||
seqid,
|
||||
msgbody,
|
||||
bodylen,
|
||||
tag);
|
||||
}
|
||||
|
||||
}
|
||||
|
67
third_party/f8/f8/app.h
vendored
67
third_party/f8/f8/app.h
vendored
@ -1,18 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include <a8/singleton.h>
|
||||
#include <a8/queue.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
namespace uuid
|
||||
{
|
||||
class SnowFlake;
|
||||
}
|
||||
}
|
||||
|
||||
namespace f8
|
||||
{
|
||||
|
||||
@ -42,13 +29,13 @@ namespace f8
|
||||
bool HasFlag(int flag);
|
||||
long long NewNodeUuid();
|
||||
const std::string NewGlobalUuid();
|
||||
int GetZoneId() { return zone_id_; }
|
||||
int GetNodeId() { return node_id_; }
|
||||
int GetInstanceId() { return instance_id_; }
|
||||
int GetNowTime() { return nowtime_; };
|
||||
int GetZoneId();
|
||||
int GetNodeId();
|
||||
int GetInstanceId();
|
||||
int GetNowTime();
|
||||
int GetPid();
|
||||
auto Terminated() { return terminated_; };
|
||||
void Terminate() { terminated_ = true; };
|
||||
bool Terminated();
|
||||
void Terminate();
|
||||
void AddSocketMsg(int sockfrom,
|
||||
int sockhandle,
|
||||
long ip_saddr,
|
||||
@ -57,43 +44,15 @@ namespace f8
|
||||
const char *msgbody,
|
||||
int bodylen,
|
||||
int tag);
|
||||
char** GetArgv() { return argv_; }
|
||||
int GetArgc() { return argc_; }
|
||||
long long GetMsgNodeSize() { return msgnode_size_; }
|
||||
long long GetWorkingMsgNodeSize() { return working_msgnode_size_; }
|
||||
long long GetMaxRunDelayTime() { return max_run_delay_time_; }
|
||||
void ResetMaxRunDelayTime() { max_run_delay_time_ = 0; }
|
||||
char** GetArgv();
|
||||
int GetArgc();
|
||||
long long GetMsgNodeSize();
|
||||
long long GetWorkingMsgNodeSize();
|
||||
long long GetMaxRunDelayTime();
|
||||
void ResetMaxRunDelayTime();
|
||||
|
||||
private:
|
||||
bool Init();
|
||||
void UnInit();
|
||||
bool ParseOpt();
|
||||
void InitLog();
|
||||
void UnInitLog();
|
||||
void Schedule();
|
||||
void DispatchNetMsg();
|
||||
|
||||
private:
|
||||
UserApp* user_app_ = nullptr;
|
||||
int argc_ = 0;
|
||||
char** argv_ = nullptr;
|
||||
int exit_code_ = 0;
|
||||
volatile bool terminated_ = false;
|
||||
int nowtime_ = 0;
|
||||
long long max_run_delay_time_ = 0;
|
||||
|
||||
int zone_id_ = 0;
|
||||
int node_id_ = 0;
|
||||
int instance_id_ = 0;
|
||||
std::set<int> flags_;
|
||||
|
||||
a8::Queue queue_;
|
||||
std::atomic<long long> msgnode_size_ = {0};
|
||||
std::atomic<long long> working_msgnode_size_ = {0};
|
||||
|
||||
std::shared_ptr<a8::uuid::SnowFlake> uuid_;
|
||||
std::mutex *loop_mutex_ = nullptr;
|
||||
std::condition_variable *loop_cond_ = nullptr;
|
||||
std::unique_ptr<class AppImpl> impl_;
|
||||
};
|
||||
|
||||
}
|
||||
|
9
third_party/f8/f8/dataset.h
vendored
Normal file
9
third_party/f8/f8/dataset.h
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace f8
|
||||
{
|
||||
class DataSet
|
||||
{
|
||||
|
||||
};
|
||||
}
|
61
third_party/f8/f8/dbpool.cc
vendored
61
third_party/f8/f8/dbpool.cc
vendored
@ -1,25 +1,18 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <f8/types.h>
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include <mysql.h>
|
||||
|
||||
#include <a8/mysql.h>
|
||||
#include <a8/list.h>
|
||||
#include <a8/timer_attacher.h>
|
||||
#include <f8/udplog.h>
|
||||
#include <a8/mutable_xobject.h>
|
||||
|
||||
#include <f8/dbpool.h>
|
||||
#include <f8/msgqueue.h>
|
||||
#include <f8/utils.h>
|
||||
#include <f8/timer.h>
|
||||
|
||||
#if 0
|
||||
namespace f8
|
||||
{
|
||||
|
||||
@ -41,10 +34,14 @@ namespace f8
|
||||
std::vector<a8::XValue> _sql_params;
|
||||
a8::XObject conn_info;
|
||||
#endif
|
||||
#if 0
|
||||
a8::XParams param;
|
||||
#endif
|
||||
time_t add_time = 0;
|
||||
#if 0
|
||||
AsyncDBOnOkFunc on_ok = nullptr;
|
||||
AsyncDBOnErrorFunc on_error = nullptr;
|
||||
#endif
|
||||
f8::Attacher timer_attacher;
|
||||
};
|
||||
|
||||
@ -68,6 +65,7 @@ namespace f8
|
||||
|
||||
void Init()
|
||||
{
|
||||
#if 0
|
||||
loop_mutex_ = new std::mutex();
|
||||
loop_cond_ = new std::condition_variable();
|
||||
|
||||
@ -78,10 +76,12 @@ namespace f8
|
||||
work_node_ = nullptr;
|
||||
msg_mutex_ = new std::mutex();
|
||||
work_thread_ = new std::thread(&DBThread::WorkThreadProc, this);
|
||||
#endif
|
||||
}
|
||||
|
||||
void UnInit()
|
||||
{
|
||||
#if 0
|
||||
terminated_ = true;
|
||||
work_thread_->join();
|
||||
delete work_thread_;
|
||||
@ -95,10 +95,12 @@ namespace f8
|
||||
|
||||
delete loop_mutex_;
|
||||
loop_mutex_ = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void AddAsyncQuery(AsyncQueryNode* p)
|
||||
{
|
||||
#if 0
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
msg_mutex_->lock();
|
||||
if (bot_node_) {
|
||||
@ -110,12 +112,14 @@ namespace f8
|
||||
}
|
||||
msg_mutex_->unlock();
|
||||
loop_cond_->notify_all();
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void WorkThreadProc()
|
||||
{
|
||||
#if 0
|
||||
mysql_thread_init();
|
||||
|
||||
while (!terminated_) {
|
||||
@ -135,10 +139,12 @@ namespace f8
|
||||
last_conn_ = nullptr;
|
||||
}
|
||||
mysql_thread_end();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CheckDB()
|
||||
{
|
||||
#if 0
|
||||
if (a8::XGetTickCount() - last_checkdb_tick_ < 1000 * 60 * 5) {
|
||||
return;
|
||||
}
|
||||
@ -156,10 +162,12 @@ namespace f8
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProcessMsg()
|
||||
{
|
||||
#if 0
|
||||
if (!work_node_ && top_node_) {
|
||||
msg_mutex_->lock();
|
||||
work_node_ = top_node_;
|
||||
@ -174,10 +182,12 @@ namespace f8
|
||||
++DBPool::Instance()->exec_query_num;
|
||||
delete pdelnode;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void WaitLoopCond()
|
||||
{
|
||||
#if 0
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
{
|
||||
msg_mutex_->lock();
|
||||
@ -191,10 +201,12 @@ namespace f8
|
||||
if (!work_node_) {
|
||||
loop_cond_->wait_for(lk, std::chrono::seconds(10));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ReCreateConn(a8::XObject& conn_info)
|
||||
{
|
||||
#if 0
|
||||
if (last_query_) {
|
||||
delete last_query_;
|
||||
last_query_ = nullptr;
|
||||
@ -214,11 +226,13 @@ namespace f8
|
||||
)) {
|
||||
f8::InitMysqlConnection(last_query_);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NeedReCreateConn(a8::XObject& conn_info)
|
||||
{
|
||||
#if 0
|
||||
if (!last_conn_) {
|
||||
return true;
|
||||
}
|
||||
@ -230,11 +244,13 @@ namespace f8
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProcAsyncQuery(AsyncQueryNode* node)
|
||||
{
|
||||
#if 0
|
||||
if (NeedReCreateConn(node->conn_info)) {
|
||||
ReCreateConn(node->conn_info);
|
||||
}
|
||||
@ -322,6 +338,7 @@ namespace f8
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
@ -333,7 +350,7 @@ namespace f8
|
||||
a8::mysql::Query* last_query_ = nullptr;
|
||||
long long last_checkdb_tick_ = 0;
|
||||
|
||||
std::thread *work_thread_ = nullptr;
|
||||
//std::thread *work_thread_ = nullptr;
|
||||
AsyncQueryNode *top_node_ = nullptr;
|
||||
AsyncQueryNode *bot_node_ = nullptr;
|
||||
AsyncQueryNode *work_node_ = nullptr;
|
||||
@ -375,6 +392,7 @@ namespace f8
|
||||
|
||||
void AsyncSqlOnOk(long long seqid, DataSet* data_set)
|
||||
{
|
||||
#if 0
|
||||
AsyncQueryRequest* request = GetAsyncQueryRequest(seqid);
|
||||
if (!request) {
|
||||
return;
|
||||
@ -384,10 +402,12 @@ namespace f8
|
||||
}
|
||||
async_query_hash.erase(seqid);
|
||||
delete request;
|
||||
#endif
|
||||
}
|
||||
|
||||
void AsyncSqlOnError(long long seqid, int errcode, const std::string& errmsg)
|
||||
{
|
||||
#if 0
|
||||
AsyncQueryRequest* request = GetAsyncQueryRequest(seqid);
|
||||
if (!request) {
|
||||
return;
|
||||
@ -400,8 +420,10 @@ namespace f8
|
||||
}
|
||||
async_query_hash.erase(seqid);
|
||||
delete request;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
void InternalExecAsyncSql(int exec_type,
|
||||
a8::XObject& conn_info, const char* querystr, std::vector<a8::XValue>& args,
|
||||
a8::XParams& param, AsyncDBOnOkFunc on_ok, AsyncDBOnErrorFunc on_error, long long hash_code)
|
||||
@ -462,6 +484,7 @@ namespace f8
|
||||
&p->timer_attacher);
|
||||
++DBPool::Instance()->total_query_num;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
@ -488,7 +511,7 @@ namespace f8
|
||||
|
||||
void DBPool::Init()
|
||||
{
|
||||
impl_ = new DBPoolImpl();
|
||||
impl_ = std::make_unique<DBPoolImpl>();
|
||||
impl_->Init();
|
||||
MsgQueue::Instance()->RegisterCallBack
|
||||
(IM_DbPool,
|
||||
@ -512,7 +535,6 @@ namespace f8
|
||||
void DBPool::UnInit()
|
||||
{
|
||||
impl_->UnInit();
|
||||
delete impl_;
|
||||
impl_ = nullptr;
|
||||
}
|
||||
|
||||
@ -521,17 +543,20 @@ namespace f8
|
||||
impl_->SetThreadNum(thread_num);
|
||||
}
|
||||
|
||||
void DBPool::ExecAsyncQuery(a8::XObject conn_info, const char* querystr, std::vector<a8::XValue> args,
|
||||
a8::XParams param, AsyncDBOnOkFunc on_ok, AsyncDBOnErrorFunc on_error, long long hash_code)
|
||||
void DBPool::ExecAsyncQuery(int ds,
|
||||
const std::string sql,
|
||||
std::vector<a8::XValue> args,
|
||||
f8::DbQueryResultCb cb)
|
||||
{
|
||||
impl_->InternalExecAsyncSql(0, conn_info, querystr, args, param, on_ok, on_error, hash_code);
|
||||
|
||||
}
|
||||
|
||||
void DBPool::ExecAsyncScript(a8::XObject conn_info, const char* querystr, std::vector<a8::XValue> args,
|
||||
a8::XParams param, AsyncDBOnOkFunc on_ok, AsyncDBOnErrorFunc on_error, long long hash_code)
|
||||
void DBPool::ExecAsyncScript(int ds,
|
||||
const std::string sql,
|
||||
std::vector<a8::XValue> args,
|
||||
f8::DbExecResultCb cb)
|
||||
{
|
||||
impl_->InternalExecAsyncSql(1, conn_info, querystr, args, param, on_ok, on_error, hash_code);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
52
third_party/f8/f8/dbpool.h
vendored
52
third_party/f8/f8/dbpool.h
vendored
@ -1,41 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <f8/dataset.h>
|
||||
|
||||
#if 0
|
||||
namespace f8
|
||||
{
|
||||
typedef std::vector<std::vector<std::string>> DataSet;
|
||||
typedef void (*AsyncDBOnOkFunc)(a8::XParams& param, const DataSet* data_set);
|
||||
typedef void (*AsyncDBOnErrorFunc)(a8::XParams& param, int error_code, const std::string& error_msg);
|
||||
|
||||
class DBPoolImpl;
|
||||
class DbOpResult
|
||||
{
|
||||
public:
|
||||
virtual int GetErrCode() = 0;
|
||||
virtual std::string GetErrMsg() = 0;
|
||||
};
|
||||
|
||||
class DbQueryResult : public DbOpResult
|
||||
{
|
||||
public:
|
||||
virtual std::shared_ptr<f8::DataSet> GetDataSet() = 0;
|
||||
};
|
||||
|
||||
class DbExecResult : public DbOpResult
|
||||
{
|
||||
public:
|
||||
virtual long long GetLastInsertId() = 0;
|
||||
virtual long long GetRowsAffected() = 0;
|
||||
};
|
||||
|
||||
typedef std::function<void(std::shared_ptr<DbQueryResult>)> DbQueryResultCb;
|
||||
typedef std::function<void(std::shared_ptr<DbExecResult>)> DbExecResultCb;
|
||||
|
||||
class DBPool : public a8::Singleton<DBPool>
|
||||
{
|
||||
private:
|
||||
DBPool() {};
|
||||
friend class a8::Singleton<DBPool>;
|
||||
|
||||
public:
|
||||
AsyncDBOnErrorFunc on_dberror = nullptr;
|
||||
std::atomic<long long> total_query_num = {0};
|
||||
std::atomic<long long> exec_query_num = {0};
|
||||
std::atomic<long long> run_loop_num = {0};
|
||||
|
||||
public:
|
||||
void Init();
|
||||
void UnInit();
|
||||
void SetThreadNum(int thread_num);
|
||||
|
||||
//执行异步并行查询
|
||||
void ExecAsyncQuery(a8::XObject conn_info, const char* querystr, std::vector<a8::XValue> args,
|
||||
a8::XParams param, AsyncDBOnOkFunc on_ok, AsyncDBOnErrorFunc on_error, long long hash_code);
|
||||
void ExecAsyncQuery(int ds,
|
||||
const std::string sql,
|
||||
std::vector<a8::XValue> args,
|
||||
f8::DbQueryResultCb cb);
|
||||
//执行异步并行sql
|
||||
void ExecAsyncScript(a8::XObject conn_info, const char* querystr, std::vector<a8::XValue> args,
|
||||
a8::XParams param, AsyncDBOnOkFunc on_ok, AsyncDBOnErrorFunc on_error, long long hash_code);
|
||||
void ExecAsyncScript(int ds,
|
||||
const std::string sql,
|
||||
std::vector<a8::XValue> args,
|
||||
f8::DbExecResultCb cb);
|
||||
|
||||
private:
|
||||
DBPoolImpl* impl_ = nullptr;
|
||||
std::unique_ptr<class DBPoolImpl> impl_;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
3
third_party/f8/f8/dynmodule.cc
vendored
3
third_party/f8/f8/dynmodule.cc
vendored
@ -1,4 +1,5 @@
|
||||
#include "f8/dynmodule.h"
|
||||
#include <f8/internal/pch.h>
|
||||
#include <f8/dynmodule.h>
|
||||
|
||||
namespace f8
|
||||
{
|
||||
|
5
third_party/f8/f8/f8.h
vendored
Normal file
5
third_party/f8/f8/f8.h
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/a8.h>
|
||||
#include <f8/types.h>
|
||||
#include <f8/timer.h>
|
15
third_party/f8/f8/httpclientpool.cc
vendored
15
third_party/f8/f8/httpclientpool.cc
vendored
@ -1,7 +1,6 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <f8/types.h>
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
@ -27,8 +26,6 @@
|
||||
static const int AHE_NO_ERROR = 0;
|
||||
static const int AHE_NO_CONN = 1;
|
||||
|
||||
import a8m.args;
|
||||
|
||||
namespace f8
|
||||
{
|
||||
|
||||
@ -220,7 +217,7 @@ namespace f8
|
||||
if (xobj->ReadFromJsonString(response)) {
|
||||
f8::MsgQueue::Instance()->PostMsg
|
||||
(IM_HttpClientPool,
|
||||
a8m::Args
|
||||
a8::Args
|
||||
(
|
||||
{
|
||||
node->context_id,
|
||||
@ -231,7 +228,7 @@ namespace f8
|
||||
} else {
|
||||
f8::MsgQueue::Instance()->PostMsg
|
||||
(IM_HttpClientPool,
|
||||
a8m::Args
|
||||
a8::Args
|
||||
(
|
||||
{
|
||||
node->context_id,
|
||||
@ -244,7 +241,7 @@ namespace f8
|
||||
} else {
|
||||
f8::MsgQueue::Instance()->PostMsg
|
||||
(IM_HttpClientPool,
|
||||
a8m::Args
|
||||
a8::Args
|
||||
(
|
||||
{
|
||||
node->context_id,
|
||||
@ -406,7 +403,7 @@ namespace f8
|
||||
}
|
||||
f8::Timer::Instance()->SetTimeoutEx
|
||||
(1000 * 10,
|
||||
[p] (int event, const a8m::Args* args)
|
||||
[p] (int event, const a8::Args* args)
|
||||
{
|
||||
|
||||
},
|
||||
@ -449,7 +446,7 @@ namespace f8
|
||||
impl_->Init();
|
||||
MsgQueue::Instance()->RegisterCallBack
|
||||
(IM_HttpClientPool,
|
||||
[] (const a8m::Args& args)
|
||||
[] (const a8::Args& args)
|
||||
{
|
||||
--(HttpClientPool::Instance()->impl_->pending_num);
|
||||
#if 1
|
||||
|
5
third_party/f8/f8/httpclientpool.h
vendored
5
third_party/f8/f8/httpclientpool.h
vendored
@ -1,10 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <a8/xobject.h>
|
||||
#include <a8/singleton.h>
|
||||
|
||||
namespace f8
|
||||
{
|
||||
|
||||
|
3
third_party/f8/f8/internal/pch.h
vendored
Normal file
3
third_party/f8/f8/internal/pch.h
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include <f8/f8.h>
|
5
third_party/f8/f8/jsonhttprequest.cc
vendored
5
third_party/f8/f8/jsonhttprequest.cc
vendored
@ -1,9 +1,8 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <a8/strutils.h>
|
||||
#include <a8/mutable_xobject.h>
|
||||
|
||||
#include <f8/types.h>
|
||||
#include <f8/jsonhttprequest.h>
|
||||
|
||||
namespace f8
|
||||
@ -37,7 +36,7 @@ namespace f8
|
||||
if (cb_) {
|
||||
std::string response;
|
||||
resp_xobj_->ToJsonStr(response);
|
||||
cb_(a8m::Args({a8::HttpResponse(response)}));
|
||||
cb_(a8::Args({a8::HttpResponse(response)}));
|
||||
}
|
||||
resped_ = true;
|
||||
}
|
||||
|
5
third_party/f8/f8/jsonhttprequest.h
vendored
5
third_party/f8/f8/jsonhttprequest.h
vendored
@ -1,12 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/types.h>
|
||||
|
||||
import a8m.args;
|
||||
|
||||
namespace a8
|
||||
{
|
||||
class XObject;
|
||||
class MutableXObject;
|
||||
}
|
||||
|
||||
|
4
third_party/f8/f8/jsonlog.cc
vendored
4
third_party/f8/f8/jsonlog.cc
vendored
@ -1,11 +1,9 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <array>
|
||||
|
||||
#include <a8/sysutils.h>
|
||||
|
||||
#include <f8/types.h>
|
||||
#include <f8/jsonlog.h>
|
||||
|
||||
namespace f8
|
||||
|
3
third_party/f8/f8/jsonlog.h
vendored
3
third_party/f8/f8/jsonlog.h
vendored
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/xobject.h>
|
||||
#include <a8/singleton.h>
|
||||
|
||||
namespace f8
|
||||
{
|
||||
|
||||
|
19
third_party/f8/f8/msgqueue.cc
vendored
19
third_party/f8/f8/msgqueue.cc
vendored
@ -1,12 +1,7 @@
|
||||
#include <f8/internal/pch.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
|
||||
|
||||
#include <f8/types.h>
|
||||
|
||||
#include <f8/timer.h>
|
||||
|
||||
#include <f8/msgqueue.h>
|
||||
|
||||
@ -21,10 +16,10 @@ namespace f8
|
||||
struct IMMsgNode
|
||||
{
|
||||
int msgid;
|
||||
const a8m::Args args;
|
||||
const a8::Args args;
|
||||
IMMsgNode* next = nullptr;
|
||||
|
||||
IMMsgNode(const a8m::Args& args1):args(std::move(args1))
|
||||
IMMsgNode(const a8::Args& args1):args(std::move(args1))
|
||||
{
|
||||
}
|
||||
|
||||
@ -83,7 +78,7 @@ namespace f8
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessMsg(int msgid, const a8m::Args& args)
|
||||
void ProcessMsg(int msgid, const a8::Args& args)
|
||||
{
|
||||
auto itr = msg_handlers.find(msgid);
|
||||
if (itr != msg_handlers.end()) {
|
||||
@ -113,7 +108,7 @@ namespace f8
|
||||
return &node->entry;
|
||||
}
|
||||
|
||||
void PostMsg(int msgid, const a8m::Args args)
|
||||
void PostMsg(int msgid, const a8::Args args)
|
||||
{
|
||||
IMMsgNode *p = new IMMsgNode(args);
|
||||
p->msgid = msgid;
|
||||
@ -183,7 +178,7 @@ namespace f8
|
||||
return imp_->RegisterCallBack(msgid, handle_func);
|
||||
}
|
||||
|
||||
void MsgQueue::PostMsg(int msgid, const a8m::Args args)
|
||||
void MsgQueue::PostMsg(int msgid, const a8::Args args)
|
||||
{
|
||||
imp_->PostMsg(msgid, std::move(args));
|
||||
}
|
||||
|
10
third_party/f8/f8/msgqueue.h
vendored
10
third_party/f8/f8/msgqueue.h
vendored
@ -1,14 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <a8/singleton.h>
|
||||
|
||||
import a8m.args;
|
||||
|
||||
namespace f8
|
||||
{
|
||||
typedef std::function<void (const a8m::Args&)> MsgHandleFunc;
|
||||
typedef std::function<void (const a8::Args&)> MsgHandleFunc;
|
||||
typedef list_head* CallBackHandle;
|
||||
|
||||
class MsgQueue : public a8::Singleton<MsgQueue>
|
||||
@ -26,7 +20,7 @@ namespace f8
|
||||
CallBackHandle RegisterCallBack(int msgid, MsgHandleFunc cb);
|
||||
void RemoveCallBack(CallBackHandle handle);
|
||||
|
||||
void PostMsg(int msgid, const a8m::Args args);
|
||||
void PostMsg(int msgid, const a8::Args args);
|
||||
|
||||
private:
|
||||
std::shared_ptr<class MsgQueueImp> imp_;
|
||||
|
2
third_party/f8/f8/netmsghandler.cc
vendored
2
third_party/f8/f8/netmsghandler.cc
vendored
@ -1,7 +1,7 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
|
||||
#include <f8/types.h>
|
||||
#include <f8/udplog.h>
|
||||
#include <f8/utils.h>
|
||||
#include <f8/protoutils.h>
|
||||
|
2
third_party/f8/f8/netmsghandler.h
vendored
2
third_party/f8/f8/netmsghandler.h
vendored
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/singleton.h>
|
||||
|
||||
#include <f8/protoutils.h>
|
||||
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
|
4
third_party/f8/f8/protoutils.cc
vendored
4
third_party/f8/f8/protoutils.cc
vendored
@ -1,6 +1,6 @@
|
||||
#include <f8/types.h>
|
||||
#include <f8/internal/pch.h>
|
||||
|
||||
#include "f8/protoutils.h"
|
||||
#include <f8/protoutils.h>
|
||||
|
||||
#include <a8/tcpclient.h>
|
||||
#include <a8/tcplistener.h>
|
||||
|
9
third_party/f8/f8/protoutils.h
vendored
9
third_party/f8/f8/protoutils.h
vendored
@ -7,15 +7,6 @@ namespace a8
|
||||
class AsioTcpClient;
|
||||
}
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
class Message;
|
||||
}
|
||||
}
|
||||
|
||||
#include <string>
|
||||
#include <a8/list.h>
|
||||
|
||||
class Player;
|
||||
namespace f8
|
||||
{
|
||||
|
1
third_party/f8/f8/scriptengine.cc
vendored
1
third_party/f8/f8/scriptengine.cc
vendored
@ -1,3 +1,4 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <a8/pyengine.h>
|
||||
|
||||
#include <f8/udplog.h>
|
||||
|
1
third_party/f8/f8/tglog.cc
vendored
1
third_party/f8/f8/tglog.cc
vendored
@ -1,3 +1,4 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
2
third_party/f8/f8/tglog.h
vendored
2
third_party/f8/f8/tglog.h
vendored
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/singleton.h>
|
||||
|
||||
namespace f8
|
||||
{
|
||||
struct TGLogImpl;
|
||||
|
61
third_party/f8/f8/timer.cc
vendored
61
third_party/f8/f8/timer.cc
vendored
@ -1,24 +1,35 @@
|
||||
#include <a8/sysutils.h>
|
||||
#include <f8/internal/pch.h>
|
||||
|
||||
#include <f8/types.h>
|
||||
#include <a8/xtimer.h>
|
||||
#include <f8/timer.h>
|
||||
|
||||
|
||||
namespace f8
|
||||
{
|
||||
class TimerImpl
|
||||
{
|
||||
public:
|
||||
bool initialized_ = false;
|
||||
a8::XTimer xtimer_;
|
||||
};
|
||||
|
||||
Attacher::Attacher()
|
||||
{
|
||||
p_.SetOwner(&f8::Timer::Instance()->xtimer_);
|
||||
real_obj_.SetOwner(&f8::Timer::Instance()->impl_->xtimer_);
|
||||
if (!f8::Timer::Instance()->Initialized()) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void Attacher::ClearTimerList()
|
||||
{
|
||||
real_obj_.ClearTimerList();
|
||||
}
|
||||
|
||||
void Timer::Init()
|
||||
{
|
||||
initialized_ = true;
|
||||
xtimer_.Init
|
||||
impl_ = std::make_shared<TimerImpl>();
|
||||
impl_->initialized_ = true;
|
||||
impl_->xtimer_.Init
|
||||
(
|
||||
[] (void* context)
|
||||
{
|
||||
@ -32,92 +43,92 @@ namespace f8
|
||||
|
||||
void Timer::UnInit()
|
||||
{
|
||||
initialized_ = false;
|
||||
impl_->initialized_ = false;
|
||||
}
|
||||
|
||||
bool Timer::Initialized()
|
||||
{
|
||||
return initialized_;
|
||||
return impl_->initialized_;
|
||||
}
|
||||
|
||||
void Timer::Update()
|
||||
{
|
||||
xtimer_.Update();
|
||||
impl_->xtimer_.Update();
|
||||
}
|
||||
|
||||
void Timer::SetTimeout(int expire_time, a8::TimerCb cb)
|
||||
{
|
||||
xtimer_.SetTimeout(expire_time, cb);
|
||||
impl_->xtimer_.SetTimeout(expire_time, cb);
|
||||
}
|
||||
|
||||
void Timer::SetTimeoutEx(int expire_time, a8::TimerCb cb, Attacher* attacher)
|
||||
{
|
||||
xtimer_.SetTimeoutEx(expire_time, cb, &attacher->p_);
|
||||
impl_->xtimer_.SetTimeoutEx(expire_time, cb, &attacher->real_obj_);
|
||||
}
|
||||
|
||||
TimerWp Timer::SetTimeoutWp(int expire_time, a8::TimerCb cb)
|
||||
{
|
||||
return TimerWp(xtimer_.SetTimeoutWp(expire_time, cb));
|
||||
return TimerWp(impl_->xtimer_.SetTimeoutWp(expire_time, cb));
|
||||
}
|
||||
|
||||
TimerWp Timer::SetTimeoutWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher)
|
||||
{
|
||||
return TimerWp(xtimer_.SetTimeoutWpEx(expire_time, cb, &attacher->p_));
|
||||
return TimerWp(impl_->xtimer_.SetTimeoutWpEx(expire_time, cb, &attacher->real_obj_));
|
||||
}
|
||||
|
||||
void Timer::SetInterval(int expire_time, a8::TimerCb cb)
|
||||
{
|
||||
xtimer_.SetInterval(expire_time, cb);
|
||||
impl_->xtimer_.SetInterval(expire_time, cb);
|
||||
}
|
||||
|
||||
void Timer::SetIntervalEx(int expire_time, a8::TimerCb cb, Attacher* attacher)
|
||||
{
|
||||
xtimer_.SetIntervalEx(expire_time, cb, &attacher->p_);
|
||||
impl_->xtimer_.SetIntervalEx(expire_time, cb, &attacher->real_obj_);
|
||||
}
|
||||
|
||||
TimerWp Timer::SetIntervalWp(int expire_time, a8::TimerCb cb)
|
||||
{
|
||||
return TimerWp(xtimer_.SetIntervalWp(expire_time, cb));
|
||||
return TimerWp(impl_->xtimer_.SetIntervalWp(expire_time, cb));
|
||||
}
|
||||
|
||||
TimerWp Timer::SetIntervalWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher)
|
||||
{
|
||||
return TimerWp(xtimer_.SetIntervalWpEx(expire_time, cb, &attacher->p_));
|
||||
return TimerWp(impl_->xtimer_.SetIntervalWpEx(expire_time, cb, &attacher->real_obj_));
|
||||
}
|
||||
|
||||
void Timer::FireEvent(TimerWp& timer_wp, int event, a8m::Args* args)
|
||||
void Timer::FireEvent(TimerWp& timer_wp, int event, a8::Args* args)
|
||||
{
|
||||
xtimer_.FireEvent(timer_wp.p_, event, args);
|
||||
impl_->xtimer_.FireEvent(timer_wp.real_obj_, event, args);
|
||||
}
|
||||
|
||||
void Timer::ModifyTime(TimerWp& timer_wp, int expire_time)
|
||||
{
|
||||
xtimer_.ModifyTime(timer_wp.p_, expire_time);
|
||||
impl_->xtimer_.ModifyTime(timer_wp.real_obj_, expire_time);
|
||||
}
|
||||
|
||||
void Timer::Delete(TimerWp& timer_wp)
|
||||
{
|
||||
xtimer_.Delete(timer_wp.p_);
|
||||
impl_->xtimer_.Delete(timer_wp.real_obj_);
|
||||
}
|
||||
|
||||
long long Timer::GetRemainTime(TimerWp& timer_wp)
|
||||
{
|
||||
return xtimer_.GetRemainTime(timer_wp.p_);
|
||||
return impl_->xtimer_.GetRemainTime(timer_wp.real_obj_);
|
||||
}
|
||||
|
||||
void Timer::DeleteCurrentTimer()
|
||||
{
|
||||
xtimer_.DeleteCurrentTimer();
|
||||
impl_->xtimer_.DeleteCurrentTimer();
|
||||
}
|
||||
|
||||
bool Timer::IsRunning()
|
||||
{
|
||||
return xtimer_.IsRunning();
|
||||
return impl_->xtimer_.IsRunning();
|
||||
}
|
||||
|
||||
long long Timer::GetIdleTime()
|
||||
{
|
||||
return xtimer_.GetIdleTime();
|
||||
return impl_->xtimer_.GetIdleTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
20
third_party/f8/f8/timer.h
vendored
20
third_party/f8/f8/timer.h
vendored
@ -1,21 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/xtimer.h>
|
||||
#include <a8/timer_attacher.h>
|
||||
#include <a8/singleton.h>
|
||||
|
||||
namespace f8
|
||||
{
|
||||
class TimerWp
|
||||
{
|
||||
public:
|
||||
TimerWp(a8::XTimerWp wp): p_(wp) {};
|
||||
TimerWp(a8::XTimerWp wp): real_obj_(wp) {};
|
||||
TimerWp() {};
|
||||
bool expired() { return p_.expired();};
|
||||
auto lock() { return p_.lock(); };
|
||||
bool expired() { return real_obj_.expired();};
|
||||
|
||||
private:
|
||||
a8::XTimerWp p_;
|
||||
a8::XTimerWp real_obj_;
|
||||
friend class Timer;
|
||||
};
|
||||
|
||||
@ -23,10 +18,10 @@ namespace f8
|
||||
{
|
||||
public:
|
||||
Attacher();
|
||||
void ClearTimerList() { p_.ClearTimerList(); };
|
||||
void ClearTimerList();
|
||||
|
||||
private:
|
||||
a8::Attacher p_;
|
||||
a8::Attacher real_obj_;
|
||||
friend class Timer;
|
||||
};
|
||||
|
||||
@ -53,7 +48,7 @@ namespace f8
|
||||
TimerWp SetIntervalWp(int expire_time, a8::TimerCb cb);
|
||||
TimerWp SetIntervalWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher);
|
||||
|
||||
void FireEvent(TimerWp& timer_wp, int event, a8m::Args* args);
|
||||
void FireEvent(TimerWp& timer_wp, int event, a8::Args* args);
|
||||
void ModifyTime(TimerWp& timer_wp, int expire_time);
|
||||
void Delete(TimerWp& timer_wp);
|
||||
long long GetRemainTime(TimerWp& timer_wp);
|
||||
@ -62,8 +57,7 @@ namespace f8
|
||||
long long GetIdleTime();
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
a8::XTimer xtimer_;
|
||||
std::shared_ptr<class TimerImpl> impl_;
|
||||
|
||||
friend class Attacher;
|
||||
};
|
||||
|
2
third_party/f8/f8/types.cc
vendored
2
third_party/f8/f8/types.cc
vendored
@ -1,6 +1,6 @@
|
||||
#include <f8/internal/pch.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <f8/types.h>
|
||||
#include <a8/mutable_xobject.h>
|
||||
|
||||
namespace f8
|
||||
|
6
third_party/f8/f8/types.h
vendored
6
third_party/f8/f8/types.h
vendored
@ -1,5 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
class Message;
|
||||
}
|
||||
}
|
||||
|
||||
namespace f8
|
||||
{
|
||||
|
||||
|
6
third_party/f8/f8/udplog.cc
vendored
6
third_party/f8/f8/udplog.cc
vendored
@ -1,11 +1,9 @@
|
||||
#include <f8/internal/pch.h>
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include <a8/strutils.h>
|
||||
#include <a8/sysutils.h>
|
||||
|
||||
#include <f8/types.h>
|
||||
#include <f8/udplog.h>
|
||||
|
||||
namespace f8
|
||||
|
6
third_party/f8/f8/udplog.h
vendored
6
third_party/f8/f8/udplog.h
vendored
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
#include <a8/xvalue.h>
|
||||
|
||||
#include <a8/singleton.h>
|
||||
|
||||
namespace f8
|
||||
{
|
||||
|
||||
|
2
third_party/f8/f8/utils.cc
vendored
2
third_party/f8/f8/utils.cc
vendored
@ -1,3 +1,5 @@
|
||||
#include <f8/internal/pch.h>
|
||||
|
||||
#include <a8/stringlist.h>
|
||||
#include <a8/mysql.h>
|
||||
#include <a8/openssl.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user