#1 Re: Bug Reports » ServiceReference#GetProperty method » 2012-05-08 23:11:38

Makes sense! Thanks smile
I have a some more questions in the pipe line but it will wait until tomorrow, good night!

#2 Bug Reports » ServiceReference#GetProperty method » 2012-05-08 23:03:19

Replies: 2

Hey again,

I am not sure if this is a bug, but the ServiceReference#GetProperty method seems to return properties (at least the ObjectClass property) surrounded with parentheses:

I registered a service under the name "foo" in a separate module, and the following code:

	auto refs = GetModuleContext()->GetServiceReferences("");
	for (auto it = refs.begin(); it != refs.end(); ++it) {
		cout << (*it).GetProperty(ServiceConstants::OBJECTCLASS()) << endl;

outputs "(foo)" rather than "foo".

Bug/no bug?

#3 Re: General Discussions & Feedback » Loading multiple modules » 2012-05-08 23:00:01

Thanks! I had moved to a C-cast because the compiler complained without usBase.h, and I did not think it made a difference besides the fact that it might be more prone to crashes.

I have everything working now.

#4 Re: General Discussions & Feedback » Loading multiple modules » 2012-05-08 17:57:10

Ok, I posted a bit fast sad.

The service is found, but calling dictionaryService->checkWord("Tutorial") doesn't seem to work. Actually I can call any method I define on the service, but if I add a debug trace in the method definition (service- side) it is not displayed, and the result displayed is always some random number.

$ ./build.sh && LD_LIBRARY_PATH="/usr/local/lib" ./testApp 
I'm here!!!
get service ref foo for module MainModule = 1 refs
Dictionary contains 'Tutorial': 99

(I also tried with a method "toUppercase" in DictionaryService and it doesn't work either).

#5 Re: General Discussions & Feedback » Loading multiple modules » 2012-05-08 14:09:17

Hi and thanks! I got it working following your instructions smile.

I'll post a bug report now, but this is a holiday here so I'll be back for more questions probably tomorrow wink.

#6 General Discussions & Feedback » Loading multiple modules » 2012-05-07 19:42:33

Replies: 5
//! [Activator]
#include "DictionaryService.h"

#include <usModuleActivator.h>
#include <usModuleContext.h>
#include <usServiceProperties.h>

// Replace that include with your own base class declaration
#include <usBase.h>

#include <algorithm>
#include <memory>


 * This class implements a module activator that uses the module
 * context to register an English language dictionary service
 * with the C++ Micro Services registry during static initialization
 * of the module. The dictionary service interface is
 * defined in a separate file and is implemented by a nested class.
class US_ABI_LOCAL MyActivator : public ModuleActivator


   * A private inner class that implements a dictionary service;
   * see DictionaryService for details of the service.
  class DictionaryImpl : public Base, public DictionaryService
    // The set of words contained in the dictionary.
    US_UNORDERED_SET_TYPE<std::string> m_dictionary;



     * Implements DictionaryService.checkWord(). Determines
     * if the passed in word is contained in the dictionary.
     * @param word the word to be checked.
     * @return true if the word is in the dictionary,
     *         false otherwise.
    bool checkWord(const std::string& word)
      std::string lword(word);
      std::transform(lword.begin(), lword.end(), lword.begin(), ::tolower);

      return m_dictionary.find(lword) != m_dictionary.end();

  std::auto_ptr<DictionaryImpl> m_dictionaryService;


   * Implements ModuleActivator::Load(). Registers an
   * instance of a dictionary service using the module context;
   * attaches properties to the service that can be queried
   * when performing a service look-up.
   * @param context the context for the module.
  void Load(ModuleContext* context)
	std::cout << "I'm here!!!" << std::endl;
    m_dictionaryService.reset(new DictionaryImpl);
    ServiceProperties props;
    props["Language"] = std::string("English");
    context->RegisterService("foo", m_dictionaryService.get(), props);

   * Implements ModuleActivator::Unload(). Does nothing since
   * the C++ Micro Services library will automatically unregister any registered services.
   * @param context the context for the module.
  void Unload(ModuleContext* /*context*/)
    // NOTE: The service is automatically unregistered


US_EXPORT_MODULE_ACTIVATOR(DictionaryServiceModule, MyActivator)

#include <usModuleInitialization.h>

US_INITIALIZE_MODULE("DictionaryServiceModule", "", "", "1.0.0")

#7 Bug Reports » System install & usConfig » 2012-05-07 17:11:42

Replies: 2


Currently when doing a system install (cmake . && make install) on a *nix system, the usConfig.h file is not copied to /usr/local/include.

Is this planned, i.e are users supposed to copy this file to their own modules, or just an oversight?

#8 Re: General Discussions & Feedback » Running a simple example » 2012-05-07 17:05:57

I had it pinned down to the fact that the activator symbol wasn't found (registering the service immediately in main()) but I did not know about this linking option. It now works perfectly :-).

And yes, a project generator would likely have saved me here.

Thanks a lot!

#9 General Discussions & Feedback » Running a simple example » 2012-05-07 16:04:16

Replies: 2


I am trying to build the Dictionary snippet and run it outside of CppMicroServices' build as an exercice to make an external module.

I can run the executable built by CppMicroServices' build just fine -- and the Dictionary service is found.
Here's the normal output.

$ ./uServices-dictionaryservice 
get service ref DictionaryService/1.0 for module DictionaryServiceModule = 1 refs
Dictionary contains 'Tutorial': 1

Now, I have taken the snippet out and trying to make a very simple build out of it.
Here's my build script:



g++ ${OPTS} -I${US_INCLUDE} -c src/main.cpp -o main.o
g++ -L/usr/local/lib/ main.o -o testApp -lCppMicroServices

It builds just fine, but when running it the Dictionary service is *not* found:

$ LD_LIBRARY_PATH=/usr/local/lib/ ./testApp 
get service ref DictionaryService/1.0 for module DictionaryServiceModule = 0 refs

The Load(ModuleContext*) method of the Activator is not even called (I made sure by adding a log on stdout there).

What am I missing?


#10 Feature Requests » Minimal module template generator » 2012-05-07 15:50:12

Replies: 1

Idea to help getting started quickly:

I think a very useful tool would be a simple module template generator, a bit similar to Maven archetypes.

The generator (a script?) would ask for a module/project name, find Cpp Micro Services' install (or ask the users its location) and generate a CMake build, an activator, and a simple test layout.

I know nothing of CMake (yet) and so I don't think I could help here, but it would definitely be a big help.

Board footer

Powered by FluxBB