Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java like annotation system in respect to OSGi standard #333

Open
al-sabr opened this issue Mar 27, 2019 · 5 comments
Open

Java like annotation system in respect to OSGi standard #333

al-sabr opened this issue Mar 27, 2019 · 5 comments

Comments

@al-sabr
Copy link

al-sabr commented Mar 27, 2019

Greetings again!

I'm creating this thread to move away a discussion we started on a previous ticket here #329 (comment)

I think that using an external tool for metadata embedding is not necessary from my point of view. Coming from the Java world we are using @annotations syntax on classes or member functions within classes.

This is an example of OSGi annotation embedding in Java:

@Reference(
  target = "(javax.portlet.name=" + NotificationsPortletKeys.NOTIFICATIONS + ")",
  unbind = "-"
)
protected void setPanelApp(PanelApp panelApp) {
  _panelApp = panelApp;
}

You can find more reading the blog post where I found the example: https://community.liferay.com/blogs/-/blogs/liferay-osgi-annotations-what-they-are-and-when-to-use-them

What would be the best is to use the same kind of alternative for C++. I was looking around trying to check if it is possible to use Reflection, Serialization, Annotations with C++11 standard and I found that it is possible. So there is a way to transpose the Java annotation standard to C++ with https://github.com/cpgf/cpgf.

The documentation is here : https://github.com/cpgf/cpgf/blob/master/doc/index.md

Introduction to reflection like in Java : https://github.com/cpgf/cpgf/blob/master/doc/introduction-reflection.md

The metadata principle and its documentation is really good : https://github.com/cpgf/cpgf/blob/master/doc/reflection-using-meta-data-lib.md

What do you think of that?

Based on : https://github.com/cpgf/cpgf/blob/master/doc/reflection-build-meta-data.md#define-meta-classes it seems to be really easy.

class Animal
{
};

class Cat : public Animal
{
};

GDefineMetaClass<Animal>
    ::define("Animal")
    ._field(blah blah)
    ._method(blah blah)
;

GDefineMetaClass<Cat, Animal>
    ::define("Cat")
    ._field(blah blah)
    ._method(blah blah)
;
@al-sabr
Copy link
Author

al-sabr commented Mar 27, 2019

@saschazelzer answered

Please move this discussion to a separate issue, not mixing it with the vcpkg topic here. Also, make sure you read http://docs.cppmicroservices.org/en/stable/framework/doc/resources.html to better understand the requirements for our resources system. Especially, it is not onyl about meta-data, but also embedding arbitrary binary data up to 2GB in size. Any embedded data also needs to be accessible without loading the library which embeds them.

@al-sabr
Copy link
Author

al-sabr commented Mar 27, 2019

On windows it is possible to include resources inside of a DLL with this mechanism: https://mklimenko.github.io/english/2018/06/23/embed-resources-msvc/

I'm asuming that on each OS Platform the same kind of resource embedding is available. Why isn't it abstracted and used in the API so that we don't need to rely to external tools?

I think that the resources can be parsed without the need to load the DLL upfront via the win32 API.

@saschazelzer
Copy link
Member

I do value a good discussion about design decisions, but I am not sure what problem you are trying to solve here.

We do not support annotations at all, so this would be a new feature where we have no real use case for currently (maybe for declarative services in the future).

Our resource system embeds arbitrary data, where only some special fiiles following a naming convention happen to contain meta-data about a bundle. We did do our homework and evaluated different approaches - the Win32 API and objcopy being among them. In the end, we would still have to build infrastructure around those tools / APIs, creating still another command line tool. And in fact we do use the underlying techniques which those tools use too (e.g. putting binary blobs in special sections inside the object files). By the way, rc.exe (for the Windows resources system) and objcopy are also external tools, albeit typically part of a development environment already.

So can you please elaborate on the problems you are encountering with the current system?

@al-sabr
Copy link
Author

al-sabr commented Mar 28, 2019

I appreciate your answer and I would like to specify that I'm not trying to solve any actual problem other then the vcpkg port of CppMicroservices. I was thinking that we should follow on the steps from what Apache Felix came up with in case that we want to start to use reflection and annotations in the future to really get rid of boiler plate code when it comes to fetching services from the service registry or when we register new ones. I thought that instead of externalizing toolings we could in the future take inspiration from Bndtools who takes the responsibility for all dependency resolving, metadata embedding in manifest and also resources embedding within Visual Studio or any IDE that support plugins.

I would like to start to contribute in this project but unfortunately I didn't code C++ for more than 10 years now. I have to update my knowledge in order to feel comfortable with all the project structure of CppMs.

I'm not well familiar with the usResourceCompile tool and its decision design yet but I will study it.

This is what I am using when doing OSGi in Java : https://www.youtube.com/watch?v=xNjuXMl9wPk I hope that the video help to clarify where I am coming from.

It is possible to embed resources with Bndtools directly inside of the output jar. The OSGi framework recognizes that and add it automatically in the class path of the bundle. There is also fragment bundles which can only contain embedded resources, html pages, js scripts and they hook themselve to their host Bundle. Fragment bundles cannot contain bytecode or classes.

@al-sabr
Copy link
Author

al-sabr commented Apr 1, 2019

This is would bring Dependency Injection and we would not need anymore to use the service registry manually to fetch or register services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants