1 /*
2  * Copyright (c) 2020 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 "ability_record.h"
17 
18 #include "adapter.h"
19 #include "utils.h"
20 
21 namespace OHOS {
22 namespace AbilitySlite {
23 AbilityData::AbilityData() = default;
24 
~AbilityData()25 AbilityData::~AbilityData()
26 {
27     AdapterFree(wantData);
28 }
29 
30 AbilityRecord::AbilityRecord() = default;
31 
~AbilityRecord()32 AbilityRecord::~AbilityRecord()
33 {
34     AdapterFree(appName);
35     AdapterFree(appPath);
36     delete abilityData;
37     abilityData = nullptr;
38     delete abilitySavedData;
39     abilitySavedData = nullptr;
40     delete abilityThread;
41     abilityThread = nullptr;
42 }
43 
SetAppName(const char * name)44 void AbilityRecord::SetAppName(const char *name)
45 {
46     AdapterFree(appName);
47     appName = Utils::Strdup(name);
48 }
49 
SetAppPath(const char * path)50 void AbilityRecord::SetAppPath(const char *path)
51 {
52     AdapterFree(appPath);
53     appPath = Utils::Strdup(path);
54 }
55 
SetWantData(const void * wantData,uint16_t wantDataSize)56 void AbilityRecord::SetWantData(const void *wantData, uint16_t wantDataSize)
57 {
58     if (abilityData == nullptr) {
59         abilityData = new AbilityData;
60     }
61     AdapterFree(abilityData->wantData);
62     abilityData->wantData = Utils::Memdup(wantData, wantDataSize);
63     if (abilityData->wantData == nullptr) {
64         abilityData->wantDataSize = 0;
65         return;
66     }
67     abilityData->wantDataSize = wantDataSize;
68 }
69 } // namespace AbilitySlite
70 } // namespace OHOS
71