Skip to content

Use JSON for communication with mne_rt_server plugins #5

Closed

Description

@mluessi

I think we should use JSON for communication between the client and the mne_rt_server plugins. An advantage of doing this is that the mne_rt_server itself can just forward the data and doesn't need to know anything about the commands a plugin implements. The implementation on the client (and plugin) side can be very simple, have for example a look at this:

http://code.google.com/p/android-scripting/source/browse/python/ase/android.py

The Android object can send any command Android supports to a remote Android phone. In addition to this, each client should implement a method "describe_methods", which returns a description (also in JSON) of all methods the plugin supports, such that the client can display a human-readable help text (the information is also machine readable, so it can e.g. be used to dynamically generate methods on the client side in Python).

Activity

  1. cpieloth commented on Jan 17, 2013

    @cpieloth
    Contributor

    Copied from: 4bcc4c9

    In my opinion it is not the question if we/you use JSON, XML or String for command type. This is just the data type specification, which you have to implement on both sides (or using a lib). When you define all necessary types and structure, you can parse every command type.
    At the moment the structure is CMD ARG1 ARG2 ... (telnet friendly). I moved/defined all placeholders, types and so in one header file, which you can use in python or C++, too. Of course you have more opportunities with JSON.
    In my opinion the decision stands or falls with the telnet support. Please read the the comment in RTDefaultCommands.h line 41.

  2. mluessi commented on Jan 17, 2013

    @mluessi
    Author

    What is the reason for using telnet? I think for simple commands to the server (~the ones we have now) telnet works, but if you want to add commands with more complex arguments in the future, telnet will be very limiting. The mne_rt_server could just have a telnet command to send a JSON string to the plugin, so you can still use a telnet client for simple commands.

    I don't think it is a good design that the client needs to know at compile time what commands all the plugins support. It could be possible to not have this requirement and still use telnet, but then the plugin would have to be able to return a help text that specifies all the functions and data types of the arguments. For complex commands with many arguments (what if ARG1 is an array?) you will end up with a JSON-style format, so it is in my opinion better to just use that from the start.

  3. cpieloth commented on Jan 17, 2013

    @cpieloth
    Contributor

    JSON vs. telnet:
    I don't need telnet ;-) Chris mentioned it. I completely agree with your thoughts about complex arguments (like I wrote before). So I would prefer JSON, too.

    Header files/Library support:
    Even though the use of header files, the client do not have to know the plugin commands at compile time, because you can still ship the plugin as a shared library (as intended)! It is just a "good practice" when you (can) provide them. Imagine you want to integrate a specific plugin in a static way e.g. a GUI with a predefined form, combo box and so on. Additionally you can provide a JSON-to-Object mapping for C++ integration, because the maintainer of the plugin must implement some interfaces (e.g. RequestObject, ResponseObject) for the server anyway.
    Of course, if you only use a print to console, there is no reason for this.

  4. chdinh commented on Jan 17, 2013

    @chdinh
    Member

    Christof and I had this discussion on monday, we thought its good to have one central command register. But after thinking about the concept of having this very generic plugin environment I've to agree with Martin "I don't think it is a good design that the client needs to know at compile time what commands all the plugins support."
    So when we design our rtprotocol lib it should be much more generic with no command definition. Command list should be generated in runtime.

    I think having this telnet ability is very convenient to control basic functionality or just to monitor what's going on.
    In the neuromag system you have a instruction MONI ON then every instruction is mirrored to the telnet.

    JSON vs telnet - I think we shouldn't think of vs. we can support both.
    Telnet if we think of single command than its fine, but when we want to send a bunch of commands than we should use JSON. Also its easy to distinguish between these two protocols JSON starts always with { and ends with }.

    @Christof What do we think of building with rtprotocoll more an rt protocol parser than a rtprotocoll definition?

  5. mluessi commented on Jan 17, 2013

    @mluessi
    Author

    It seems we all agree on JSON for complex commands so let's go for that.

    JSON vs telnet - I think we shouldn't think of vs. we can support both.

    Yes, can we just implement a "JSON_PLUGIN_COMMAND" in telnet? It would just be one of the telnet commands mne_rt_server supports with a single argument, which is the JSON sting (is there a limitation on the max string length imposed by telnet? If so we would have to do something else).

    Also, I agree with @Christof said about header files above. The plugin will be C++, so it can have a header/library with the commands it supports. If the client is written in C++ as well it can directly use that (e.g. for GUIs etc). But for scripting languages (e.g. Python) this wouldn't be necessary, as the client can query what methods are supported at run time.

  6. added a commit that references this issue on Jan 20, 2014
  7. cpieloth commented on Feb 14, 2014

    @cpieloth
    Contributor

    Can this ticket be closed?

  8. chdinh commented on Feb 19, 2014

    @chdinh
    Member

    @cpieloth you're right - thx!

  9. added a commit that references this issue on Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions