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

Function Start

doc/src/tutorial/dictionaryclient3/Activator.cpp:71–121  ·  view source on GitHub ↗

* Implements BundleActivator::Start(). Creates a service * tracker to monitor dictionary services and starts its "word * checking loop". It will not be able to check any words until * the service tracker finds a dictionary service; any discovered * dictionary service will be automatically used by the client. * It reads words from standard input and chec

Source from the content-addressed store, hash-verified

69 * @param context the bundle context for this bundle.
70 */
71 void
72 Start(BundleContext context)
73 {
74 m_context = context;
75
76 // Create a service tracker to monitor dictionary services.
77 m_tracker = new ServiceTracker<IDictionaryService>(
78 m_context,
79 LDAPFilter(std::string("(&(") + Constants::OBJECTCLASS + "="
80 + us_service_interface_iid<IDictionaryService>() + ")" + "(Language=*))"));
81 m_tracker->Open();
82
83 std::cout << "Enter a blank line to exit." << std::endl;
84
85 // Loop endlessly until the user enters a blank line
86 while (std::cin)
87 {
88 // Ask the user to enter a word.
89 std::cout << "Enter word: ";
90
91 std::string word;
92 std::getline(std::cin, word);
93
94 // Get the selected dictionary, if available.
95 std::shared_ptr<IDictionaryService> dictionary = m_tracker->GetService();
96
97 // If the user entered a blank line, then
98 // exit the loop.
99 if (word.empty())
100 {
101 break;
102 }
103 // If there is no dictionary, then say so.
104 else if (!dictionary)
105 {
106 std::cout << "No dictionary available." << std::endl;
107 }
108 // Otherwise print whether the word is correct or not.
109 else if (dictionary->CheckWord(word))
110 {
111 std::cout << "Correct." << std::endl;
112 }
113 else
114 {
115 std::cout << "Incorrect." << std::endl;
116 }
117 }
118
119 // This automatically closes the tracker
120 delete m_tracker;
121 }
122
123 /**
124 * Implements BundleActivator::Stop(). Does nothing since

Callers

nothing calls this directly

Calls 4

OpenMethod · 0.45
GetServiceMethod · 0.45
emptyMethod · 0.45
CheckWordMethod · 0.45

Tested by

no test coverage detected