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 <any>
namespace a8
{
export module a8m.args;
export namespace a8m {
class Args
{
public:
@ -12,7 +13,7 @@ namespace a8
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));};
T Get(size_t index) const { /*return std::any_cast<T>(args_.at(index));*/ return T(); };
private:
std::vector<std::any> args_;

View File

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

View File

@ -143,7 +143,7 @@ namespace a8
base_->timer_tick = get_tick_count_func_(context_);
InternalSetInterval
(gc_time_,
[this] (int event, const a8::Args* args)
[this] (int event, const a8m::Args* args)
{
if (a8m::TIMER_EXEC_EVENT() == event) {
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) {
timer->cb(event, args);
@ -556,7 +556,7 @@ namespace a8
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()) {
abort();

View File

@ -2,12 +2,13 @@
#include <functional>
#include <a8/args.h>
#include <a8/types.h>
import a8m.args;
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*);
class Attacher;
@ -30,7 +31,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, a8::Args* args);
void FireEvent(XTimerWp& timer_wp, int event, a8m::Args* args);
void ModifyTime(XTimerWp& timer_wp, int expire_time);
void ResetTimer(XTimerWp& timer_wp);
void Delete(XTimerWp& timer_wp);

View File

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

View File

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

View File

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

View File

@ -21,10 +21,10 @@ namespace f8
struct IMMsgNode
{
int msgid;
const a8::Args args;
const a8m::Args args;
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);
if (itr != msg_handlers.end()) {
@ -113,7 +113,7 @@ namespace f8
return &node->entry;
}
void PostMsg(int msgid, const a8::Args args)
void PostMsg(int msgid, const a8m::Args args)
{
IMMsgNode *p = new IMMsgNode(args);
p->msgid = msgid;
@ -183,7 +183,7 @@ namespace f8
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));
}

View File

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

View File

@ -85,7 +85,7 @@ namespace f8
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);
}

View File

@ -53,7 +53,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, a8::Args* args);
void FireEvent(TimerWp& timer_wp, int event, a8m::Args* args);
void ModifyTime(TimerWp& timer_wp, int expire_time);
void Delete(TimerWp& timer_wp);
long long GetRemainTime(TimerWp& timer_wp);