33 #include <Ice/Application.h>
34 #include <Ice/BuiltinSequences.h>
35 #include <Ice/PropertiesF.h>
36 #include <IceUtil/Handle.h>
43 #include "../ArmarXManager.h"
44 #include "../Component.h"
45 #include "../logging/Logging.h"
46 #include "../system/ArmarXDataPath.h"
47 #include "../system/ImportExport.h"
48 #include "../system/cmake/CMakePackageFinder.h"
55 struct InitializationData;
58 #define xstr(s) stringify(s)
59 #define stringify(s) #s
74 class ManagedIceObjectRegistryInterface;
208 template <
class T,
typename... Args>
212 std::unique_lock lock(instanceMutex);
216 throw LocalException(
"Application instance already created");
237 #ifdef ARMARX_VERSION
238 return xstr(ARMARX_VERSION);
247 int run(
int argc,
char* argv[])
override;
255 void setName(
const std::string& name);
262 std::string getName()
const;
269 void interruptCallback(
int signal)
override;
271 void registerDataPathsFromDependencies(std::string dependencies);
278 std::vector<std::string> getArmarXPackageNames();
280 bool isPackageAutoDiscoveryEnabled();
282 static std::string GetArmarXConfigDefaultPath(
bool envVarExpanded =
true);
283 static Ice::StringSeq GetDefaultsPaths();
285 static const std::string& GetProjectName();
286 static const Ice::StringSeq& GetProjectDependencies();
294 void updateIceProperties(
const Ice::PropertyDict& properties)
override;
296 void icePropertiesUpdated(
const std::set<std::string>& changedProperties)
override;
300 bool getForbidThreadCreation()
const;
301 void setForbidThreadCreation(
bool value);
302 void enableLibLoading(
bool enable =
true);
304 void storeCommandLineArguments(
int argc,
char* argv[]);
305 const std::vector<std::string>& getCommandLineArguments()
const;
346 const Ice::InitializationData& initData,
349 void loadDefaultConfig(
int argc,
char* argv[],
const Ice::InitializationData& initData);
351 void loadDependentProjectDatapaths();
360 virtual std::string getDomainName();
383 static void HandlerInterrupt(
int sig);
390 static void HandlerFault(
int sig);
393 void loadLibrariesFromProperties();
403 static std::mutex instanceMutex;
408 std::string applicationName;
417 std::shared_ptr<std::thread> shutdownThread;
419 static std::string ProjectName;
420 static Ice::StringSeq ProjectDependendencies;
423 bool forbidThreadCreation =
false;
424 bool libLoadingEnabled =
false;
426 std::vector<std::string> commandLineArguments;
443 template <
class ComponentT,
class AppT>
455 registry->addObject(Component::create<ComponentT>(properties,
"",
appConfigDomain));
492 template <
class ComponentT,
class AppT = armarx::Application>
497 const std::string& configName =
"",
498 const std::string& configDomain =
"ArmarX",
499 bool enableLibLoading =
false)
502 AppT::template createInstance<internal::SimpleSingleComponentApp<ComponentT, AppT>>();
506 sApp->appConfigDomain = configDomain;
507 sApp->appConfigName = configName;
508 app->enableLibLoading(enableLibLoading);
509 app->setName(appName);
510 app->storeCommandLineArguments(argc, argv);
511 return app->main(argc, argv);
525 std::vector<ComponentPtr> components;
535 registry->addObject(comp);
540 template <
class ComponentType>
541 std::vector<ComponentPtr>
547 template <
class ComponentType,
class... ComponentTypes>
548 std::vector<ComponentPtr>
551 std::vector<ComponentPtr> result{comp};
553 result.insert(result.end(), tempResult.begin(), tempResult.end());
557 template <
class... ComponentTypes>
558 std::vector<ComponentPtr>
561 std::vector<ComponentPtr> result;
563 result.insert(result.end(), tempResult.begin(), tempResult.end());
583 template <
class... ComponentTypes>
584 std::tuple<armarx::ApplicationPtr, std::vector<ComponentPtr>>
588 const std::string& configDomain =
"ArmarX")
591 std::vector<ComponentPtr> comps =
595 app->setName(appName);
596 return std::make_tuple(app, comps);