Top Related Projects
Quick Overview
Mars is a cross-platform network component developed by WeChat. It provides a reliable and efficient network layer for mobile applications, focusing on performance, stability, and battery efficiency. Mars is designed to handle various network conditions and optimize data transfer for mobile devices.
Pros
- Cross-platform support (iOS, Android, Windows, macOS)
- Optimized for mobile networks, handling poor connectivity scenarios
- Developed and battle-tested by WeChat, a large-scale messaging app
- Open-source with active community support
Cons
- Complex setup and integration process
- Steep learning curve for developers unfamiliar with network programming
- Limited documentation in English
- May be overkill for smaller projects or apps with simple networking needs
Code Examples
- Initializing Mars:
#include "mars/comm/xlogger/xlogger.h"
#include "mars/app/app_logic.h"
void MarsInit() {
mars::app::SetCallback(mars_callback);
mars::app::Init();
}
- Sending a message:
#include "mars/stn/stn.h"
void SendMessage(const std::string& message) {
mars::stn::Task task;
task.cmdid = 1;
task.channel_select = mars::stn::Task::kChannelShort;
task.cgi = "/sendmessage";
task.shortlink_host_list.push_back("api.example.com");
task.req_body = message;
mars::stn::StartTask(task);
}
- Handling network status changes:
#include "mars/comm/network/netinfo_util.h"
void OnNetworkChange(mars::comm::NetInfo& netInfo) {
if (netInfo.nettype == mars::comm::kWifi) {
// Handle WiFi connection
} else if (netInfo.nettype == mars::comm::kMobile) {
// Handle mobile data connection
}
}
Getting Started
-
Clone the Mars repository:
git clone https://github.com/Tencent/mars.git
-
Build Mars for your target platform (iOS, Android, etc.) following the instructions in the project's README.
-
Include Mars in your project and initialize it:
#include "mars/app/app_logic.h" int main() { mars::app::SetCallback(your_callback_function); mars::app::Init(); // Your app logic here return 0; }
-
Implement necessary callbacks and start using Mars features in your application.
Competitor Comparisons
RT-Thread is an open source IoT Real-Time Operating System (RTOS).
Pros of rt-thread
- More comprehensive real-time operating system (RTOS) with a wider range of features and components
- Larger and more active community, with frequent updates and contributions
- Better documentation and examples for embedded systems development
Cons of rt-thread
- Steeper learning curve due to its more complex architecture
- Potentially higher resource consumption compared to mars for simpler applications
Code Comparison
rt-thread example (kernel initialization):
int main(void)
{
rt_hw_interrupt_disable();
rtthread_startup();
return 0;
}
mars example (network connection):
mars::stn::SetCallback(mars::stn::StnCallBack::Instance());
mars::app::SetCallback(mars::app::AppCallBack::Instance());
mars::baseevent::OnCreate();
Both projects serve different purposes: rt-thread is a full-fledged RTOS, while mars focuses on network communication for mobile applications. rt-thread is more suitable for embedded systems and IoT devices, offering a complete operating system environment. mars, on the other hand, is optimized for cross-platform mobile development with a focus on network communication.
rt-thread provides a broader set of features for embedded development, including device drivers, file systems, and networking stacks. mars excels in providing a reliable and efficient network communication layer for mobile apps, with features like connection recovery and traffic control.
code and manual
Pros of LiteOS
- Designed specifically for IoT devices, offering a lightweight and efficient solution
- Supports a wider range of hardware platforms, including ARM Cortex-M and RISC-V
- Provides a comprehensive set of IoT-focused features, including connectivity and security modules
Cons of LiteOS
- Less focus on cross-platform mobile development compared to mars
- Smaller community and ecosystem compared to mars, which may result in fewer resources and third-party integrations
Code Comparison
LiteOS example (RTOS task creation):
UINT32 Example_Task(VOID)
{
UINT32 uwRet = LOS_OK;
TSK_INIT_PARAM_S stTask = {0};
stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleTask;
stTask.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
stTask.pcName = "ExampleTask";
stTask.usTaskPrio = 4;
uwRet = LOS_TaskCreate(&g_ExampleTaskId, &stTask);
return uwRet;
}
mars example (Network request):
mars::stn::Task task;
task.cmdid_ = 1;
task.channel_select_ = mars::stn::Task::kChannelShort;
task.cgi_ = "/cgi-bin/micromsg-bin/getprofile";
task.shortlink_host_list_.push_back("www.qq.com");
mars::stn::StartTask(task);
Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Pros of esp-idf
- Specifically designed for ESP32 microcontrollers, offering optimized performance and features
- Extensive documentation and community support for IoT and embedded development
- Regular updates and active maintenance by Espressif Systems
Cons of esp-idf
- Limited to ESP32 and related microcontrollers, lacking cross-platform support
- Steeper learning curve for developers new to embedded systems programming
Code Comparison
esp-idf example (FreeRTOS task creation):
void app_main(void)
{
xTaskCreate(hello_task, "hello_task", 2048, NULL, 5, NULL);
}
mars example (Network status check):
void Mars::CheckNetworkStatus() {
if (::getNetworkStatus() == kNetworkUnavailable) {
// Handle network unavailability
}
}
Summary
esp-idf is a specialized framework for ESP32 microcontrollers, offering optimized performance and extensive support for IoT development. However, it's limited to ESP32 devices and may have a steeper learning curve. mars, on the other hand, is a cross-platform network library focusing on mobile development, with broader device support but less specialization for specific hardware.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Mars
(ä¸æçæ¬è¯·åçè¿é)
Mars is a cross-platform infrastructure component developed by WeChat Mobile Team. It has been proved to be effective by billions of WeChat users.
- Cross platform, easy to deploy if you are developing multi-platform or multi-business application.
- Suitable for small amount data transmission
- Mobile platform friendly, low power and traffic consumption
- A network solution fit for mobile application
- comm: common library, including socket, thread, message queue, coroutine, etc.
- Xlog: a reliable log component with high-performance.
- SDT: a network detection component.
- STN: a signaling network component, the major part of Mars.
Samples
Start with sample usage here.
Getting started
python scripts only support python3.10 or higher
Choose Android or iOS/OS X or Windows.
Android
You can use either mars-wrapper or mars-core. We recommend you to use mars-wrapper when you just want to build a sample or demo, while mars-core is preferred to be used in your APP.
mars-wrapper
Add dependencies by adding the following lines to your app/build.gradle.
dependencies {
compile 'com.tencent.mars:mars-wrapper:1.2.5'
}
OR
mars-core
Add dependencies by adding the following lines to your app/build.gradle.
dependencies {
compile 'com.tencent.mars:mars-core:1.2.5'
}
OR
mars-xlog
If you just want to user xlog, add dependencies by adding the following lines to your app/build.gradle. note: xlog is included in mars-core and mars-wrapper.
dependencies {
compile 'com.tencent.mars:mars-xlog:1.2.5'
}
If you read here, make sure you have added dependencies of mars-wrapper, mars-core or mars-xlog.
Xlog Init
Initialize Xlog when your APP starts. Remember to use an exclusive folder to save the log files, no other files are acceptable in the folder since they would be removed by the cleansing function in Xlog automatically.
When multiple processes is used in your app, make sure that each process owns its exclusive log file.
System.loadLibrary("c++_shared");
System.loadLibrary("marsxlog");
final String SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
final String logPath = SDCARD + "/marssample/log";
// this is necessary, or may crash for SIGBUS
final String cachePath = this.getFilesDir() + "/xlog"
//init xlog
Xlog xlog = new Xlog();
Log.setLogImp(xlog);
if (BuildConfig.DEBUG) {
Log.setConsoleLogOpen(true);
Log.appenderOpen(Xlog.LEVEL_DEBUG, Xlog.AppednerModeAsync, "", logPath, logFileName, 0);
} else {
Log.setConsoleLogOpen(false);
Log.appenderOpen(Xlog.LEVEL_INFO, Xlog.AppednerModeAsync, "", logPath, logFileName, 0);
}
Uninitialized Xlog when your app exits
Log.appenderClose();
STN Init
If you add dependencies of mars-core to your project, you need to initialize and release STN. Initialize STN before you use it
// set callback
AppLogic.setCallBack(stub);
StnLogic.setCallBack(stub);
SdtLogic.setCallBack(stub);
// Initialize the Mars PlatformComm
Mars.init(getApplicationContext(), new Handler(Looper.getMainLooper()));
// Initialize the Mars
StnLogic.setLonglinkSvrAddr(profile.longLinkHost(), profile.longLinkPorts());
StnLogic.setShortlinkSvrAddr(profile.shortLinkPort());
StnLogic.setClientVersion(profile.productID());
Mars.onCreate(true);
BaseEvent.onForeground(true);
StnLogic.makesureLongLinkConnected();
Firstly, you should call the setCallBack interface, and secondly, the Mars.init. Then, to initialize the Mars, there is to need to strictly follow the orders of the four commands. Finally, after Mars are initialized, onForeground and makesureLongLinkConnect can be called.
Destroy STN or exit your app:
Mars.onDestroy();
Event Change
Network change:
BaseEvent.onNetworkChange()
If you add dependencies of mars-wrapper to your project, you just need initialize STN and no need uninitialized.
MarsServiceProxy.init(this, getMainLooper(),null);
No matter which way of dependencies you used, you must pay attention to these.
The state (background or foreground) of the APP is changed:
BaseEvent.onForeground(boolean);
The account of the APP is changed:
StnLogic.reset();
If you want to modify the encryption algorithm of Xlog, the packer/unpacker of longlink/shortlink, or you want to define the other components by yourself, refer here
iOS/OS X
Compile
python build_ios.py
or
python build_osx.py
- Add mars.framework as a dependency of your project.
- Rename files in mars/libraries/mars_android_sdk/jni with .rewriteme extension to .cc extension.
- Add header files in mars/libraries/mars_android_sdk/jni and source files from step 2 into your project.
Xlog Init
Initialize Xlog when your app starts. Remember to use an exclusive folder to save the log files, no other files are acceptable in the folder since they would be removed by the cleansing function in Xlog automatically.
NSString* logPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/log"];
// set do not backup for logpath
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
setxattr([logPath UTF8String], attrName, &attrValue, sizeof(attrValue), 0, 0);
// init xlogger
#if DEBUG
xlogger_SetLevel(kLevelDebug);
appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
XLogConfig config;
config.mode_ = kAppenderAsync;
config.logdir_ = [logPath UTF8String];
config.nameprefix_ = "Test";
config.pub_key_ = "";
config.compress_mode_ = kZlib;
config.compress_level_ = 0;
config.cachedir_ = "";
config.cache_days_ = 0;
appender_open(config);
Close xlog in function "applicationWillTerminate"
appender_close();
STN Init
Initialize STN before you use it:
- (void)setCallBack {
mars::stn::SetCallback(mars::stn::StnCallBack::Instance());
mars::app::SetCallback(mars::app::AppCallBack::Instance());
}
- (void) createMars {
mars::baseevent::OnCreate();
}
- (void)setClientVersion:(UInt32)clientVersion {
mars::stn::SetClientVersion(clientVersion);
}
- (void)setShortLinkDebugIP:(NSString *)IP port:(const unsigned short)port {
std::string ipAddress([IP UTF8String]);
mars::stn::SetShortlinkSvrAddr(port, ipAddress);
}
- (void)setShortLinkPort:(const unsigned short)port {
mars::stn::SetShortlinkSvrAddr(port);
}
- (void)setLongLinkAddress:(NSString *)string port:(const unsigned short)port debugIP:(NSString *)IP {
std::string ipAddress([string UTF8String]);
std::string debugIP([IP UTF8String]);
std::vector<uint16_t> ports;
ports.push_back(port);
mars::stn::SetLonglinkSvrAddr(ipAddress,ports,debugIP);
}
- (void)setLongLinkAddress:(NSString *)string port:(const unsigned short)port {
std::string ipAddress([string UTF8String]);
std::vector<uint16_t> ports;
ports.push_back(port);
mars::stn::SetLonglinkSvrAddr(ipAddress,ports);
}
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForeground);
}
- (void)makesureLongLinkConnect {
mars::stn::MakesureLonglinkConnected();
}
Firstly, you should call the setCallBack interface, and secondly, the Mars.init. Then, to initialize the Mars, there is to need to strictly follow the orders of the four commands. Finally, after Mars are initialized, onForeground and makesureLongLinkConnect can be called.
If you want to destroy STN or exit App:
- (void)destroyMars {
mars::baseevent::OnDestroy();
}
Event Change
When the App's state of background or foreground is changed:
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForeground);
}
Network change:
- (void)reportEvent_OnNetworkChange {
mars::baseevent::OnNetworkChange();
}
Windows
Install Visual Studio 2015.
Compile
python build_windows.py
- Add mars.lib as a dependency of your project.
- Rename files in mars/libraries/mars_android_sdk/jni with .rewriteme extension to .cc extension.
- Add header files in mars/libraries/mars_android_sdk/jni and source files from step 2 into your project.
Xlog Init
Initialize Xlog when your app starts. Remember to use an exclusive folder to save the log files, no other files are acceptable in the folder since they would be removed by the cleansing function in Xlog automatically.
std::string logPath = ""; //use your log path
std::string pubKey = ""; //use you pubkey for log encrypt
// init xlog
#if DEBUG
xlogger_SetLevel(kLevelDebug);
appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
appender_open(kAppenderAsync, logPath.c_str(), "Test", 0, pubKey.c_str());
Uninitialized xlog before your app exits
appender_close();
STN Init
Initialize STN before you use it:
void setShortLinkDebugIP(const std::string& _ip, unsigned short _port)
{
mars::stn::SetShortlinkSvrAddr(_port, _ip);
}
void setShortLinkPort(unsigned short _port)
{
mars::stn::SetShortlinkSvrAddr(_port, "");
}
void setLongLinkAddress(const std::string& _ip, unsigned short _port, const std::string& _debug_ip)
{
vector<uint16_t> ports;
ports.push_back(_port);
mars::stn::SetLonglinkSvrAddr(_ip, ports, _debug_ip);
}
void Init()
{
mars::stn::SetCallback(mars::stn::StnCallBack::Instance());
mars::app::SetCallback(mars::app::AppCallBack::Instance());
mars::baseevent::OnCreate();
//todo
//mars::stn::SetClientVersion(version);
//setShortLinkDebugIP(...)
//setLongLinkAddress(...)
mars::baseevent::OnForeground(true);
mars::stn::MakesureLonglinkConnected();
}
Firstly, you should call the setCalBack interface, and secondly, the Mars.init. Then, to initialize the Mars, there is to need to strictly follow the orders of the four commands. Finally, after Mars are initialized, onForeground and makesureLongLinkConnect can be called.
If you want to destroy STN or exit App:
mars::baseevent::OnDestroy();
Support
Any problem?
- Learn more from mars/sample.
- Read the source code.
- Read the wiki or FAQ for help.
- Contact us for help.
Contributing
For more information about contributing issues or pull requests, see our Mars Contributing Guide.
License
Mars is under the MIT license. See the LICENSE file for details.
Mars
Mars æ¯å¾®ä¿¡å®æ¹ç跨平å°è·¨ä¸å¡çç»ç«¯åºç¡ç»ä»¶ã
- commï¼å¯ä»¥ç¬ç«ä½¿ç¨çå ¬å ±åºï¼å æ¬ socketã线ç¨ãæ¶æ¯éåãåç¨çï¼
- xlogï¼é«å¯é æ§é«æ§è½çè¿è¡ææ¥å¿ç»ä»¶ï¼
- SDTï¼ ç½ç»è¯æç»ä»¶ï¼
- STNï¼ ä¿¡ä»¤ååç½ç»æ¨¡åï¼ä¹æ¯ Mars æ主è¦çé¨åã
Samples
sample ç使ç¨è¯·åèè¿éã
Getting started
python >= 3,10 æ¥å ¥ Android æè iOS/OS X æè Windows ã
Android
gradle æ¥å ¥æ们æä¾äºä¸¤ç§æ¥å ¥æ¹å¼ï¼mars-wrapper æè mars-coreãå¦æä½ åªæ¯æ³å个 sample æ¨èä½¿ç¨ mars-wrapperï¼å¯ä»¥å¿«éå¼åï¼ä½æ¯å¦æä½ æ³æ mars ç¨å°ä½ ç app ä¸çè¯ï¼æ¨èä½¿ç¨ mars-coreï¼å¯å®å¶æ§æ´é«ã
mars-wrapper
å¨ app/build.gradle ä¸æ·»å mars-wrapper çä¾èµï¼
dependencies {
compile 'com.tencent.mars:mars-wrapper:1.2.5'
}
æè
mars-core
å¨ app/build.gradle ä¸æ·»å mars-core çä¾èµï¼
dependencies {
compile 'com.tencent.mars:mars-core:1.2.5'
}
æè
mars-xlog
å¦æåªæ³ä½¿ç¨ xlog,å¯ä»¥åªå xlog çä¾èµ(mars-core,mars-wrapper ä¸é½å·²ç»å æ¬ xlog)ï¼
dependencies {
compile 'com.tencent.mars:mars-xlog:1.2.5'
}
æ¥çå¾ä¸æä½ä¹åï¼è¯·å ç¡®ä¿ä½ å·²ç»æ·»å äº mars-wrapper æè mars-core æè mars-xlog çä¾èµ
Xlog Init
å¨ç¨åºå¯å¨å è½½ Xlog åç´§æ¥çåå§å Xlogãä½è¦æ³¨æå¦æä½ çç¨åºä½¿ç¨äºå¤è¿ç¨ï¼ä¸è¦æå¤ä¸ªè¿ç¨çæ¥å¿è¾åºå°åä¸ä¸ªæ件ä¸ï¼ä¿è¯æ¯ä¸ªè¿ç¨ç¬äº«ä¸ä¸ªæ¥å¿æ件ãèä¸ä¿å log çç®å½è¯·ä½¿ç¨åç¬çç®å½ï¼ä¸è¦åæ¾ä»»ä½å ¶ä»æ件é²æ¢è¢« xlog èªå¨æ¸ çåè½è¯¯å ã
System.loadLibrary("c++_shared");
System.loadLibrary("marsxlog");
final String SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
final String logPath = SDCARD + "/marssample/log";
// this is necessary, or may crash for SIGBUS
final String cachePath = this.getFilesDir() + "/xlog"
//init xlog
Xlog.XLogConfig logConfig = new Xlog.XLogConfig();
logConfig.mode = Xlog.AppednerModeAsync;
logConfig.logdir = logPath;
logConfig.nameprefix = logFileName;
logConfig.pubkey = "";
logConfig.compressmode = Xlog.ZLIB_MODE;
logConfig.compresslevel = 0;
logConfig.cachedir = "";
logConfig.cachedays = 0;
if (BuildConfig.DEBUG) {
logConfig.level = Xlog.LEVEL_VERBOSE;
Xlog.setConsoleLogOpen(true);
} else {
logConfig.level = Xlog.LEVEL_INFO;
Xlog.setConsoleLogOpen(false);
}
Log.setLogImp(new Xlog());
ç¨åºéåºæ¶å ³éæ¥å¿ï¼
Log.appenderClose();
STN Init
å¦æä½ æ¯æ mars-core ä½ä¸ºä¾èµå å ¥å°ä½ ç项ç®ä¸çè¯ï¼ä½ éè¦æ¾å¼çåå§ååååå§å STN
å¨ä½¿ç¨ STN ä¹åè¿è¡åå§å
// set callback
AppLogic.setCallBack(stub);
StnLogic.setCallBack(stub);
SdtLogic.setCallBack(stub);
// Initialize the Mars PlatformComm
Mars.init(getApplicationContext(), new Handler(Looper.getMainLooper()));
// Initialize the Mars
StnLogic.setLonglinkSvrAddr(profile.longLinkHost(), profile.longLinkPorts());
StnLogic.setShortlinkSvrAddr(profile.shortLinkPort());
StnLogic.setClientVersion(profile.productID());
Mars.onCreate(true);
BaseEvent.onForeground(true);
StnLogic.makesureLongLinkConnected();
åå§å顺åºä¸ä¸å®è¦ä¸¥æ ¼éµå®ä¸è¿°ä»£ç ç顺åºï¼ä½å¨åå§åæ¶é¦å
è¦è°ç¨ setCallBack æ¥å£ (callback æ件çç¼åå¯ä»¥åè demo)ï¼åè°ç¨ Mars.initï¼æååè°ç¨ onForeground å makesureLongLinkConnectï¼ä¸é´é¡ºåºå¯ä»¥éææ´æ¹ã注æï¼STN é»è®¤æ¯åå°ï¼æ以åå§å STN åéè¦ä¸»å¨è°ç¨ä¸æ¬¡BaseEvent.onForeground(true)
éè¦éæ¾ STN æè éåºç¨åºæ¶:
Mars.onDestroy();
Event Change
ç½ç»åæ¢æ¶:
BaseEvent.onNetworkChange()
å¦æä½ æ¯æ mars-wrapper ä½ä¸ºä¾èµå å ¥å°ä½ ç项ç®ä¸ï¼ä½ åªéè¦æ¾å¼çåå§å STNï¼ä¸éè¦ååå§å(å 为 mars-wrapper ä¼è¿è¡ååå§å)
MarsServiceProxy.init(this, getMainLooper(),null);
ä¸ç®¡ä½ æ¯ä½¿ç¨ mars-wrapper è¿æ¯ mars-coreï¼ä½ é½éè¦ç¹å«æ³¨æ以ä¸äºä»¶ï¼
ååå°åæ¢:
BaseEvent.onForeground(boolean);
åºç¨çè´¦å·ä¿¡æ¯æ´æ¹:
StnLogic.reset();
å¦æä½ æ³ä¿®æ¹ Xlog çå å¯ç®æ³æè é¿çè¿çå 解å é¨åçè³æ´æ¹ç»ä»¶çå ¶ä»é¨åï¼å¯ä»¥åèè¿é
iOS/OS X
ç¼è¯
python build_ios.py
or
python build_osx.py
æ mars.framework ä½ä¸ºä¾èµå å ¥å°ä½ ç项ç®ä¸ï¼æmars/libraries/mars_android_sdk/jni ç®å½çåç¼å为 rewriteme çæ件åå æ".rewriteme"å头æ件ä¸èµ·å å ¥å°ä½ ç项ç®ä¸ã
Xlog Init
å¨ç¨åºå¯å¨å è½½ Xlog åç´§æ¥çåå§å Xlogãä½è¦æ³¨æä¿å log çç®å½è¯·ä½¿ç¨åç¬çç®å½ï¼ä¸è¦åæ¾ä»»ä½å ¶ä»æ件é²æ¢è¢« xlog èªå¨æ¸ çåè½è¯¯å ã
NSString* logPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/log"];
// set do not backup for logpath
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
setxattr([logPath UTF8String], attrName, &attrValue, sizeof(attrValue), 0, 0);
// init xlogger
#if DEBUG
xlogger_SetLevel(kLevelDebug);
appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
XLogConfig config;
config.mode_ = kAppenderAsync;
config.logdir_ = [logPath UTF8String];
config.nameprefix_ = "Test";
config.pub_key_ = "";
config.compress_mode_ = kZlib;
config.compress_level_ = 0;
config.cachedir_ = "";
config.cache_days_ = 0;
appender_open(config);
å¨å½æ° "applicationWillTerminate" ä¸ååå§å Xlog
appender_close();
STN Init
å¨ä½ ç¨ STN ä¹ååå§åï¼
- (void)setCallBack {
mars::stn::SetCallback(mars::stn::StnCallBack::Instance());
mars::app::SetCallback(mars::app::AppCallBack::Instance());
}
- (void) createMars {
mars::baseevent::OnCreate();
}
- (void)setClientVersion:(UInt32)clientVersion {
mars::stn::SetClientVersion(clientVersion);
}
- (void)setShortLinkDebugIP:(NSString *)IP port:(const unsigned short)port {
std::string ipAddress([IP UTF8String]);
mars::stn::SetShortlinkSvrAddr(port, ipAddress);
}
- (void)setShortLinkPort:(const unsigned short)port {
mars::stn::SetShortlinkSvrAddr(port);
}
- (void)setLongLinkAddress:(NSString *)string port:(const unsigned short)port debugIP:(NSString *)IP {
std::string ipAddress([string UTF8String]);
std::string debugIP([IP UTF8String]);
std::vector<uint16_t> ports;
ports.push_back(port);
mars::stn::SetLonglinkSvrAddr(ipAddress,ports,debugIP);
}
- (void)setLongLinkAddress:(NSString *)string port:(const unsigned short)port {
std::string ipAddress([string UTF8String]);
std::vector<uint16_t> ports;
ports.push_back(port);
mars::stn::SetLonglinkSvrAddr(ipAddress,ports);
}
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForground);
}
- (void)makesureLongLinkConnect {
mars::stn::MakesureLonglinkConnected();
}
åå§å顺åºä¸ä¸å®è¦ä¸¥æ ¼éµå®ä¸è¿°ä»£ç ç顺åºï¼ä½å¨åå§åæ¶é¦å
è¦è°ç¨ setCallBack æ¥å£ (callback æ件çç¼åå¯ä»¥åè demo)ï¼åè°ç¨ Mars.initï¼æååè°ç¨ onForeground å makesureLongLinkConnectï¼ä¸é´é¡ºåºå¯ä»¥éææ´æ¹ã注æï¼STN é»è®¤æ¯åå°ï¼æ以åå§å STN åéè¦ä¸»å¨è°ç¨ä¸æ¬¡BaseEvent.onForeground(true)
éè¦éæ¾ STN æè éåºç¨åºæ¶:
- (void)destroyMars {
mars::baseevent::OnDestroy();
}
Event Change
ååå°åæ¢æ¶:
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForeground);
}
ç½ç»åæ¢æ¶ï¼
- (void)reportEvent_OnNetworkChange {
mars::baseevent::OnNetworkChange();
}
Windows
å®è£ Visual Studio 2015
ç¼è¯
python build_windows.py
æ mars.libä½ä¸ºä¾èµå å ¥å°ä½ ç项ç®ä¸ï¼æmars/libraries/mars_android_sdk/jni ç®å½çåç¼å为 rewriteme çæ件åå æ".rewriteme"å头æ件ä¸èµ·å å ¥å°ä½ ç项ç®ä¸ã
Xlog Init
å¨ç¨åºå¯å¨å è½½ Xlog åç´§æ¥çåå§å Xlogãä½è¦æ³¨æä¿å log çç®å½è¯·ä½¿ç¨åç¬çç®å½ï¼ä¸è¦åæ¾ä»»ä½å ¶ä»æ件é²æ¢è¢« xlog èªå¨æ¸ çåè½è¯¯å ã
std::string logPath = ""; //use your log path
std::string pubKey = ""; //use you pubkey for log encrypt
// init xlog
#if DEBUG
xlogger_SetLevel(kLevelDebug);
appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
appender_open(kAppenderAsync, logPath.c_str(), "Test", 0, pubKey.c_str());
å¨ç¨åºéåºåååå§å Xlog
appender_close();
STN Init
å¨ä½ ç¨ STN ä¹ååå§åï¼
void setShortLinkDebugIP(const std::string& _ip, unsigned short _port)
{
mars::stn::SetShortlinkSvrAddr(_port, _ip);
}
void setShortLinkPort(unsigned short _port)
{
mars::stn::SetShortlinkSvrAddr(_port, "");
}
void setLongLinkAddress(const std::string& _ip, unsigned short _port, const std::string& _debug_ip)
{
vector<uint16_t> ports;
ports.push_back(_port);
mars::stn::SetLonglinkSvrAddr(_ip, ports, _debug_ip);
}
void Init()
{
mars::stn::SetCallback(mars::stn::StnCallBack::Instance());
mars::app::SetCallback(mars::app::AppCallBack::Instance());
mars::baseevent::OnCreate();
//todo
//mars::stn::SetClientVersion(version);
//setShortLinkDebugIP(...)
//setLongLinkAddress(...)
mars::baseevent::OnForeground(true);
mars::stn::MakesureLonglinkConnected();
}
åå§å顺åºä¸ä¸å®è¦ä¸¥æ ¼éµå®ä¸è¿°ä»£ç ç顺åºï¼ä½å¨åå§åæ¶é¦å
è¦è°ç¨ setCallBack æ¥å£ (callback æ件çç¼åå¯ä»¥åè demo)ï¼åè°ç¨ Mars.initï¼æååè°ç¨ onForeground å makesureLongLinkConnectï¼ä¸é´é¡ºåºå¯ä»¥éææ´æ¹ã注æï¼STN é»è®¤æ¯åå°ï¼æ以åå§å STN åéè¦ä¸»å¨è°ç¨ä¸æ¬¡BaseEvent.onForeground(true)
éè¦éæ¾ STN æè éåºç¨åºæ¶:
mars::baseevent::OnDestroy();
Support
è¿æå ¶ä»é®é¢ï¼
- åç mars/sampleï¼
- é 读 æºç ï¼
- é 读 wiki æè FAQï¼
- èç³»æ们ã
Contributing
å ³äº Mars åæ¯ç®¡çãissue 以å pr è§èï¼è¯·é 读 Mars Contributing Guideã
License
Mars 使ç¨ç MIT åè®®ï¼è¯¦ç»è¯·åè LICENSEã
ä¿¡æ¯å ¬ç¤º
- SDKå称ï¼Mars
- çæ¬å·ï¼0.2.0
- å¼åè ï¼æ·±å³å¸è ¾è®¯è®¡ç®æºç³»ç»æéå ¬å¸
- 主è¦åè½ï¼Mars æ¯å¾®ä¿¡å®æ¹ç跨平å°è·¨ä¸å¡çç»ç«¯åºç¡ç»ä»¶ãæ¯æiOSãmacOS åAndroidãMars é对移å¨ç½ç»çç¹ç¹è¿è¡äºä¼åï¼æç»æä¾äºé«æ§è½çç½ç»åè½ã
- Mars 使ç¨è¯´æ
- Mars 个人信æ¯ä¿æ¤è§å
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot