| 80 | } |
| 81 | |
| 82 | int |
| 83 | main(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 |
nothing calls this directly
no test coverage detected