29 #include "../ArmarXManager.h"
30 #include "../Component.h"
31 #include "../logging/Logging.h"
32 #include "../system/ArmarXDataPath.h"
33 #include "../system/ImportExport.h"
34 #include "../system/cmake/CMakePackageFinder.h"
43 #include <Ice/Application.h>
44 #include <Ice/BuiltinSequences.h>
45 #include <Ice/PropertiesF.h>
46 #include <IceUtil/Handle.h>
55 struct InitializationData;
58 #define xstr(s) stringify(s)
59 #define stringify(s) #s
74 class ManagedIceObjectRegistryInterface;
194 public Ice::Application,
209 template <
class T,
typename ...Args>
212 std::unique_lock lock(instanceMutex);
216 throw LocalException(
"Application instance already created");
236 #ifdef ARMARX_VERSION
237 return xstr(ARMARX_VERSION);
246 int run(
int argc,
char* argv[])
override;
254 void setName(
const std::string& name);
261 std::string getName()
const;
268 void interruptCallback(
int signal)
override;
270 void registerDataPathsFromDependencies(std::string dependencies);
277 std::vector<std::string> getArmarXPackageNames();
279 bool isPackageAutoDiscoveryEnabled();
281 static std::string GetArmarXConfigDefaultPath(
bool envVarExpanded =
true);
282 static Ice::StringSeq GetDefaultsPaths();
284 static const std::string& GetProjectName();
285 static const Ice::StringSeq& GetProjectDependencies();
293 void updateIceProperties(
const Ice::PropertyDict& properties)
override;
295 void icePropertiesUpdated(
const std::set<std::string>& changedProperties)
override;
299 bool getForbidThreadCreation()
const;
300 void setForbidThreadCreation(
bool value);
301 void enableLibLoading(
bool enable =
true);
303 void storeCommandLineArguments(
int argc,
char* argv[]);
304 const std::vector<std::string>& getCommandLineArguments()
const;
341 int doMain(
int argc,
char* argv[],
const Ice::InitializationData& initData,
Ice::Int i)
override;
343 void loadDefaultConfig(
int argc,
char* argv[],
const Ice::InitializationData& initData);
345 void loadDependentProjectDatapaths();
354 virtual std::string getDomainName();
378 static void HandlerInterrupt(
int sig);
385 static void HandlerFault(
int sig);
389 void loadLibrariesFromProperties();
399 static std::mutex instanceMutex;
404 std::string applicationName;
413 std::shared_ptr<std::thread> shutdownThread;
415 static std::string ProjectName;
416 static Ice::StringSeq ProjectDependendencies;
419 bool forbidThreadCreation =
false;
420 bool libLoadingEnabled =
false;
422 std::vector<std::string> commandLineArguments;
437 template<
class ComponentT,
class AppT>
447 registry->addObject(Component::create<ComponentT>(properties,
"",
appConfigDomain));
484 template<
class ComponentT,
class AppT = armarx::Application>
485 int runSimpleComponentApp(
int argc,
char* argv[], std::string appName,
const std::string& configName =
"",
const std::string& configDomain =
"ArmarX",
bool enableLibLoading =
false)
487 armarx::ApplicationPtr app = AppT::template createInstance<internal::SimpleSingleComponentApp<ComponentT, AppT> >();
490 sApp->appConfigDomain = configDomain;
491 sApp->appConfigName = configName;
492 app->enableLibLoading(enableLibLoading);
493 app->setName(appName);
494 app->storeCommandLineArguments(argc, argv);
495 return app->main(argc, argv);
505 components(components) {}
508 std::vector<ComponentPtr> components;
516 registry->addObject(comp);
521 template<
class ComponentType>
527 template<
class ComponentType,
class... ComponentTypes >
528 std::vector<ComponentPtr>
createComponents(ComponentType comp, ComponentTypes... components)
530 std::vector<ComponentPtr> result {comp};
532 result.insert(result.end(), tempResult.begin(), tempResult.end());
536 template<
class... ComponentTypes >
539 std::vector<ComponentPtr> result;
541 result.insert(result.end(), tempResult.begin(), tempResult.end());
561 template<
class... ComponentTypes >
562 std::tuple<armarx::ApplicationPtr, std::vector<ComponentPtr> >
runMultipleComponentsApp(
int argc,
char* argv[], std::string appName,
const std::string& configDomain =
"ArmarX")
565 std::vector<ComponentPtr> comps =
createComponentsUtil(Component::create<ComponentTypes>(props,
"", configDomain)...);
568 app->setName(appName);
569 return std::make_tuple(app, comps);