| 1 |
/* |
| 2 |
* Copyright © 2017 Canonical Ltd. |
| 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 |
* Authors: |
| 17 |
* Ted Gould <[email protected]> |
| 18 |
*/ |
| 19 |
|
| 20 |
#pragma once |
| 21 |
|
| 22 |
#include <list> |
| 23 |
|
| 24 |
#include "config.h" |
| 25 |
|
| 26 |
#include "helper.h" |
| 27 |
#include "jobs-base.h" |
| 28 |
|
| 29 |
namespace lomiri |
| 30 |
{ |
| 31 |
namespace app_launch |
| 32 |
{ |
| 33 |
namespace helper_impls |
| 34 |
{ |
| 35 |
|
| 36 |
/** We really should have put a relationship between Helper::Instance |
| 37 |
and Application::Instance in the API. But to work around that today |
| 38 |
we're just handling it here because the helper interface is a subset |
| 39 |
of what the Application::Instance class provides */ |
| 40 |
class BaseInstance : public Helper::Instance |
| 41 |
{ |
| 42 |
public: |
| 43 |
std::shared_ptr<jobs::instance::Base> impl; |
| 44 |
Helper::Type type_; |
| 45 |
|
| 46 |
BaseInstance(const Helper::Type& type, const std::shared_ptr<jobs::instance::Base>& inst); |
| 47 |
BaseInstance(const Helper::Type& type, const std::shared_ptr<Application::Instance>& inst); |
| 48 |
|
| 49 |
bool isRunning() override; |
| 50 |
void stop() override; |
| 51 |
|
| 52 |
const std::string& getInstanceId() const |
| 53 |
{ |
| 54 |
return impl->getInstanceId(); |
| 55 |
} |
| 56 |
|
| 57 |
const AppID& getAppId() const |
| 58 |
{ |
| 59 |
return impl->getAppId(); |
| 60 |
} |
| 61 |
|
| 62 |
const Helper::Type& getType() const |
| 63 |
{ |
| 64 |
return type_; |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
class Base : public Helper |
| 69 |
{ |
| 70 |
public: |
| 71 |
Base(const Helper::Type& type, const AppID& appid, const std::shared_ptr<Registry::Impl>& registry); |
| 72 |
|
| 73 |
AppID appId() const override; |
| 74 |
|
| 75 |
bool hasInstances() override; |
| 76 |
std::vector<std::shared_ptr<Helper::Instance>> instances() override; |
| 77 |
|
| 78 |
std::shared_ptr<Helper::Instance> launch(std::vector<Helper::URL> urls = {}) override; |
| 79 |
#ifdef LAL_USE_MIRCLIENT |
| 80 |
std::shared_ptr<Helper::Instance> launch(MirPromptSession* session, std::vector<Helper::URL> urls = {}) override; |
| 81 |
#endif |
| 82 |
|
| 83 |
|
| 84 |
std::shared_ptr<Helper::Instance> existingInstance(const std::string& instanceid); |
| 85 |
|
| 86 |
const Helper::Type& getType() const |
| 87 |
{ |
| 88 |
return _type; |
| 89 |
} |
| 90 |
|
| 91 |
private: |
| 92 |
Helper::Type _type; |
| 93 |
AppID _appid; |
| 94 |
std::shared_ptr<Registry::Impl> registry_; |
| 95 |
|
| 96 |
bool isSnapPackage(); |
| 97 |
std::list<std::pair<std::string, std::string>> defaultEnv(); |
| 98 |
}; |
| 99 |
|
| 100 |
} // namespace helper_impl |
| 101 |
} // namespace app_launch |
| 102 |
} // namespace lomiri |