TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / application / database.cpp
1 /*
2  * Copyright (C) 2017 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #include "anbox/application/database.h"
19 #include "anbox/application/launcher_storage.h"
20 #include "anbox/system_configuration.h"
21 #include "anbox/logger.h"
22
23 namespace anbox {
24 namespace application {
25 const Database::Item Database::Unknown{};
26
27 Database::Database() :
28   storage_(std::make_shared<LauncherStorage>(SystemConfiguration::instance().application_item_dir())) {}
29
30 Database::~Database() {}
31
32 void Database::store_or_update(const Item &item) {
33   if (!done_reset) {
34     storage_->reset();
35     done_reset = true;
36   }
37   storage_->add_or_update(item);
38   items_[item.package] = item;
39
40   // We don't need to store the icon data anymore at this point as the
41   // launcher is already stored it on the disk.
42   items_[item.package].icon.clear();
43 }
44
45 void Database::remove(const Item &item) {
46   auto iter = items_.find(item.package);
47   if (iter == items_.end())
48     return;
49   storage_->remove(item);
50   items_.erase(iter);
51 }
52
53 const Database::Item& Database::find_by_package(const std::string &package) const {
54   auto iter = items_.find(package);
55   if (iter == items_.end())
56     return Unknown;
57   return iter->second;
58 }
59 }  // namespace application
60 }  // namespace anbox