-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:asynchronous thread, now we have a message-looper-hander(Referen…
…ce from Android) 添加了个新功能,现在支持异步线程,我们有了一个支持同步/异步 message+looper+hander的机制。(从android framwork 中的 AHander ALooper AMessage 借鉴而来,不过我们用了c++11/c++17 stl库进行了重新实现)
- Loading branch information
xiancan
committed
Aug 1, 2022
1 parent
3c098b3
commit 74ae413
Showing
15 changed files
with
1,563 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
APP_PLATFORM := android-21 | ||
#下面这个配置非常重要,不然由于c++库的问题,各种标准库链接符号问题。。。 | ||
#https://developer.android.google.cn/ndk/guides/cpp-support | ||
APP_STL := c++_shared | ||
APP_CPPFLAGS := -frtti -fexceptions | ||
#APP_STL := c++_static | ||
|
||
APP_ABI :=arm64-v8a | ||
#APP_ABI +=armeabi | ||
#APP_ABI +=armeabi-v7a | ||
APP_CPPFLAGS += -Wno-error=format-security | ||
APP_CPPFLAGS += -Wno-error=format-security -std=c++17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// Created by Administrator on 2022/7/31. | ||
// | ||
|
||
#include "CHandler.h" | ||
|
||
void CHandler::deliverMessage(const std::shared_ptr<CMessage> &msg) { | ||
onMessageReceived(msg); | ||
mMessageCounter++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// Created by Administrator on 2022/7/31. | ||
// | ||
|
||
#ifndef LIVE555_CHANDLER_H | ||
#define LIVE555_CHANDLER_H | ||
|
||
|
||
#include <memory> | ||
#include <map> | ||
#include "CLooper.h" | ||
|
||
class CMessage; | ||
|
||
class CHandler :public std::enable_shared_from_this<CHandler> { | ||
friend class CMessage; // deliverMessage() | ||
friend class CLooperRoster; // clear() | ||
public: | ||
CLooper::handler_id id() const { | ||
return mID; | ||
} | ||
|
||
std::shared_ptr<CLooper> looper() const { | ||
return mLooper.lock(); | ||
} | ||
|
||
std::weak_ptr<CLooper> getLooper() { | ||
return mLooper; | ||
} | ||
|
||
std::weak_ptr<CHandler> getHandler() { | ||
return shared_from_this(); | ||
} | ||
|
||
protected: | ||
virtual void onMessageReceived(const std::shared_ptr<CMessage> &msg) = 0; | ||
|
||
private: | ||
|
||
CLooper::handler_id mID = 0; | ||
std::weak_ptr<CLooper> mLooper; | ||
|
||
inline void setID(CLooper::handler_id id, const std::weak_ptr<CLooper> &looper) { | ||
mID = id; | ||
mLooper = looper; | ||
} | ||
|
||
inline void clear() { | ||
mID = 0; | ||
mLooper.reset(); | ||
} | ||
|
||
uint32_t mMessageCounter = 0; | ||
std::map<uint32_t, uint32_t> mMessages; | ||
|
||
void deliverMessage(const std::shared_ptr<CMessage> &msg); | ||
}; | ||
|
||
|
||
#endif //LIVE555_CHANDLER_H |
Oops, something went wrong.