1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_SHARING_BASE_SESSION_H 17 #define OHOS_SHARING_BASE_SESSION_H 18 19 #include "common/identifier.h" 20 #include "common/object.h" 21 #include "common/sharing_log.h" 22 #include "event/handle_event_base.h" 23 #include "isession_listener.h" 24 #include "session_def.h" 25 26 namespace OHOS { 27 namespace Sharing { 28 29 enum SessionRunningStatus { 30 SESSION_START, 31 SESSION_STOP, 32 SESSION_PAUSE, 33 SESSION_DESTROY, 34 SESSION_RESUME, 35 SESSION_INTERRUPT 36 }; 37 38 class BaseSession : public Object, 39 public HandleEventBase, 40 public IdentifierInfo { 41 public: 42 using Ptr = std::shared_ptr<BaseSession>; 43 44 BaseSession() = default; 45 virtual ~BaseSession() = default; 46 SetSessionListener(std::weak_ptr<ISessionListener> listener)47 void SetSessionListener(std::weak_ptr<ISessionListener> listener) 48 { 49 listener_ = listener; 50 } 51 52 public: 53 virtual void UpdateOperation(SessionStatusMsg::Ptr &statusMsg) = 0; 54 virtual void UpdateMediaStatus(SessionStatusMsg::Ptr &statusMsg) = 0; 55 56 protected: Notify(SessionStatusMsg::Ptr & statusMsg)57 void Notify(SessionStatusMsg::Ptr &statusMsg) 58 { 59 SHARING_LOGD("trace."); 60 auto listener = listener_.lock(); 61 if (listener) { 62 listener->OnSessionNotify(statusMsg); 63 } 64 } 65 66 protected: 67 bool interrupting_ = false; 68 std::weak_ptr<ISessionListener> listener_; 69 SessionRunningStatus status_ = SESSION_START; 70 }; 71 72 } // namespace Sharing 73 } // namespace OHOS 74 #endif