Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Universal Declarative Services - Simon Chemouil

278 views

Published on

OSGi Community Event 2012

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Universal Declarative Services - Simon Chemouil

  1. 1. Motivation Implementation Going Universal Summary Universal Declarative Services A component framework for C++ and a model-driven solution to polyglot components Simon Chemouil 1 1Global Vision Systems OSGi Community Event, 2012 Simon Chemouil Universal Declarative Services
  2. 2. Motivation Implementation Going Universal Summary Who am I? Free Software enthusiast, functional programmer, interested in model-driven development, modularity, re-usability, maintainability. . . How to never have to write that piece of software again? Technical Architect at Global Vision Systems, Toulouse We create data visualization software for large industries (2D, 3D, tables, etc). We do both Java and C++ Java using OSGi (Felix, iPojo) for server and client side (Eclipse RCP and Android) C++ to keep a fast 3D engine-agnostic manipulation layer Simon Chemouil Universal Declarative Services
  3. 3. Motivation Implementation Going Universal Summary Outline 1 Motivation The case for modularity Service Components and C++ 2 Implementing Declarative Services for C++ Challenges in C++ Dening components 3 Going Universal Simpler Component Denitions What's next? 4 Summary Conclusion Simon Chemouil Universal Declarative Services
  4. 4. Motivation Implementation Going Universal Summary Why modularity? Service Components Native OSGi Did you miss Native-OSGi, Modular Software Development in a Native world by Alexander Broekhuis and Sascha Zelzer? Universal OSGi an RFP and a blog post by Peter Kriens in 2007. Apply OSGi techniques to native (C/C++) development. Simon Chemouil Universal Declarative Services
  5. 5. Motivation Implementation Going Universal Summary Why modularity? Service Components An OSGi Architect Walks in a C++ Bar... Our C++ project going through re-architecture / refactoring Custom-made plugin system, limited. Plugins can't use each other C/C++ OSGi ports: Celix (Alexander), CppMicroServices (Sascha), SOF, CTK, nOSGi, . . . Yet no service component framework such as Declarative Services Simon Chemouil Universal Declarative Services
  6. 6. Motivation Implementation Going Universal Summary Why modularity? Service Components Why a Service Component Framework? Services: powerful primitives, unpractical programming: Lack of structure Dynamic Service Components: Structure the services A nice semantic model to reason about dynamism Why is there no such framework for an OSGi C++ port: 1 Technical challenges 2 It was just not done yet! Simon Chemouil Universal Declarative Services
  7. 7. Motivation Implementation Going Universal Summary Why modularity? Service Components Why Declarative Services? Many existing component frameworks for C++ Just as there were some for Java before DS No modularity Simple and matured component model A few years of personal experience Works with POJOs (or POCOs!) Components do not depend on the framework Makes them testable and easily reusable! Simon Chemouil Universal Declarative Services
  8. 8. Motivation Implementation Going Universal Summary Why modularity? Service Components Does it make sense for C++? We use C++ for performance: Performance hit with component frameworks? We need extensibility and customization... Do we need modularity? Why use dierent architecture between Java and C++? What if we could talk about components, whatever the implementation language? Simon Chemouil Universal Declarative Services
  9. 9. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Getting started Native OSGi implementation: CppMicroServices is light, works with any shared library Inspired by PojoSR For C++! Bundles are called Modules: Native shared libraries: not archives. Moving to NativeOSGi later? Easy! Components are framework-agnostic! Simon Chemouil Universal Declarative Services
  10. 10. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Ingredients in Declarative Services Components are described in XML les in the bundle Service callbacks Dened in description Service arrival/departure Policy, Cardinality, Target Component callbacks Activation, modication, deactivation Simon Chemouil Universal Declarative Services
  11. 11. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Component Descriptions in C++ XML descriptions. . . We have native shared libraries, not JARs! Instead, we register a ComponentDescriptor instance to the ComponentManager service. The ComponentManager service is provided by the core Ds4Cpp framework. Simon Chemouil Universal Declarative Services
  12. 12. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Component Descriptions in C++ Denition class C o m p o n e n t D e s c r i p t o r { public : const s t r i n g c o m p o n e n t I d ; const s t r i n g i m p l S h a r e d O b j e c t ; const v e c t o r s t r i n g ∗ p r o v i d e d S e r v i c e s ; v e c t o r C omponent Reference ∗ r e f e r e n c e s ; const bool i m m e d i a t e ; const bool a u t o E n a b l e ; } ; Simon Chemouil Universal Declarative Services
  13. 13. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Component Descriptions in C++ Let's see how it looks like in practice. . . Simon Chemouil Universal Declarative Services
  14. 14. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Extensible Hello World! Simon Chemouil Universal Declarative Services
  15. 15. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Component Descriptions in C++ Denition std : : vector ComponentReference ∗ r e f e r e n c e s = . . . ; references −push_back ( ComponentReference (greetdemo : : GreetProvider , greetdemo : : GreetProvider , std : : s t r i n g () , ComponentReference : : DYNAMIC, ComponentReference : : MULTIPLE, ComponentReference : : OPTIONAL_REF) ) ; std : : vector std : : string s e r v i c e s ; s e r v i c e s . push_back (greetdemo : : GreetManager) ; ComponentDescriptor ∗ componentDesc = new ds4cpp : : ComponentDescriptor ( greetdemo : : GreetManagerImpl , , s e r v i c e s , ∗ references , true , true ) ; Simon Chemouil Universal Declarative Services
  16. 16. Motivation Implementation Going Universal Summary Challenges in C++ Dening components A Component in C++ Denition c l a s s GreetManagerImpl : p u b l i c GreetManager { p u b l i c : GreetManagerImpl () ; v i r t u a l ~GreetManagerImpl () ; void a c t i v a t e () ; void addGreetProvider ( GreetProvider ∗) ; void removeGreetProvider ( GreetProvider ∗) ; // S e r v i c e m e t h o d s . s t r i n g getDefaultTarget ( const s t r i n g ) const ; s t r i n g getGreeting ( const s t r i n g , const s t r i n g ) const ; l i s t string g e t A l l G r e e t i n g s ( const s t r i n g ) const ; l i s t string getAvailableLanguages () const ; }; Simon Chemouil Universal Declarative Services
  17. 17. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Service Callbacks in C++ (1/2) No reection/introspection! There are some limited libraries (e.g Reex). C++ name mangling We can't guess the binary name Instead, we force a convention in the C++ component: setRefName, unsetRefName for single dependencies addRefName, removeRefName for multiple dependencies Simon Chemouil Universal Declarative Services
  18. 18. Motivation Implementation Going Universal Summary Challenges in C++ Dening components Service Callbacks in C++ (2/2) Our tools: dlopen/dlsym/dlclose (and Windows equivalents) Against us: C++ name mangling Solutions? Reection libraries: too limited, not dynamic. C++11 attributes (≈ Java annotations): still largely unsupported Qt meta-objects? Not bad! Yet need a custom preprocessor Still not modular (work in progress) How about C wrappers? Dicult to write manually, but provide universal ABI! Simon Chemouil Universal Declarative Services
  19. 19. Motivation Implementation Going Universal Summary Challenges in C++ Dening components C Wrapper Denition extern C { DS_ABI_EXPORT GreetManagerImplWrapper∗ __greetdemo__GreetManagerImpl__create () { return new GreetManagerImplWrapper ; } DS_ABI_EXPORT void __greetdemo__GreetManagerImpl__activate ( GreetManagerImplWrapper∗ object ) { object −a c t i v a t e () ; } DS_ABI_EXPORT void __greetdemo__GreetManagerImpl__add_greetdemo__GreetProvider ( GreetManagerImplWrapper∗ object , : : us : : Base ∗ s e r v i c e ) { greetdemo : : GreetProvider ∗ l s e r v i c e = dynamic_castgreetdemo : : GreetProvider ∗( s e r v i c e ) ; object −addGreetProvider ( l s e r v i c e ) ; } DS_ABI_EXPORT void __greetdemo__GreetManagerImpl__remove_greetdemo__GreetProvider ( GreetManagerImplWrapper∗ object , : : us : : Base ∗ s e r v i c e ) { greetdemo : : GreetProvider ∗ l s e r v i c e = dynamic_castgreetdemo : : GreetProvider ∗( s e r v i c e ) ; object −removeGreetProvider ( l s e r v i c e ) ; } } // extern C Simon Chemouil Universal Declarative Services
  20. 20. Motivation Implementation Going Universal Summary Challenges in C++ Dening components It works! But. . . The proof-of-concept is successful: We have components wired dynamically OSGi's patterns work nicely (yet a bit more tricky) We support the use cases we need Dynamic arrival, thread-safety planned but unnished, service removal to do. But no one would write that wrapper code! Are there solutions to help us here? Simon Chemouil Universal Declarative Services
  21. 21. Demo Time!
  22. 22. Motivation Implementation Going Universal Summary Simpler Component Denitions What's next? C++ is too complex! Automatically generating the wrappers? Where to get the description? Macros? Parsing C++?! Xtext Java tooling to dene DSLs and compilers Generates an Eclipse editor! Uses EMF as backend, so more can be built upon. Simon Chemouil Universal Declarative Services
  23. 23. Motivation Implementation Going Universal Summary Simpler Component Denitions What's next? Back to GreetManagerImpl! Denition component g r e e t d e m o . G r e e t M a n a g e r I m p l { provides { g r e e t d e m o . G r e e t M a n a g e r } references { dynamic service g r e e t d e m o . G r e e t P r o v i d e r [ 0 . . n ] } } Simon Chemouil Universal Declarative Services
  24. 24. Motivation Implementation Going Universal Summary Simpler Component Denitions What's next? Dening multiple components Denition module DSDemo { name = DS G r e e t Demo version = 1 . 0 . 0 includes { g r e e t d e m o . E n g l i s h G r e e t P r o v i d e r g r e e t d e m o . F r e n c h G r e e t P r o v i d e r g r e e t d e m o . G r e e t M a n a g e r I m p l g r e e t d e m o . C o n s o l e G r e e t e r } } Simon Chemouil Universal Declarative Services
  25. 25. Generating C++ code
  26. 26. Demo Time!
  27. 27. Motivation Implementation Going Universal Summary Simpler Component Denitions What's next? Improving our ADL The ADL we designed maps to Declarative Services' capabilities What about richer component models? Creating new target language back-ends Java/DS, Java/iPojo Making it extensible Simon Chemouil Universal Declarative Services
  28. 28. Motivation Implementation Going Universal Summary Simpler Component Denitions What's next? Bridging Java and C++ Using Remote OSGi Services: An idea discussed in NativeOSGi. We expose C++ services where we can generate a Java interface Use JNI/JNA bindings or network. Basically, we bridge the two service registries! It does sound like CORBA Simon Chemouil Universal Declarative Services
  29. 29. Motivation Implementation Going Universal Summary Simpler Component Denitions What's next? Creating UI Tools Textual DSLs are nice... But component diagrams are nicer! Up-to-date component metadata is extremely useful: Forces high-level design (round-trips between architects and developers) Allows code generation/rapid project bootstrapping Static analysis (code conformance) Can be used for SDK documentation. Long term project! Simon Chemouil Universal Declarative Services
  30. 30. Motivation Implementation Going Universal Summary Conclusion Declarative Services for C++ We have been using Ds4Cpp for a few months! If you want to try it. . . you can! We just open sourced it (Apache Software License 2.0) https://github.com/Global-Vision-Systems/Ds4Cpp (the demo is packaged with it)! We need testers and eyes to x my bad C++ :-) And remove the limitations (talk to me!) Simon Chemouil Universal Declarative Services
  31. 31. Motivation Implementation Going Universal Summary Conclusion Universal Components Tooling The tooling has still some rough edges Enough for our current needs. . . Some clean-up required. We have a roadmap for the improvements. Simon Chemouil Universal Declarative Services
  32. 32. Motivation Implementation Going Universal Summary Conclusion Universal Declarative Services Questions? Twitter: @simach simon.chemouil@global-vision-systems.com Simon Chemouil Universal Declarative Services

×