1 /* 2 * Copyright (c) 2025 Huawei Device 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_MECHBODY_CONTROLLER_SERVICE_H 17 #define OHOS_MECHBODY_CONTROLLER_SERVICE_H 18 19 #include "mechbody_controller_stub.h" 20 #include "system_ability.h" 21 #include "mc_controller_manager.h" 22 23 namespace OHOS { 24 namespace MechBodyController { 25 26 class MechBodyControllerService : public SystemAbility, public MechBodyControllerStub { 27 DECLARE_SYSTEM_ABILITY(MechBodyControllerService); 28 public: 29 static MechBodyControllerService& GetInstance(); 30 private: 31 MechBodyControllerService(const MechBodyControllerService&) = delete; 32 MechBodyControllerService& operator= (const MechBodyControllerService&) = delete; 33 MechBodyControllerService(MechBodyControllerService&&) = delete; 34 MechBodyControllerService& operator= (MechBodyControllerService&&) = delete; 35 public: 36 MechBodyControllerService(); 37 ~MechBodyControllerService(); 38 39 int32_t OnDeviceConnected(int32_t mechId) override; 40 int32_t OnDeviceDisconnected(int32_t mechId) override; 41 42 int32_t RegisterAttachStateChangeCallback(const sptr<IRemoteObject> callback) override; 43 int32_t UnRegisterAttachStateChangeCallback() override; 44 int32_t OnAttachStateChange(const AttachmentState &attachmentState, const MechInfo &mechInfo); 45 int32_t GetAttachedDevices(std::set<MechInfo> &mechInfo) override; 46 int32_t SetUserOperation(const std::shared_ptr<Operation> &operation, 47 const std::string &mac, const std::string ¶m) override; 48 49 int32_t SetTrackingEnabled(bool &isEnabled) override; 50 int32_t GetTrackingEnabled(bool &isEnabled) override; 51 int32_t RegisterTrackingEventCallback(sptr<IRemoteObject> callback) override; 52 int32_t UnRegisterTrackingEventCallback() override; 53 int32_t SetTrackingLayout(CameraTrackingLayout &cameraTrackingLayout) override; 54 int32_t GetTrackingLayout(CameraTrackingLayout &cameraTrackingLayoutb) override; 55 56 int32_t RegisterCmdChannel(const sptr<IRemoteObject> callback) override; 57 int32_t RotateByDegree(const int32_t &mechId, std::string &cmdId, 58 const std::shared_ptr<RotateByDegreeParam> &rotateByDegreeParam) override; 59 int32_t NotifyOperationResult(const uint32_t &tokenId, const std::string &cmdId, const ExecResult &result); 60 int32_t RotateToEulerAngles(const int32_t &mechId, std::string &cmdId, 61 const std::shared_ptr<RotateToEulerAnglesParam> &rotateToEulerAnglesParam) override; 62 int32_t GetMaxRotationTime(const int32_t &mechId, std::shared_ptr<TimeLimit> &speedLimit) override; 63 int32_t GetMaxRotationSpeed(const int32_t &mechId, RotateSpeedLimit &speedLimit) override; 64 int32_t RotateBySpeed(const int32_t &mechId, std::string &cmdId, 65 const std::shared_ptr<RotateBySpeedParam> &rotateBySpeedParam) override; 66 int32_t StopMoving(const int32_t &mechId, std::string &cmdId) override; 67 int32_t GetRotationAngles(const int32_t &mechId, std::shared_ptr<EulerAngles> &eulerAngles) override; 68 int32_t GetRotationDegreeLimits(const int32_t &mechId, RotateDegreeLimit &rotationLimit) override; 69 int32_t GetRotationAxesStatus(const int32_t &mechId, RotationAxesStatus &axesStatus) override; 70 int32_t RegisterRotationAxesStatusChangeCallback(const sptr<IRemoteObject> callback) override; 71 int32_t UnRegisterRotationAxesStatusChangeCallback() override; 72 int32_t OnRotationAxesStatusChange(const int32_t &mechId, const RotationAxesStatus &axesStatus); 73 74 private: 75 bool IsSystemApp(); 76 77 protected: 78 void OnStart() override; 79 void OnStop() override; 80 81 public: 82 std::mutex motionManagersMutex; 83 std::map<int32_t, std::shared_ptr<MotionManager>> motionManagers_; 84 std::shared_ptr<IMechConnectListener> listener_ = nullptr; 85 std::mutex deviceAttachCallbackMutex; 86 std::map<uint32_t, sptr<IRemoteObject>> deviceAttachCallback_; 87 std::mutex AxesStatusChangeCallbackMutex_; 88 std::map<uint32_t, sptr<IRemoteObject>> rotationAxesStatusChangeCallback_; 89 std::mutex cmdChannelMutex_; 90 std::map<uint32_t, sptr<IRemoteObject>> cmdChannels_; 91 std::shared_ptr<TransportSendAdapter> sendAdapter_; 92 }; 93 } // namespace MechBodyController 94 } // namespace OHOS 95 #endif // OHOS_MECHBODY_CONTROLLER_SERVICE_H 96