Add new features into boot sequence app info
[platform/core/appfw/aul-1.git] / tool / aulctl / operation / status_once_operation.cc
1 /*
2  * Copyright (c) 2022 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 "status_once_operation.hh"
18
19 #include <iostream>
20 #include <string>
21 #include <utility>
22
23 #include "boot_sequence/boot_sequence_manager.hh"
24 #include "aul_app_context.h"
25 #include "aul_boot_sequence.h"
26
27 namespace aul {
28
29 StatusOnceOperation::StatusOnceOperation(std::string appid)
30     : appid_(std::move(appid)) {
31 }
32
33 bool StatusOnceOperation::Process() {
34   auto& manager = internal::boot_sequence::BootSequenceManager::GetInst();
35   auto app_list = manager.GetAppInfoList(getuid());
36   if (app_list.empty()) {
37     std::cerr << "Failed to get boot sequence app list." << std::endl;
38     return false;
39   }
40
41   for (const auto& app : app_list) {
42     if (app->GetAppId() != appid_)
43       continue;
44
45     std::cout << "appid: " << app->GetAppId() << std::endl;
46
47     std::cout << "status: " << app->GetActiveState() << std::endl;
48     std::cout << "sub status: " << app->GetSubState() << std::endl;
49     if (app->GetSubState() == "fail")
50       std::cout << "  message: " << app->GetStatusMessage() << std::endl;
51
52     aul_app_context_h context;
53     int ret = aul_app_context_create(app->GetAppId().c_str(), &context);
54     if (ret == 0) {
55       const char* val = nullptr;
56       aul_app_context_get_app_path(context, const_cast<char**>(&val));
57       std::cout << "app path: " << val << std::endl;
58       std::free(const_cast<char*>(val));
59       pid_t pid = -1;
60       aul_app_context_get_pid(context, &pid);
61       std::cout << "pid: " << pid << std::endl;
62       aul_app_context_destroy(context);
63     }
64
65     std::cout << "begin: " << app->GetBeginTimestamp() << std::endl;
66     std::cout << "end: " << app->GetEndTimestamp() << std::endl;
67
68     std::cout << "started time: " << app->GetSocketReadyTimestamp()
69               << std::endl;
70
71     std::cout << "termiated time: " << app->GetTerminatedTimestamp()
72               << std::endl;
73
74     std::cout << "requires: ";
75     for (auto& appid : app->RequiresGet())
76       std::cout << appid << " ";
77
78     std::cout << std::endl;
79
80     std::cout << "before: ";
81     for (auto& appid : app->BeforeGet())
82       std::cout << appid << " ";
83
84     std::cout << std::endl;
85
86     std::cout << "after: ";
87     for (auto& appid : app->AfterGet())
88       std::cout << appid << " ";
89
90     std::cout << std::endl;
91
92     std::cout << "conflict: ";
93     for (auto& appid : app->ConflictsGet())
94       std::cout << appid << " ";
95
96     std::cout << std::endl;
97
98     std::cout << "args: {\n";
99     auto& b = app->GetArgs();
100     bundle_foreach(
101         b.GetHandle(),
102         [](const char* key, const int type,
103            const bundle_keyval_t* kv, void* data) {
104           auto& kb = *static_cast<tizen_base::Bundle*>(data);
105           std::cout << key << ": ";
106           switch (type) {
107           case BUNDLE_TYPE_STR:
108             std::cout << kb.GetString(key) << std::endl;
109             break;
110           case BUNDLE_TYPE_STR_ARRAY:
111             std::cout << "[ ";
112             for (auto& val : kb.GetStringArray(key))
113               std::cout << val << ", ";
114
115             std::cout << "]" << std::endl;
116             break;
117           default:
118             break;
119           }
120         },
121         const_cast<tizen_base::Bundle*>(&b));
122     std::cout << "}" << std::endl;
123
124     std::cout << "bg-launch: " << app->IsBackgroundLaunch() << std::endl;
125     return true;
126   }
127
128   std::cerr << "Not found app info." << std::endl;
129   return false;
130 }
131
132 }  // namespace aul