Application.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Dennis Weigelt
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
26#pragma once
27
28#include <atomic>
29#include <filesystem>
30#include <memory>
31#include <mutex>
32#include <string>
33
36
38{
39 using PropertyEnabledMap = std::map<std::string, bool>;
40
41 /**
42 * @class Application
43 * @ingroup data_structure
44 * @brief Class containing data about an application
45 * Provides methods to get and set the date contained in the application. It doesn't manage the application
46 * therefore changes in this class won't synchronize to the actual configuration files.
47 */
49 {
50
51 private:
52 std::string name; /// pretty name of the app
53 std::string executableName; /// name of the executable
54 std::filesystem::path executablePath; /// directory where the app resides
55 std::string packageName;
56 /// Refreshed by updateFound(), read from the GUI thread on every status refresh.
57 std::atomic<bool> found;
58
59 protected:
60 /**
61 * Guards `properties`, `enabledMap` and `defaultMap`.
62 *
63 * An application's properties are (re)loaded by the lifecycle worker that starts it while
64 * the GUI thread may be displaying them. The lock is deliberately held only around the
65 * pointer swap and the map accesses, never around parsing or around generating the property
66 * xml - those take seconds and would freeze the GUI. load() therefore builds a complete new
67 * container outside the lock and swaps it in, and getProperties() hands out a shared_ptr
68 * copy, so a reader keeps a consistent snapshot even if a new one is swapped in meanwhile.
69 */
70 mutable std::mutex propertiesMutex;
74
75 public:
76 /**
77 * Constructor that sets the name and the path to the executable of the application.
78 * @param name name of the application
79 * @param executablePath path to the binary executable of the application
80 */
81 Application(std::string name, std::string executablePath, std::string packageName);
82
83 /**
84 * Copy constructor
85 * @param name name of the application
86 * @param executablePath path to the binary executable of the application
87 */
89
90 /**
91 * @return the name of this application
92 */
93 std::string getName();
94
95 /**
96 * @return the name of executable of this application
97 */
98 std::string getExecutableName();
99
100 /**
101 * @return the absolute path to the executable of this application
102 */
103 std::string getExecutableAbsPath();
104
105 /**
106 * @return the path to the executable file of this application
107 */
108 std::string getPathToExecutable();
109
110 std::string getPackageName();
111
112 bool isDefaultPropertyEnabled(std::string name);
113 void setDefaultPropertyEnabled(std::string name, bool enabled);
114
115 bool isDefaultProperty(std::string name);
116 void setIsDefaultProperty(std::string name, bool defaultValue);
117
118 /**
119 * @return the properties of this application
120 **/
122
123 /**
124 * Sets the properties of this application. These properties (along with the
125 * default config) define the behaviour of the application on start.
126 * @param properties new properties
127 */
129
130 /**
131 * @return whether the executable existed the last time updateFound() ran.
132 *
133 * Deliberately does not hit the file system: this is read for every application on every
134 * status refresh of the GUI, and on a network mounted workspace the stat() calls alone
135 * were enough to stall the GUI thread. Call updateFound() to refresh it.
136 */
137 bool getFound();
138
139 /**
140 * Checks whether the executable exists and caches the result for getFound().
141 * Involves a stat(), so avoid calling it from the GUI thread in a loop.
142 */
143 void updateFound();
144 };
145
146 using ApplicationPtr = std::shared_ptr<Application>;
147 using ApplicationVectorPtr = std::shared_ptr<std::vector<ApplicationPtr>>;
148} // namespace ScenarioManager::Data_Structure
void setProperties(armarx::PropertyDefinitionsPtr properties)
Sets the properties of this application.
std::mutex propertiesMutex
Guards properties, enabledMap and defaultMap.
Definition Application.h:70
void setDefaultPropertyEnabled(std::string name, bool enabled)
armarx::PropertyDefinitionsPtr properties
Definition Application.h:71
Application(std::string name, std::string executablePath, std::string packageName)
Constructor that sets the name and the path to the executable of the application.
void updateFound()
Checks whether the executable exists and caches the result for getFound().
void setIsDefaultProperty(std::string name, bool defaultValue)
armarx::PropertyDefinitionsPtr getProperties()
std::shared_ptr< Application > ApplicationPtr
std::map< std::string, bool > PropertyEnabledMap
Definition Application.h:39
std::shared_ptr< std::vector< ApplicationPtr > > ApplicationVectorPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.