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

Question: Why Callbacks instead of a Case Structure in a Message Handling Loop #5

Open
drjdpowell opened this issue Jan 27, 2023 · 8 comments
Labels
question Further information is requested

Comments

@drjdpowell
Copy link

I would have thought that a Queued Message Handler (with a case structure selected by the Message ID) would be a lot more familiar to people. You, instead require Callback VIs for each message. A valid choice, but I think it would be a lot harder for many people to adopt.

@negentropicdev
Copy link
Collaborator

I don't want to lock into a single design pattern or architecture. Plus, I come from a text programming background where things like callbacks, delegates, lambdas, and all sorts of other fun mechanisms run rampant. Yes, a VI wrapper is needed, but with the context you can pass in, you can give the callback a message queue if that's what you want. Or an event reference. Or update a DVR. I use this with all sorts of app architectures and module patterns so I aim for flexibility in allowing any higher layer design patterns.

It's certainly not the most prevalent pattern in LV but why should that be a limiting factor? Teaching teachable people is easy :)

@negentropicdev negentropicdev added the question Further information is requested label Jan 27, 2023
@negentropicdev
Copy link
Collaborator

Another reason with this design, many modules can be supplied with the connection to communicate over and can subscribe to messages on a single connection. Which message handling loop would get the message? One big loop would be needed at the application layer to cover all the reusable libraries? If a library is written to use this implementation, messages can be multiplexed without caring about the rest of the application. All an app needs to do is provide the module with the connections/endpoints to use.

@negentropicdev
Copy link
Collaborator

It would certainly be possible to implement a different messaging layer that directly ties into a QMH pattern. Or a QMH layer on top of the messaging layer.

@drjdpowell
Copy link
Author

drjdpowell commented Jan 30, 2023

Suggestion then:

  1. Have the ability to register a single Callback for all messages. This allows an easy way to adapt your library into an existing massage-based architecture.
  2. Have an example that uses this to pass messages to a message-handling loop. Maybe choose a lightweight framework like the JKI State Machine and show how you can pass messages into it via a User Event. This example would serve as a template for the User to adapt their own existing message-passing methods.

@drjdpowell
Copy link
Author

Actually, maybe get in touch with the DQMH people. That is a widely used framework without a well-developed TCP solution, which uses individually-type messages (User Events) that might match well with your Callbacks.

@negentropicdev negentropicdev transferred this issue from illuminated-g/lv-stream Jan 30, 2023
@negentropicdev
Copy link
Collaborator

  1. I'm hesitant on this because that's not really what this is meant for. If 1. is really desired I would say a different messaging layer could be implemented which I'm more than happy to do. I'd prefer to err on the side of "safety" in that modules only handle external messages that they're expecting, which is normal for nearly any messaging API I've seen whether any host of pubsub systems, SystemLink messages, etc. It also creates a list of clearly defined messages that are expected from external software. It's not really that difficult to setup a string array with a list of expected messages to iterate over and register for and encourages purposeful API design.
  2. I've created Create example of integrating with QMH framework lv-msg-simple-examples#1 to have an example of that created with the QMH project template and look at creating examples for other QMH patterned frameworks.

I'm looking into integrating with DQMH but they already appear to have a Generic Networking Module available though of course that's meant strictly for DQMH module - DQMH module messaging. With my APIs it would be easier to expose web UIs and messaging with other non-DQMH systems so I'm going to get in touch with a few of the consortium people and plan a path forward for this.

@joerghampel
Copy link

HSE's Generic Networking (GenNet) modules were designed around the use case of using a module's API (its request VIs) on one computer but actually executing the functions on another computer. Although GenNet can be used to just communicate between applications, that was not the first use case in mind.

While handy for our own projects, the GenNet modules in their current form are not trivial to use for others, as there is no scripting to a) convert an existing module to a networked one (basically overwriting the DQMH Message Queue class) and b) implement requests and replies in a GenNet compatible way.

It's worth pursuing this idea here and discussing this some more.

@negentropicdev
Copy link
Collaborator

@joerghampel I've started https://github.com/orgs/illuminated-g/discussions/1 to continue the DQMH integration discussion. Probably over this next weekend I'll take a first pass at a web UI for the thermal chamber example and we can have something to start pulling apart.

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

No branches or pull requests

3 participants