Skip to content

Commit

Permalink
Merge pull request #1311 from Tencent/ft/master/merge2409
Browse files Browse the repository at this point in the history
2.1 merge to master
  • Loading branch information
outman-zhou authored Sep 2, 2024
2 parents c559159 + c5ba0ed commit 9ab46e1
Show file tree
Hide file tree
Showing 143 changed files with 8,941 additions and 6,207 deletions.
43 changes: 34 additions & 9 deletions clang_format_ignore.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
mars/boost
mars/googletest
mars/googlemock
mars/rapidjson
mars/log/crypt/micro-ecc-master
mars/comm/UWP/zlib
mars/openssl
mars/zstd/tests
samples
mars/mars/boost
mars/mars/googletest
mars/mars/googlemock
mars/mars/rapidjson
mars/mars/log/crypt/micro-ecc-master
mars/mars/comm/UWP/zlib
mars/mars/openssl
mars/mars/zstd/tests
mars/samples

mars-private/mars/mmjpeg
mars-private/mars/protobuf
mars-private/mars/cdn/src/proto
mars-private/mars/cdn/src/protocol
mars-private/mars/openssl
mars-private/mars/vfs
mars-private/mars/smc/src/protobuf

mars-private/mars/andromeda/andromeda.h
mars-private/mars/andromeda/cronet_android_jni_callback.h
mars-private/mars/andromeda/cronet_file_task_runer_wrapper.h
mars-private/mars/andromeda/http_cronet_context_builder.h
mars-private/mars/andromeda/http_network_estimate_callback.h
mars-private/mars/andromeda/http_result_callback.h
mars-private/mars/andromeda/http_with_cronet.h

mars-wechat/mars/webp
mars-wechat/mars/accessory

build
cmake_build
tools
mmnet
openssl-build-tools
2 changes: 1 addition & 1 deletion mars/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ add_subdirectory(zstd/build/cmake/lib zstd)

project (mars)

include(comm/CMakeUtils.txt)
include(comm/utils.cmake)

include_directories(.)
include_directories(..)
Expand Down
2 changes: 1 addition & 1 deletion mars/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")

project (app)

include(../comm/CMakeUtils.txt)
include(../comm/utils.cmake)
include(../comm/CMakeExtraFlags.txt)

include_directories(.)
Expand Down
5 changes: 2 additions & 3 deletions mars/app/app_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "mars/comm/objc/data_protect_attr.h"
#endif

#include "mars/baseevent/baseprjevent.h"
#include "mars/comm/dns/dns.h"
#include "mars/comm/xlogger/xlogger.h"

Expand Down Expand Up @@ -51,7 +50,7 @@ mars::comm::ProxyInfo AppManager::GetProxyInfo(const std::string& _host) {
}

if (!slproxymutex_.try_lock_for(std::chrono::milliseconds(500))) {
return mars::comm::ProxyInfo();
return {};
}

if (slproxycount_ < 3 || 5 * 1000 > gettickspan(slproxytimetick_)) {
Expand All @@ -65,7 +64,7 @@ mars::comm::ProxyInfo AppManager::GetProxyInfo(const std::string& _host) {
return proxy_info_;
}

return mars::comm::ProxyInfo();
return {};
}

std::string AppManager::GetAppFilePath() {
Expand Down
2 changes: 1 addition & 1 deletion mars/baseevent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")

project (baseevent)

include(../comm/CMakeUtils.txt)
include(../comm/utils.cmake)
include(../comm/CMakeExtraFlags.txt)


Expand Down
3 changes: 3 additions & 0 deletions mars/baseevent/base_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

#include <stdint.h>

#include <string>

namespace mars {
namespace baseevent {
void OnCreate();
void OnInitBeforeOnCreate(int _encoder_status);
void OnInitBeforeOnCreateV2(int _encoder_status, std::string _encoder_name);
void OnDestroy();
void OnSingalCrash(int _sig);
void OnExceptionCrash();
Expand Down
2 changes: 2 additions & 0 deletions mars/baseevent/baseprjevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

extern boost::signals2::signal<void()>& GetSignalOnCreate();
extern boost::signals2::signal<void(int _encoder_version)>& GetSignalOnInitBeforeOnCreate();
extern boost::signals2::signal<void(int _encoder_version, std::string _encoder_name)>&
GetSignalOnInitBeforeOnCreateV2();
extern boost::signals2::signal<void()>& GetSignalOnDestroy();
extern boost::signals2::signal<void(int _sig)>& GetSignalOnSingalCrash();
extern boost::signals2::signal<void()>& GetSignalOnExceptionCrash();
Expand Down
4 changes: 4 additions & 0 deletions mars/baseevent/src/baseprj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ void OnInitBeforeOnCreate(int _encoder_status) {
GetSignalOnInitBeforeOnCreate()(_encoder_status);
}

void OnInitBeforeOnCreateV2(int _encoder_status, std::string _encoder_name) {
GetSignalOnInitBeforeOnCreateV2()(_encoder_status, _encoder_name);
}

void OnDestroy() {
GetSignalOnDestroy()();
}
Expand Down
5 changes: 5 additions & 0 deletions mars/baseevent/src/baseprjevent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ boost::signals2::signal<void(int _encoder_version)>& GetSignalOnInitBeforeOnCrea
return SignalOnInitBeforeOnCreate;
}

boost::signals2::signal<void(int _encoder_version, std::string _encoder_name)>& GetSignalOnInitBeforeOnCreateV2() {
static boost::signals2::signal<void(int _encoder_version, std::string _encoder_name)> SignalOnInitBeforeOnCreateV2;
return SignalOnInitBeforeOnCreateV2;
}

boost::signals2::signal<void()>& GetSignalOnDestroy() {
static boost::signals2::signal<void()> SignalOnDestroy;
return SignalOnDestroy;
Expand Down
2 changes: 1 addition & 1 deletion mars/boost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_compile_options(-w) # 屏蔽所有编译警告

project (mars-boost)

include(../comm/CMakeUtils.txt)
include(../comm/utils.cmake)

include_directories(.)
include_directories(..)
Expand Down
2 changes: 1 addition & 1 deletion mars/boot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")

project(boot)

include(../comm/CMakeUtils.txt)
include(../comm/utils.cmake)
include(../comm/CMakeExtraFlags.txt)

include_directories(.)
Expand Down
8 changes: 7 additions & 1 deletion mars/boot/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#ifndef MMNET_BASE_CONTEXT_H
#define MMNET_BASE_CONTEXT_H

#include <atomic>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include <atomic>

#include "base_manager.h"

Expand Down Expand Up @@ -97,6 +98,11 @@ class Context {
static std::atomic<int> s_context_index;
};

template <class... Args>
std::shared_ptr<Context> make_context_ptr(Args&&... args) {
return std::shared_ptr<Context>(Context::CreateContext(std::forward<Args>(args)...), Context::DestroyContext);
}

} // namespace boot
} // namespace mars

Expand Down
6 changes: 5 additions & 1 deletion mars/comm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")

project (comm)

include(CMakeUtils.txt)
include(utils.cmake)
include(CMakeExtraFlags.txt)

include_directories(.)
include_directories(..)
include_directories(../..)
include_directories(../openssl/include)
include_directories(alarm)
include_directories(assert)
include_directories(corepattern)
include_directories(crypt)
Expand All @@ -27,6 +28,9 @@ include_directories(owl)
file(GLOB SELF_TEMP_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR} *.cc *.c *.h)
list(APPEND SELF_SRC_FILES ${SELF_TEMP_SRC_FILES})

file(GLOB SELF_TEMP_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR} alarm/*.cc alarm/*.h)
source_group(assert FILES ${SELF_TEMP_SRC_FILES})
list(APPEND SELF_SRC_FILES ${SELF_TEMP_SRC_FILES})

file(GLOB SELF_TEMP_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR} assert/*.c assert/*.h)
source_group(assert FILES ${SELF_TEMP_SRC_FILES})
Expand Down
36 changes: 32 additions & 4 deletions mars/comm/alarm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

#include "comm/alarm.h"

#include "alarm/alarm_manager.h"
#include "comm/assert/__assert.h"
#include "comm/platform_comm.h"
#include "comm/thread/lock.h"
#include "comm/time_utils.h"

using namespace mars::alarm;

namespace mars {
namespace comm {

Expand Down Expand Up @@ -58,7 +61,14 @@ bool Alarm::Start(int _after, bool _needWake) {

#ifdef ANDROID

if (_needWake && !startAlarm(type_, (int64_t)seq, _after)) {
bool ret = false;
if (context_ && context_->GetManager<AlarmManager>()
&& context_->GetManager<AlarmManager>()->IsAlarmCallbackSet()) {
ret = context_->GetManager<AlarmManager>()->StartAlarm(type_, (int64_t)seq, _after);
} else {
ret = startAlarm(type_, (int64_t)seq, _after);
}
if (_needWake && !ret) {
xerror2(TSF "startAlarm error, id:%0, after:%1, seq:%2", (uintptr_t)this, _after, seq);
MessageQueue::CancelMessage(broadcast_msg_id_);
broadcast_msg_id_ = MessageQueue::KNullPost;
Expand Down Expand Up @@ -96,7 +106,15 @@ bool Alarm::Cancel() {

#ifdef ANDROID

if (!stopAlarm((int64_t)seq_)) {
bool ret = false;
if (context_ && context_->GetManager<AlarmManager>()
&& context_->GetManager<AlarmManager>()->IsAlarmCallbackSet()) {
ret = context_->GetManager<AlarmManager>()->StopAlarm((int64_t)seq_);
} else {
ret = stopAlarm((int64_t)seq_);
}

if (!ret) {
xwarn2(TSF "stopAlarm error, id:%0, seq:%1", (uintptr_t)this, seq_);
status_ = kCancel;
endtime_ = gettickcount();
Expand Down Expand Up @@ -186,11 +204,21 @@ void Alarm::OnAlarm(const MessageQueue::MessagePost_t& _id, MessageQueue::Messag
return;
}

stopAlarm(seq_);

// stopAlarm(seq_);
if (startAlarm(type_, (int64_t)seq_, missTime))
return;

if (context_ && context_->GetManager<AlarmManager>()
&& context_->GetManager<AlarmManager>()->IsAlarmCallbackSet()) {
context_->GetManager<AlarmManager>()->StopAlarm(seq_);
if (context_->GetManager<AlarmManager>()->StartAlarm(type_, (int64_t)seq_, missTime))
return;
} else {
stopAlarm(seq_);
if (startAlarm(type_, (int64_t)seq_, missTime))
return;
}

xerror2(TSF "startAlarm err, continue") >> group;
}

Expand Down
12 changes: 8 additions & 4 deletions mars/comm/alarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <boost/bind.hpp>

#include "boot/context.h"
#include "comm/xlogger/xlogger.h"
#include "messagequeue/message_queue.h"

Expand Down Expand Up @@ -52,8 +53,9 @@ class Alarm {

public:
template <class T>
explicit Alarm(const T& _op, bool _inthread = true)
: target_(detail::transform(_op))
explicit Alarm(const T& _op, bool _inthread = true, mars::boot::Context* _context = nullptr)
: context_(_context)
, target_(detail::transform(_op))
, reg_async_(MessageQueue::InstallAsyncHandler(MessageQueue::GetDefMessageQueue()))
, broadcast_msg_id_(MessageQueue::KNullPost)
, runthread_(boost::bind(&Alarm::__Run, this), "alarm")
Expand All @@ -73,8 +75,9 @@ class Alarm {
}

template <class T>
explicit Alarm(const T& _op, const MessageQueue::MessageQueue_t& _id)
: target_(detail::transform(_op))
explicit Alarm(const T& _op, const MessageQueue::MessageQueue_t& _id, mars::boot::Context* _context = nullptr)
: context_(_context)
, target_(detail::transform(_op))
, reg_async_(MessageQueue::InstallAsyncHandler(_id))
, broadcast_msg_id_(MessageQueue::KNullPost)
, runthread_(boost::bind(&Alarm::__Run, this), "alarm")
Expand Down Expand Up @@ -132,6 +135,7 @@ class Alarm {
virtual void __Run();

private:
mars::boot::Context* context_;
Runnable* target_;
MessageQueue::ScopeRegister reg_async_;
MessageQueue::MessagePost_t broadcast_msg_id_;
Expand Down
42 changes: 42 additions & 0 deletions mars/comm/alarm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required (VERSION 3.6)

set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "Installation directory" FORCE)
message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")

project (alarm)

include(../comm/CMakeUtils.txt)
include(../comm/CMakeExtraFlags.txt)

include_directories(.)
include_directories(src)
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})

file(GLOB SELF_TEMP_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR} src/*.cc src/*.h)
source_group(src FILES ${SELF_TEMP_SRC_FILES})
list(APPEND SELF_SRC_FILES ${SELF_TEMP_SRC_FILES})


if(MSVC)
add_definitions(/FI"../../comm/projdef.h")
include_directories(../comm/windows)
elseif(ANDROID)
if(NOT CPP_CALL_BACK)
file(GLOB SELF_ANDROID_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR} jni/*.cc)
endif()
if(NATIVE_CALLBACK)
message("applogic native callback")
add_definitions(-DNATIVE_CALLBACK)
endif()

list(APPEND SELF_SRC_FILES ${SELF_ANDROID_SRC_FILES})
endif()

BuildWithUnitTest("${PROJECT_NAME}" "${SELF_SRC_FILES}")
Loading

0 comments on commit 9ab46e1

Please sign in to comment.