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