• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "remote_command_factory.h"
17 
18 #include "nlohmann/json.hpp"
19 
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
GetInstance()23 RemoteCommandFactory &RemoteCommandFactory::GetInstance()
24 {
25     static RemoteCommandFactory instance;
26     return instance;
27 }
28 
NewSyncRemoteHapTokenCommand(const std::string & srcDeviceId,const std::string & dstDeviceId,AccessTokenID tokenID)29 std::shared_ptr<SyncRemoteHapTokenCommand> RemoteCommandFactory::NewSyncRemoteHapTokenCommand(
30     const std::string &srcDeviceId, const std::string &dstDeviceId, AccessTokenID tokenID)
31 {
32     return std::make_shared<SyncRemoteHapTokenCommand>(srcDeviceId, dstDeviceId, tokenID);
33 }
34 
NewDeleteRemoteTokenCommand(const std::string & srcDeviceId,const std::string & dstDeviceId,AccessTokenID tokenID)35 std::shared_ptr<DeleteRemoteTokenCommand> RemoteCommandFactory::NewDeleteRemoteTokenCommand(
36     const std::string &srcDeviceId, const std::string &dstDeviceId, AccessTokenID tokenID)
37 {
38     return std::make_shared<DeleteRemoteTokenCommand>(srcDeviceId, dstDeviceId, tokenID);
39 }
40 
NewUpdateRemoteHapTokenCommand(const std::string & srcDeviceId,const std::string & dstDeviceId,const HapTokenInfoForSync & tokenInfo)41 std::shared_ptr<UpdateRemoteHapTokenCommand> RemoteCommandFactory::NewUpdateRemoteHapTokenCommand(
42     const std::string &srcDeviceId, const std::string &dstDeviceId, const HapTokenInfoForSync& tokenInfo)
43 {
44     return std::make_shared<UpdateRemoteHapTokenCommand>(srcDeviceId, dstDeviceId, tokenInfo);
45 }
46 
NewSyncRemoteNativeTokenCommand(const std::string & srcDeviceId,const std::string & dstDeviceId)47 std::shared_ptr<SyncRemoteNativeTokenCommand> RemoteCommandFactory::NewSyncRemoteNativeTokenCommand(
48     const std::string &srcDeviceId, const std::string &dstDeviceId)
49 {
50     return std::make_shared<SyncRemoteNativeTokenCommand>(srcDeviceId, dstDeviceId);
51 }
52 
NewRemoteCommandFromJson(const std::string & commandName,const std::string & commandJsonString)53 std::shared_ptr<BaseRemoteCommand> RemoteCommandFactory::NewRemoteCommandFromJson(
54     const std::string &commandName, const std::string &commandJsonString)
55 {
56     const std::string SYNC_HAP_COMMAND_NAME = "SyncRemoteHapTokenCommand";
57     const std::string DELETE_TOKEN_COMMAND_NAME = "DeleteRemoteTokenCommand";
58     const std::string UPDATE_HAP_COMMAND_NAME = "UpdateRemoteHapTokenCommand";
59     const std::string SYNC_NATIVE_COMMAND_NAME = "SyncRemoteNativeTokenCommand";
60 
61     if (commandName == SYNC_HAP_COMMAND_NAME) {
62         return std::make_shared<SyncRemoteHapTokenCommand>(commandJsonString);
63     }
64     if (commandName == DELETE_TOKEN_COMMAND_NAME) {
65         return std::make_shared<DeleteRemoteTokenCommand>(commandJsonString);
66     }
67     if (commandName == UPDATE_HAP_COMMAND_NAME) {
68         return std::make_shared<UpdateRemoteHapTokenCommand>(commandJsonString);
69     }
70     if (commandName == SYNC_NATIVE_COMMAND_NAME) {
71         return std::make_shared<SyncRemoteNativeTokenCommand>(commandJsonString);
72     }
73     return nullptr;
74 }
75 }  // namespace AccessToken
76 }  // namespace Security
77 }  // namespace OHOS
78