Modify CPUBoostingController
[platform/core/appfw/launchpad.git] / src / lib / launchpad-common / hydra_request.cc
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "launchpad-common/hydra_request.hh"
18
19 #include <stdlib.h>
20
21 namespace launchpad {
22
23 HydraRequest::HydraRequest(int cmd, int priority)
24     : cmd_(cmd), priority_(priority) {}
25
26 HydraRequest::HydraRequest(int cmd, int priority, int argc, char** argv)
27     : cmd_(cmd), priority_(priority), argc_(argc), argv_(argv) {}
28
29 int HydraRequest::GetCommand() const {
30   return cmd_;
31 }
32
33 int HydraRequest::GetPriority() const {
34   return priority_;
35 }
36
37 int HydraRequest::GetArgc() const {
38   return argc_;
39 }
40
41 char** HydraRequest::GetArgv() const {
42   return argv_;
43 }
44
45 void HydraRequest::WriteToParcel(tizen_base::Parcel* parcel) const {
46   parcel->WriteInt32(cmd_);
47   parcel->WriteInt32(priority_);
48   parcel->WriteInt32(argc_);
49   for (int i = 0; i < argc_; ++i)
50     parcel->WriteCString(argv_[i]);
51 }
52
53 void HydraRequest::ReadFromParcel(tizen_base::Parcel* parcel) {
54   for (int i = 0; i < argc_; ++i)
55     free(argv_[i]);
56
57   free(argv_);
58   argv_ = nullptr;
59
60   parcel->ReadInt32(&cmd_);
61   parcel->ReadInt32(&priority_);
62   parcel->ReadInt32(&argc_);
63   if (argc_ == 0)
64     return;
65
66   argv_ = static_cast<char**>(calloc(argc_ + 1, sizeof(char*)));
67   if (argv_ == nullptr)
68     return;
69
70   for (int i = 0; i < argc_; ++i)
71     parcel->ReadCString(&argv_[i]);
72 }
73
74 }  // namespace launchpad