1 /*
2  * Copyright (c) 2021-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 #include "operation_builder.h"
16 #include "operation.h"
17 
18 namespace OHOS {
19 namespace AAFwk {
OperationBuilder()20 OperationBuilder::OperationBuilder()
21     : abilityName_(""), action_(""), bundleName_(""), deviceId_(""), flags_(0), uri_("")
22 {
23     entities_.clear();
24 }
25 
~OperationBuilder()26 OperationBuilder::~OperationBuilder()
27 {}
28 
29 /**
30  * @description: Sets a AbilityName in an OperationBuilder.
31  * @return Returns this OperationBuilder object containing the AbilityName.
32  */
WithAbilityName(const std::string & abilityName)33 OperationBuilder &OperationBuilder::WithAbilityName(const std::string &abilityName)
34 {
35     abilityName_ = abilityName;
36     return *this;
37 }
38 
39 /**
40  * @description: Sets a BundleName in an OperationBuilder.
41  * @return Returns this OperationBuilder object containing the BundleName.
42  */
WithBundleName(const std::string & bundleName)43 OperationBuilder &OperationBuilder::WithBundleName(const std::string &bundleName)
44 {
45     bundleName_ = bundleName;
46     return *this;
47 }
48 
49 /**
50  * @description: Sets a DeviceId in an OperationBuilder.
51  * @return Returns this OperationBuilder object containing the DeviceId.
52  */
WithDeviceId(const std::string & deviceID)53 OperationBuilder &OperationBuilder::WithDeviceId(const std::string &deviceID)
54 {
55     deviceId_ = deviceID;
56     return *this;
57 }
58 
59 /**
60  * @description: Sets a Action in an OperationBuilder.
61  * @return Returns this OperationBuilder object containing the Action.
62  */
WithAction(const std::string & action)63 OperationBuilder &OperationBuilder::WithAction(const std::string &action)
64 {
65     action_ = action;
66     return *this;
67 }
68 
69 /**
70  * @description: Sets a Entities in an OperationBuilder.
71  * @return Returns this OperationBuilder object containing the Entities.
72  */
WithEntities(const std::vector<std::string> & entities)73 OperationBuilder &OperationBuilder::WithEntities(const std::vector<std::string> &entities)
74 {
75     entities_ = entities;
76     return *this;
77 }
78 
79 /**
80  * @description: Sets a Flags in an OperationBuilder.
81  * @return Returns this OperationBuilder object containing the Flags.
82  */
WithFlags(unsigned int flags)83 OperationBuilder &OperationBuilder::WithFlags(unsigned int flags)
84 {
85     flags_ = flags;
86     return *this;
87 }
88 
89 /**
90  * @description: Sets a Uri in an OperationBuilder.
91  * @return Returns this OperationBuilder object containing the Uri.
92  */
WithUri(const Uri & uri)93 OperationBuilder &OperationBuilder::WithUri(const Uri &uri)
94 {
95     uri_ = uri;
96     return *this;
97 }
98 
build()99 std::shared_ptr<Operation> OperationBuilder::build()
100 {
101     std::shared_ptr<Operation> operation = std::make_shared<Operation>();
102     operation->abilityName_ = abilityName_;
103     operation->bundleName_ = bundleName_;
104     operation->deviceId_ = deviceId_;
105     operation->action_ = action_;
106     operation->entities_ = entities_;
107     operation->flags_ = flags_;
108     operation->uri_ = uri_;
109 
110     return operation;
111 }
112 }  // namespace AAFwk
113 }  // namespace OHOS