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 MECH_CLIENT_H 17 #define MECH_CLIENT_H 18 19 #include <condition_variable> 20 #include <atomic> 21 #include "iremote_broker.h" 22 #include "js_mech_manager_stub.h" 23 #include "mechbody_controller_types.h" 24 #include "system_ability_load_callback_stub.h" 25 #include "system_ability_status_change_stub.h" 26 27 namespace OHOS { 28 namespace MechBodyController { 29 30 class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 31 public: 32 void SetCallback(const sptr <JsMechManagerStub> &callback); 33 34 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 35 36 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 37 public: 38 sptr<JsMechManagerStub> callback_; 39 }; 40 41 class MechClient : public std::enable_shared_from_this<MechClient> { 42 public: 43 int32_t AttachStateChangeListenOn(sptr<JsMechManagerStub> callback); 44 45 int32_t AttachStateChangeListenOff(); 46 47 int32_t GetAttachedDevices(std::vector<std::shared_ptr<MechInfo>> &attachedDevices); 48 49 int32_t SetUserOperation(const Operation &operation, const std::string &mac, const std::string ¶ms = ""); 50 51 int32_t SendUserOperation(const Operation &operation, const std::string &mac, const std::string ¶ms); 52 53 int32_t SetCameraTrackingEnabled(const bool &isEnabled); 54 55 int32_t GetCameraTrackingEnabled(bool &isEnabled); 56 57 int32_t TrackingEventListenOn(sptr<JsMechManagerStub> callback); 58 59 int32_t TrackingEventListenOff(); 60 61 int32_t SetCameraTrackingLayout(CameraTrackingLayout &cameraTrackingLayout); 62 63 int32_t GetCameraTrackingLayout(CameraTrackingLayout &cameraTrackingLayout); 64 65 int32_t RegisterCmdChannel(sptr<JsMechManagerStub> stub); 66 67 int32_t Rotate(const int32_t &mechId, const std::string &cmdId, const RotateByDegreeParam &rotateByDegreeParam); 68 69 int32_t RotateToEulerAngles(const int32_t &mechId, const std::string &cmdId, 70 const RotateToEulerAnglesParam &rotateToEulerAnglesParam); 71 72 int32_t GetMaxRotationTime(const int32_t &mechId, TimeLimit &timeLimit); 73 74 int32_t GetMaxRotationSpeed(const int32_t &mechId, RotateSpeedLimit &rotateSpeedLimit); 75 76 int32_t RotateBySpeed(const int32_t &mechId, const std::string &cmdId, RotateBySpeedParam &rotateBySpeedParam); 77 78 int32_t StopMoving(const int32_t &mechId, const std::string &cmdId); 79 80 int32_t GetRotationAngles(const int32_t &mechId, EulerAngles ¤tPosition); 81 82 int32_t GetRotationDegreeLimits(const int32_t &mechId, RotateDegreeLimit &rotationLimit); 83 84 int32_t GetRotationAxesStatus(const int32_t &mechId, RotationAxesStatus &axesStatus); 85 86 int32_t RotationAxesStatusChangeListenOn(sptr<JsMechManagerStub> callback); 87 88 int32_t RotationAxesStatusChangeListenOff(); 89 90 private: 91 sptr <IRemoteObject> GetDmsProxy(); 92 93 private: 94 std::condition_variable producerCon_; 95 std::mutex systemAbilityStatusChangeListenerMutex_; 96 sptr<SystemAbilityStatusChangeListener> systemAbilityStatusChangeListener_; 97 }; 98 99 class MechBodyServiceLoadCallback : public SystemAbilityLoadCallbackStub { 100 public: 101 102 MechBodyServiceLoadCallback(const std::weak_ptr<MechClient> &client, Operation operation, const std::string &mac, 103 const std::string ¶m); 104 105 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr <IRemoteObject> &remoteObject) override; 106 107 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 108 109 private: 110 std::weak_ptr<MechClient> client; 111 Operation operation; 112 std::string mac; 113 std::string param; 114 }; 115 116 } // namespace MechManager 117 } // namespace OHOS 118 #endif //MECH_CLIENT_H