Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mars2] mars multi-instance. #1128

Open
wants to merge 1 commit into
base: rb/2023-05
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mars/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include_directories(..)
include_directories(../..)
include_directories(../comm)
include_directories(../../..)
include_directories(../boot)

file(GLOB SELF_TEMP_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR} *.cc *.h)
list(APPEND SELF_SRC_FILES ${SELF_TEMP_SRC_FILES})
Expand Down
24 changes: 23 additions & 1 deletion mars/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ struct DeviceInfo {
std::string devicename;
std::string devicetype;
};


/* mars2
extern mars::comm::ProxyInfo GetProxyInfo(const std::string& _host);
extern std::string GetAppFilePath();
extern AccountInfo GetAccountInfo();
Expand All @@ -49,7 +50,27 @@ extern std::string GetRecentUserName();
extern unsigned int GetClientVersion();
extern DeviceInfo GetDeviceInfo();
extern double GetOsVersion();
*/

//mars2
class Callback {
public:
virtual ~Callback(){};

virtual bool GetProxyInfo(const std::string& _host, mars::comm::ProxyInfo& _proxy_info) {
return false;
}

virtual std::string GetAppFilePath() = 0;

virtual AccountInfo GetAccountInfo() = 0;

virtual unsigned int GetClientVersion() = 0;

virtual DeviceInfo GetDeviceInfo() = 0;
};

/* mars2
#ifdef NATIVE_CALLBACK

class AppLogicNativeCallback {
Expand All @@ -68,6 +89,7 @@ extern double GetOsVersion();
extern void SetAppLogicNativeCallback(std::shared_ptr<AppLogicNativeCallback> _cb);

#endif //NATIVE_CALLBACK
*/

}}

Expand Down
91 changes: 86 additions & 5 deletions mars/app/app_logic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,43 @@
#include "mars/comm/dns/dns.h"
#include "mars/baseevent/baseprjevent.h"
#include "mars/comm/macro.h"
#include "mars/boot/context.h"
#include "app_manager.h"

using namespace mars::boot;
using namespace mars::comm;

namespace mars {
namespace app {

static Callback* sg_callback = NULL;
//mars2
//static Callback* sg_callback = NULL;

void SetCallback(Callback* const callback) {
/* mars2
sg_callback = callback;
*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
app_manager->SetCallback(callback);
}
}

#if !defined(ANDROID) || defined (CPP_CALL_BACK)


/* mars2
NO_DESTROY static mars::comm::ProxyInfo sg_proxyInfo;
static bool sg_gotProxy = false;
NO_DESTROY static Mutex sg_slproxymutex;
NO_DESTROY static Thread sg_slproxyThread;
static uint64_t sg_slporxytimetick = gettickcount();
static int sg_slproxycount = 0;

*/


static void __GetProxyInfo(const std::string& _host, uint64_t _timetick) {
/* mars2
xinfo_function(TSF"timetick:%_, host:%_", _timetick, _host);

mars::comm::ProxyInfo proxy_info;
Expand Down Expand Up @@ -108,16 +122,28 @@ NO_DESTROY static Thread sg_slproxyThread;
lock.lock();
sg_proxyInfo.ip = ips.front();
sg_gotProxy = true;

*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

冗余代码太多了,考虑抽成一个函数,用的时候:
if (auto app_manager = GetDefaultAppManager()) {
app_manager->xxx();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者直接 GetDefaultAppManager()->xxx() 也行

xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
app_manager->GetProxyInfo(_host, _timetick);
}
}

#if TARGET_OS_IPHONE
static void __ClearProxyInfo() {
/*mars2
ScopedLock lock(sg_slproxymutex);
sg_slporxytimetick = gettickcount();
sg_slproxycount = 0;
sg_gotProxy = false;
sg_proxyInfo.type = mars::comm::kProxyNone;
*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
app_manager->ClearProxyInfo();
}
}

static void __InitbindBaseprjevent() {
Expand All @@ -127,6 +153,7 @@ NO_DESTROY static Thread sg_slproxyThread;
#endif

mars::comm::ProxyInfo GetProxyInfo(const std::string& _host) {
/* mars2
xassert2(sg_callback != NULL);

#if !TARGET_OS_IPHONE
Expand All @@ -151,10 +178,17 @@ NO_DESTROY static Thread sg_slproxyThread;
}

return mars::comm::ProxyInfo();

*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
return app_manager->GetProxyInfo(_host);
}
return mars::comm::ProxyInfo();
}

std::string GetAppFilePath() {
/* mars2
xassert2(sg_callback != NULL);

std::string path = sg_callback->GetAppFilePath();
Expand All @@ -163,31 +197,71 @@ NO_DESTROY static Thread sg_slproxyThread;
#endif

return path;
*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
return app_manager->GetAppFilePath();
}
return "";
}

AccountInfo GetAccountInfo() {
/* mars2
xassert2(sg_callback != NULL);
return sg_callback->GetAccountInfo();
*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
return app_manager->GetAccountInfo();
}
return AccountInfo();
}

std::string GetUserName() {
/*mars2
xassert2(sg_callback != NULL);
AccountInfo info = sg_callback->GetAccountInfo();
return info.username;
*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
return app_manager->GetUserName();
}
return "";
}

std::string GetRecentUserName() {
/* mars2
xassert2(sg_callback != NULL);
return GetUserName();
*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
return app_manager->GetRecentUserName();
}
return "";
}

unsigned int GetClientVersion() {
/* mars2
xassert2(sg_callback != NULL);
return sg_callback->GetClientVersion();
*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
return app_manager->GetClientVersion();
}
return 0;
}


DeviceInfo GetDeviceInfo() {
/*mars2
xassert2(sg_callback != NULL);

static DeviceInfo device_info;
Expand All @@ -197,6 +271,13 @@ NO_DESTROY static Thread sg_slproxyThread;

device_info = sg_callback->GetDeviceInfo();
return device_info;
*/
AppManager* app_manager = Context::CreateContext("default")->GetManager<AppManager>();
xassert2(NULL != app_manager, "mars2 app_manager is empty.");
if (app_manager) {
return app_manager->GetDeviceInfo();
}
return DeviceInfo();
}

#endif
Expand Down
18 changes: 18 additions & 0 deletions mars/app/app_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AutoBuffer;
namespace mars {
namespace app {

/* mars2
class Callback {
public:
virtual ~Callback() {};
Expand All @@ -44,8 +45,25 @@ namespace app {

virtual DeviceInfo GetDeviceInfo() = 0;
};
*/

void SetCallback(Callback* const callback);

//start app.h
mars::comm::ProxyInfo GetProxyInfo(const std::string& _host);
std::string GetAppFilePath();
AccountInfo GetAccountInfo();
std::string GetUserName();
std::string GetRecentUserName();
unsigned int GetClientVersion();
DeviceInfo GetDeviceInfo();
double GetOsVersion();

#ifdef NATIVE_CALLBACK
void SetAppLogicNativeCallback(std::shared_ptr<AppLogicNativeCallback> _cb);
#endif
//end app.h

}}


Expand Down
Loading