86 lines
1.7 KiB
Markdown
86 lines
1.7 KiB
Markdown
|
|
# DisplayFlow API 文档
|
||
|
|
|
||
|
|
本文档描述 DisplayFlow 的核心 API。
|
||
|
|
|
||
|
|
## 1. 核心 API
|
||
|
|
|
||
|
|
### 1.1 会话管理
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
class SessionManager {
|
||
|
|
public:
|
||
|
|
std::shared_ptr<Session> CreateSession(RoleType role);
|
||
|
|
void DestroySession(SessionId sessionId);
|
||
|
|
std::shared_ptr<Session> GetSession(SessionId sessionId);
|
||
|
|
};
|
||
|
|
```
|
||
|
|
|
||
|
|
### 1.2 角色管理
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
class RoleManager {
|
||
|
|
public:
|
||
|
|
bool RegisterRole(RoleType type, std::shared_ptr<IRole> role);
|
||
|
|
bool SwitchRole(SessionId sessionId, RoleType newRole);
|
||
|
|
};
|
||
|
|
```
|
||
|
|
|
||
|
|
### 1.3 网络管理
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
class NetworkManager {
|
||
|
|
public:
|
||
|
|
bool Initialize();
|
||
|
|
std::vector<NetworkInterface> GetAvailableInterfaces();
|
||
|
|
bool Connect(const NetworkInterface& interface);
|
||
|
|
void Disconnect();
|
||
|
|
};
|
||
|
|
```
|
||
|
|
|
||
|
|
## 2. 平台 API
|
||
|
|
|
||
|
|
### 2.1 Android
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
class AndroidPlatformAdapter {
|
||
|
|
public:
|
||
|
|
bool Initialize();
|
||
|
|
bool StartScreenCapture();
|
||
|
|
void StopScreenCapture();
|
||
|
|
void SetFrameCallback(FrameCallback callback);
|
||
|
|
};
|
||
|
|
```
|
||
|
|
|
||
|
|
### 2.2 Windows
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
class WindowsPlatformAdapter {
|
||
|
|
public:
|
||
|
|
bool Initialize();
|
||
|
|
bool CreateVirtualDisplay(const Resolution& resolution);
|
||
|
|
void DestroyVirtualDisplay();
|
||
|
|
bool RenderFrame(const VideoFrame& frame);
|
||
|
|
};
|
||
|
|
```
|
||
|
|
|
||
|
|
## 3. 使用示例
|
||
|
|
|
||
|
|
### 3.1 创建 Host 会话
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
auto sessionManager = std::make_shared<SessionManager>();
|
||
|
|
auto session = sessionManager->CreateSession(RoleType::Host);
|
||
|
|
auto hostRole = std::make_shared<HostRole>();
|
||
|
|
hostRole->Start(session);
|
||
|
|
```
|
||
|
|
|
||
|
|
### 3.2 创建 Client 会话
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
auto sessionManager = std::make_shared<SessionManager>();
|
||
|
|
auto session = sessionManager->CreateSession(RoleType::Client);
|
||
|
|
auto clientRole = std::make_shared<ClientRole>();
|
||
|
|
clientRole->Start(session);
|
||
|
|
```
|
||
|
|
|