1 /* 2 * Copyright (c) 2021-2024 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 OS_ACCOUNT_INTERFACES_INNERKITS_OSACCOUNT_NATIVE_INCLUDE_OS_ACCOUNT_SUBSCRIBER_H 17 #define OS_ACCOUNT_INTERFACES_INNERKITS_OSACCOUNT_NATIVE_INCLUDE_OS_ACCOUNT_SUBSCRIBER_H 18 19 #include "os_account_info.h" 20 #include "os_account_state_reply_callback.h" 21 #include "os_account_subscribe_info.h" 22 23 namespace OHOS { 24 namespace AccountSA { 25 struct OsAccountStateData { 26 OsAccountState state = OsAccountState::INVALID_TYPE; 27 int32_t fromId = -1; 28 int32_t toId = -1; 29 std::shared_ptr<OsAccountStateReplyCallback> callback = nullptr; 30 }; 31 32 class OsAccountSubscriber { 33 public: 34 OsAccountSubscriber(); 35 OsAccountSubscriber(const OsAccountSubscribeInfo &subscribeInfo); 36 virtual ~OsAccountSubscriber(); 37 38 /** 39 * Notify the account state changed. 40 * 41 * @since 16 42 */ OnStateChanged(const OsAccountStateData & data)43 virtual void OnStateChanged(const OsAccountStateData &data) {}; 44 45 /** 46 * Notify the account changed. 47 * 48 * @deprecated since 16 49 * @useinstead OnStateChanged 50 * @since 7 51 */ OnAccountsChanged(const int & id)52 virtual void OnAccountsChanged(const int &id) {}; 53 54 /** 55 * Notify the account swtiching or switched. 56 * 57 * @deprecated since 16 58 * @useinstead OnStateChanged 59 * @since 12 60 */ OnAccountsSwitch(const int & newId,const int & oldId)61 virtual void OnAccountsSwitch(const int &newId, const int &oldId) {}; 62 63 void GetSubscribeInfo(OsAccountSubscribeInfo &subscribeInfo) const; 64 65 private: 66 OsAccountSubscribeInfo subscribeInfo_; 67 }; 68 } // namespace AccountSA 69 } // namespace OHOS 70 71 #endif // OS_ACCOUNT_INTERFACES_INNERKITS_OSACCOUNT_NATIVE_INCLUDE_OS_ACCOUNT_SUBSCRIBER_H 72