更新时间:2022-03-21 GMT+08:00
分享

场景1: 初始化

描述

使用投屏SDK业务组件时,需要先完成SDK的基础组件的初始化。

业务流程

  1. 调用ShareServiceController::GetInstance() 获取业务调用Controller

    Huawei::Idea::ShareServiceController* mShareServiceController = Huawei::Idea::ShareServiceController::GetInstance()

  2. 初始化日志

    const LogInfo logInfo = {LOG_PATH,IDEA_LEVEL_DEBUG,true}; mShareServiceController->SetLog(logInfo);

  3. 自定义事件回调类,继承自Huawei::Idea::IEventHandler, 其中构造函数INotifyUI 入参是抽象类,可由UI 类继承实现,用作向UI通知消息

    class IDEA_SHARE_API IShareEventHandler : public Huawei::Idea::IEventHandler{ public: IShareEventHandler (INotifyUI* evtHandler, ShareServiceController* controller); ~IShareEventHandler (); void OnError(ShareAppErr errorCode, std::string errorMsg, void* extralInfo); void OnDiscoverResult(DiscoverResult* discoverResult); void OnConnectResult(DeviceInfo* deviceInfo); void OnDisconnectResult(int reason); .... }; class INotifyUI { public: virtual void HandleConnectResult(std::string deviceName) = 0; virtual void HandleDisConnectResult() = 0; virtual void HandleStartSharingResult() = 0; virtual void HandleStopSharingResult() = 0; .... };

类之间关系如下图所示:

图1-7 类之间关系

4.注册回调类,初始化SDK

    const AppInfo appInfo = {};   
    mshareEvtHandler = new IShareEventHandler(this,mShareServiceController);   
    int ret = -1;   
    if (NULL != mshareEvtHandler){   
     ret = mShareServiceController->Create(appInfo,mshareEvtHandler);   
    }

注意事项

IShareEventHandler是用户自定义回调类,需继承IEventHandler, 实现IEventHandler所有的回调方法。

相关文档