1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#ifndef COOPERATE_H 17c29fa5a6Sopenharmony_ci#define COOPERATE_H 18c29fa5a6Sopenharmony_ci 19c29fa5a6Sopenharmony_ci#include <mutex> 20c29fa5a6Sopenharmony_ci 21c29fa5a6Sopenharmony_ci#include "nocopyable.h" 22c29fa5a6Sopenharmony_ci 23c29fa5a6Sopenharmony_ci#include "i_context.h" 24c29fa5a6Sopenharmony_ci#include "state_machine.h" 25c29fa5a6Sopenharmony_ci 26c29fa5a6Sopenharmony_cinamespace OHOS { 27c29fa5a6Sopenharmony_cinamespace Msdp { 28c29fa5a6Sopenharmony_cinamespace DeviceStatus { 29c29fa5a6Sopenharmony_cinamespace Cooperate { 30c29fa5a6Sopenharmony_ciclass Cooperate final : public ICooperate { 31c29fa5a6Sopenharmony_cipublic: 32c29fa5a6Sopenharmony_ci Cooperate(IContext *env); 33c29fa5a6Sopenharmony_ci ~Cooperate(); 34c29fa5a6Sopenharmony_ci DISALLOW_COPY_AND_MOVE(Cooperate); 35c29fa5a6Sopenharmony_ci 36c29fa5a6Sopenharmony_ci void AddObserver(std::shared_ptr<ICooperateObserver> observer) override; 37c29fa5a6Sopenharmony_ci void RemoveObserver(std::shared_ptr<ICooperateObserver> observer) override; 38c29fa5a6Sopenharmony_ci 39c29fa5a6Sopenharmony_ci int32_t RegisterListener(int32_t pid) override; 40c29fa5a6Sopenharmony_ci int32_t UnregisterListener(int32_t pid) override; 41c29fa5a6Sopenharmony_ci int32_t RegisterHotAreaListener(int32_t pid) override; 42c29fa5a6Sopenharmony_ci int32_t UnregisterHotAreaListener(int32_t pid) override; 43c29fa5a6Sopenharmony_ci int32_t RegisterEventListener(int32_t pid, const std::string &networkId) override; 44c29fa5a6Sopenharmony_ci int32_t UnregisterEventListener(int32_t pid, const std::string &networkId) override; 45c29fa5a6Sopenharmony_ci 46c29fa5a6Sopenharmony_ci int32_t Enable(int32_t tokenId, int32_t pid, int32_t userData) override; 47c29fa5a6Sopenharmony_ci int32_t Disable(int32_t pid, int32_t userData) override; 48c29fa5a6Sopenharmony_ci int32_t Start(int32_t pid, int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId) override; 49c29fa5a6Sopenharmony_ci int32_t Stop(int32_t pid, int32_t userData, bool isUnchained) override; 50c29fa5a6Sopenharmony_ci 51c29fa5a6Sopenharmony_ci int32_t GetCooperateState(int32_t pid, int32_t userData, const std::string &networkId) override; 52c29fa5a6Sopenharmony_ci int32_t GetCooperateState(const std::string &udId, bool &state) override; 53c29fa5a6Sopenharmony_ci int32_t Update(uint32_t mask, uint32_t flag) override; 54c29fa5a6Sopenharmony_ci void Dump(int32_t fd) override; 55c29fa5a6Sopenharmony_ci 56c29fa5a6Sopenharmony_ciprivate: 57c29fa5a6Sopenharmony_ci void Loop(); 58c29fa5a6Sopenharmony_ci void StartWorker(); 59c29fa5a6Sopenharmony_ci void StopWorker(); 60c29fa5a6Sopenharmony_ci void LoadMotionDrag(); 61c29fa5a6Sopenharmony_ci void UnloadMotionDrag(); 62c29fa5a6Sopenharmony_ci 63c29fa5a6Sopenharmony_ci IContext *env_ { nullptr }; 64c29fa5a6Sopenharmony_ci Context context_; 65c29fa5a6Sopenharmony_ci StateMachine sm_; 66c29fa5a6Sopenharmony_ci std::mutex lock_; 67c29fa5a6Sopenharmony_ci bool workerStarted_ { false }; 68c29fa5a6Sopenharmony_ci std::thread worker_; 69c29fa5a6Sopenharmony_ci Channel<CooperateEvent>::Receiver receiver_; 70c29fa5a6Sopenharmony_ci}; 71c29fa5a6Sopenharmony_ci} // namespace Cooperate 72c29fa5a6Sopenharmony_ci} // namespace DeviceStatus 73c29fa5a6Sopenharmony_ci} // namespace Msdp 74c29fa5a6Sopenharmony_ci} // namespace OHOS 75c29fa5a6Sopenharmony_ci#endif // COOPERATE_H 76