MCPcopy Create free account
hub / github.com/CppMicroServices/CppMicroServices / main

Function main

doc/src/tutorial/driver/main.cpp:82–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82int
83main(int /*argc*/, char** /*argv*/)
84{
85 char cmd[256];
86
87 std::unordered_map<std::string, long> symbolicNameToId;
88
89 FrameworkFactory factory;
90 auto framework = factory.NewFramework();
91
92 auto get_bundle = [&framework, &symbolicNameToId](std::string const& str)
93 {
94 std::stringstream ss(str);
95
96 long int id = -1;
97 ss >> id;
98 if (!ss)
99 {
100 id = -1;
101 auto it = symbolicNameToId.find(str);
102 if (it != symbolicNameToId.end())
103 {
104 id = it->second;
105 }
106 }
107
108 return framework.GetBundleContext().GetBundle(id);
109 };
110
111 try
112 {
113 framework.Start();
114
115 /* install all available bundles for this example */
116#if defined(US_BUILD_SHARED_LIBS)
117 for (auto name : GetExampleBundles())
118 {
119 framework.GetBundleContext().InstallBundles(BUNDLE_PATH + PATH_SEPARATOR + US_LIB_PREFIX + name
120 + US_LIB_POSTFIX + US_LIB_EXT);
121 }
122#endif
123
124 for (auto b : framework.GetBundleContext().GetBundles())
125 {
126 symbolicNameToId[b.GetSymbolicName()] = b.GetBundleId();
127 }
128 }
129 catch (std::exception const& e)
130 {
131 std::cerr << e.what() << std::endl;
132 return 1;
133 }
134
135 std::cout << "> ";
136 while (std::cin.getline(cmd, sizeof(cmd)))
137 {
138 /*
139 The user can stop the framework and we handle this like

Callers

nothing calls this directly

Calls 15

GetExampleBundlesFunction · 0.85
NewFrameworkMethod · 0.80
InstallBundlesMethod · 0.80
GetSymbolicNameMethod · 0.80
findMethod · 0.45
endMethod · 0.45
GetBundleMethod · 0.45
GetBundleContextMethod · 0.45
StartMethod · 0.45
GetBundlesMethod · 0.45
GetBundleIdMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected