This commit is contained in:
aozhiwei 2024-05-01 20:45:57 +08:00
parent 2f1dca6913
commit bef63f6cb5
11 changed files with 43 additions and 30 deletions

View File

@ -1,10 +1,11 @@
#pragma once module;
#include <vector> #include <vector>
#include <any> #include <any>
namespace a8 export module a8m.args;
{
export namespace a8m {
class Args class Args
{ {
public: public:
@ -12,7 +13,7 @@ namespace a8
Args(std::vector<std::any> args):args_(std::move(args)) {}; Args(std::vector<std::any> args):args_(std::move(args)) {};
template <typename T> template <typename T>
T Get(size_t index) const { return std::any_cast<T>(args_.at(index));}; T Get(size_t index) const { /*return std::any_cast<T>(args_.at(index));*/ return T(); };
private: private:
std::vector<std::any> args_; std::vector<std::any> args_;

View File

@ -3,7 +3,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <a8/args.h> import a8m.args;
namespace google namespace google
{ {
@ -26,8 +26,8 @@ namespace a8
SendQueueNode* next; SendQueueNode* next;
}; };
typedef std::function<void(const a8::Args&)> CommonCbProc; typedef std::function<void(const a8m::Args&)> CommonCbProc;
typedef std::function<void(const a8::Args*)> CommonCbProcEx; typedef std::function<void(const a8m::Args*)> CommonCbProcEx;
typedef std::weak_ptr<struct XTimerPtr> XTimerWp; typedef std::weak_ptr<struct XTimerPtr> XTimerWp;
namespace reflect namespace reflect

View File

@ -143,7 +143,7 @@ namespace a8
base_->timer_tick = get_tick_count_func_(context_); base_->timer_tick = get_tick_count_func_(context_);
InternalSetInterval InternalSetInterval
(gc_time_, (gc_time_,
[this] (int event, const a8::Args* args) [this] (int event, const a8m::Args* args)
{ {
if (a8m::TIMER_EXEC_EVENT() == event) { if (a8m::TIMER_EXEC_EVENT() == event) {
int i = 0; int i = 0;
@ -210,7 +210,7 @@ namespace a8
} }
} }
void InternalFireEvent(xtimer_list* timer, int event, a8::Args* args) void InternalFireEvent(xtimer_list* timer, int event, a8m::Args* args)
{ {
if (timer->cb) { if (timer->cb) {
timer->cb(event, args); timer->cb(event, args);
@ -556,7 +556,7 @@ namespace a8
return result; return result;
} }
void XTimer::FireEvent(XTimerWp& timer_wp, int event, a8::Args* args) void XTimer::FireEvent(XTimerWp& timer_wp, int event, a8m::Args* args)
{ {
if (timer_wp.expired()) { if (timer_wp.expired()) {
abort(); abort();

View File

@ -2,12 +2,13 @@
#include <functional> #include <functional>
#include <a8/args.h>
#include <a8/types.h> #include <a8/types.h>
import a8m.args;
namespace a8 namespace a8
{ {
typedef std::function<void(int, const a8::Args*)> TimerCb; typedef std::function<void(int, const a8m::Args*)> TimerCb;
typedef long long (*XGetTickCountFunc)(void*); typedef long long (*XGetTickCountFunc)(void*);
class Attacher; class Attacher;
@ -30,7 +31,7 @@ namespace a8
XTimerWp SetIntervalWp(int expire_time, TimerCb cb); XTimerWp SetIntervalWp(int expire_time, TimerCb cb);
XTimerWp SetIntervalWpEx(int expire_time, TimerCb cb, Attacher* attacher); XTimerWp SetIntervalWpEx(int expire_time, TimerCb cb, Attacher* attacher);
void FireEvent(XTimerWp& timer_wp, int event, a8::Args* args); void FireEvent(XTimerWp& timer_wp, int event, a8m::Args* args);
void ModifyTime(XTimerWp& timer_wp, int expire_time); void ModifyTime(XTimerWp& timer_wp, int expire_time);
void ResetTimer(XTimerWp& timer_wp); void ResetTimer(XTimerWp& timer_wp);
void Delete(XTimerWp& timer_wp); void Delete(XTimerWp& timer_wp);

View File

@ -21,11 +21,14 @@
#include <f8/httpclientpool.h> #include <f8/httpclientpool.h>
#include <f8/msgqueue.h> #include <f8/msgqueue.h>
#include <f8/utils.h> #include <f8/utils.h>
#include <any>
#include <f8/timer.h> #include <f8/timer.h>
static const int AHE_NO_ERROR = 0; static const int AHE_NO_ERROR = 0;
static const int AHE_NO_CONN = 1; static const int AHE_NO_CONN = 1;
import a8m.args;
namespace f8 namespace f8
{ {
@ -217,7 +220,7 @@ namespace f8
if (xobj->ReadFromJsonString(response)) { if (xobj->ReadFromJsonString(response)) {
f8::MsgQueue::Instance()->PostMsg f8::MsgQueue::Instance()->PostMsg
(IM_HttpClientPool, (IM_HttpClientPool,
a8::Args a8m::Args
( (
{ {
node->context_id, node->context_id,
@ -228,7 +231,7 @@ namespace f8
} else { } else {
f8::MsgQueue::Instance()->PostMsg f8::MsgQueue::Instance()->PostMsg
(IM_HttpClientPool, (IM_HttpClientPool,
a8::Args a8m::Args
( (
{ {
node->context_id, node->context_id,
@ -241,7 +244,7 @@ namespace f8
} else { } else {
f8::MsgQueue::Instance()->PostMsg f8::MsgQueue::Instance()->PostMsg
(IM_HttpClientPool, (IM_HttpClientPool,
a8::Args a8m::Args
( (
{ {
node->context_id, node->context_id,
@ -403,7 +406,7 @@ namespace f8
} }
f8::Timer::Instance()->SetTimeoutEx f8::Timer::Instance()->SetTimeoutEx
(1000 * 10, (1000 * 10,
[p] (int event, const a8::Args* args) [p] (int event, const a8m::Args* args)
{ {
}, },
@ -446,9 +449,14 @@ namespace f8
impl_->Init(); impl_->Init();
MsgQueue::Instance()->RegisterCallBack MsgQueue::Instance()->RegisterCallBack
(IM_HttpClientPool, (IM_HttpClientPool,
[] (const a8::Args& args) [] (const a8m::Args& args)
{ {
--(HttpClientPool::Instance()->impl_->pending_num); --(HttpClientPool::Instance()->impl_->pending_num);
#if 1
std::vector<std::any> args_;
auto a = std::any_cast<long long>(args_.at(0));
#endif
#if 0
long long context_id = args.Get<long long>(0); long long context_id = args.Get<long long>(0);
int code = args.Get<int>(1); int code = args.Get<int>(1);
auto xobj = args.Get<std::shared_ptr<a8::XObject>>(2); auto xobj = args.Get<std::shared_ptr<a8::XObject>>(2);
@ -461,6 +469,7 @@ namespace f8
response response
); );
} }
#endif
} }
); );
impl_->SetThreadNum(thread_num); impl_->SetThreadNum(thread_num);

View File

@ -37,7 +37,7 @@ namespace f8
if (cb_) { if (cb_) {
std::string response; std::string response;
resp_xobj_->ToJsonStr(response); resp_xobj_->ToJsonStr(response);
cb_(a8::Args({a8::HttpResponse(response)})); cb_(a8m::Args({a8::HttpResponse(response)}));
} }
resped_ = true; resped_ = true;
} }

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include <a8/types.h> #include <a8/types.h>
#include <a8/args.h>
import a8m.args;
namespace a8 namespace a8
{ {

View File

@ -21,10 +21,10 @@ namespace f8
struct IMMsgNode struct IMMsgNode
{ {
int msgid; int msgid;
const a8::Args args; const a8m::Args args;
IMMsgNode* next = nullptr; IMMsgNode* next = nullptr;
IMMsgNode(const a8::Args& args1):args(std::move(args1)) IMMsgNode(const a8m::Args& args1):args(std::move(args1))
{ {
} }
@ -83,7 +83,7 @@ namespace f8
} }
} }
void ProcessMsg(int msgid, const a8::Args& args) void ProcessMsg(int msgid, const a8m::Args& args)
{ {
auto itr = msg_handlers.find(msgid); auto itr = msg_handlers.find(msgid);
if (itr != msg_handlers.end()) { if (itr != msg_handlers.end()) {
@ -113,7 +113,7 @@ namespace f8
return &node->entry; return &node->entry;
} }
void PostMsg(int msgid, const a8::Args args) void PostMsg(int msgid, const a8m::Args args)
{ {
IMMsgNode *p = new IMMsgNode(args); IMMsgNode *p = new IMMsgNode(args);
p->msgid = msgid; p->msgid = msgid;
@ -183,7 +183,7 @@ namespace f8
return imp_->RegisterCallBack(msgid, handle_func); return imp_->RegisterCallBack(msgid, handle_func);
} }
void MsgQueue::PostMsg(int msgid, const a8::Args args) void MsgQueue::PostMsg(int msgid, const a8m::Args args)
{ {
imp_->PostMsg(msgid, std::move(args)); imp_->PostMsg(msgid, std::move(args));
} }

View File

@ -3,11 +3,12 @@
#include <functional> #include <functional>
#include <a8/singleton.h> #include <a8/singleton.h>
#include <a8/args.h>
import a8m.args;
namespace f8 namespace f8
{ {
typedef std::function<void (const a8::Args&)> MsgHandleFunc; typedef std::function<void (const a8m::Args&)> MsgHandleFunc;
typedef list_head* CallBackHandle; typedef list_head* CallBackHandle;
class MsgQueue : public a8::Singleton<MsgQueue> class MsgQueue : public a8::Singleton<MsgQueue>
@ -25,7 +26,7 @@ namespace f8
CallBackHandle RegisterCallBack(int msgid, MsgHandleFunc cb); CallBackHandle RegisterCallBack(int msgid, MsgHandleFunc cb);
void RemoveCallBack(CallBackHandle handle); void RemoveCallBack(CallBackHandle handle);
void PostMsg(int msgid, const a8::Args args); void PostMsg(int msgid, const a8m::Args args);
private: private:
std::shared_ptr<class MsgQueueImp> imp_; std::shared_ptr<class MsgQueueImp> imp_;

View File

@ -85,7 +85,7 @@ namespace f8
return TimerWp(xtimer_.SetIntervalWpEx(expire_time, cb, &attacher->p_)); return TimerWp(xtimer_.SetIntervalWpEx(expire_time, cb, &attacher->p_));
} }
void Timer::FireEvent(TimerWp& timer_wp, int event, a8::Args* args) void Timer::FireEvent(TimerWp& timer_wp, int event, a8m::Args* args)
{ {
xtimer_.FireEvent(timer_wp.p_, event, args); xtimer_.FireEvent(timer_wp.p_, event, args);
} }

View File

@ -53,7 +53,7 @@ namespace f8
TimerWp SetIntervalWp(int expire_time, a8::TimerCb cb); TimerWp SetIntervalWp(int expire_time, a8::TimerCb cb);
TimerWp SetIntervalWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher); TimerWp SetIntervalWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher);
void FireEvent(TimerWp& timer_wp, int event, a8::Args* args); void FireEvent(TimerWp& timer_wp, int event, a8m::Args* args);
void ModifyTime(TimerWp& timer_wp, int expire_time); void ModifyTime(TimerWp& timer_wp, int expire_time);
void Delete(TimerWp& timer_wp); void Delete(TimerWp& timer_wp);
long long GetRemainTime(TimerWp& timer_wp); long long GetRemainTime(TimerWp& timer_wp);