-
Notifications
You must be signed in to change notification settings - Fork 3
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
API implementation test with Qt4 #20
Comments
Looks good, device_name is probably a good idea !. Do we really need the wait argument, if we really on a signaling mechanism to handle the result or errors for that matter (as long as they are not handled by exceptions and in that case the calling code needs to handle them) |
I would suggest to keep the wait as an optional argument, because at some point we would use api to communicate between devices. One other question: how such a api construct could be used for both Qt and web versions? Could you please create a similar test in the web version? |
Idealistically at some point we could reach the directory structure like :
|
As I mentioned in the meeting I don't have alot of time to provide an example for the web version right now, Ill try to do my best but I'm not promising anything. The structure of the API is quite similar to what we already use in MXCuBE3. Each UI just needs a layer that routes the incoming calls, HTTP requests, RPC or just function calls to the right API call. The example you have provided could be used in both WEB-UI and QT providing that the right routing mechanism exists. I'm not sure that understand what you mean by communication between devices ?, the API is only meant to be used by the user interface. |
@marcus-oscarsson |
Hm, The idea is to provide an API that is to be used exclusively between the UI and the backend. As such I think its convenient if its a non blocking API. The queue and other components should have well defined APIs that are used internally, or between components within the "core". It would in my opinion be a bit strange to route those internal calls through a layer above the core ? The API could theoretically be extended to include other types of clients, apart from UI's, if that is what you refer to. Such a client could be a workflow like application, but that I think that should be discussed after we have settled the initial API, since it would be extending the scope a bit. |
As you mentioned, the "internal" API of some components will be very similar to the one in the UI-API. Queue, Lims, Processing, are probably such components. Queue is a particularly good example because few of its functions are actually used exclusively internally. Its possible that we at some stage can provide a direct mapping to those components if it completely satisfies the needs of the UI-API. I think its to early to do that today because the current "internal" queue API is not ready for that. Taking time to reflect on what we need from a UI perspective are probably going to give us a better idea if its a good idea to provide such a mapping or not. |
I created branch called api_test in the mxcube: https://github.com/mxcube/mxcube/tree/api_test |
Thanks ! |
I think that each UI or eventually other client that uses the API needs a layer which "bridges" the different technologies / architectures used. The Qt4 UI can simply use the API as it is within the same process as the rest of the MXCuBE core. However, the WEB app and other REST, or other client-server based, solutions needs something that handles the parts that are specific to the technology used. In lack of a better term I would call this a communication layer. The implementation of this layer would be fairly straight forward, for direct function calls, like in Qt4, it would be something in the lines of what @IvarsKarpics have provided above. For MXCuBE 3 or anything using REST one would need to do something like this:
The REST implementation could of course be reused for any application using the REST protocol. This transport layer can be seen as belonging to the UI part of the application while the UI-API would belong more to the server. |
@marcus-oscarsson I guess the questions are 1) if the Qt4 implementation needs a separate communication layer or can call the API layer directly. 2) if we accept that the API layer functions can have additional parameters that are not part of the official API nor supported by the MXCuBE3 communication layer (e.g. 'wait=False'). |
I see,
|
Thanks @marcus-oscarsson for the mx3 example. This is exactly what I was looking for. For me calling methods is straight forward (as you said comes for free). Other question is how to handle signals coming from hardware objects. Should we define sample_changer as a hwobj and reemit signals or there is a better suggestion how to pass data to ui layer? |
Hm, well I think that the same "design" that I described above can be used for signals as well. The signal/event system is dependent on the protocols used, for instance websokets for REST HTTP services and Qt Signals for Qt. So one way would simply be to define which handlers that are needed, like we have done in the proposals, and make sure that they are forwarded to the right place. That would mean that the PyDispatcher signals from the Hardware Objects needs to be "relayed" using the protocol specific event mechanism. See example below
My Qt syntax is a bit rusty but I think it should be something in this direction ... |
Hmm, not sure if this is a best solution because then we strictly define two protocols (socketio and Qt signals). Whats speaks again using the same PyDispatcher signals and use api as a "hardware object"? |
Without having looked at htis in detail: |
We can of course provide a wrapper function like Rasmus suggests, called send_signal or emit that calls the right function depending on "transport". |
Hi all,
I created a mini brick to test the sample changer interface:
In the header of file I have:
from api import sample_changer
api
is a directory containing filesample_changer.py
:We could use beamline-setup as container of all hardware objects. By default
mount_sample
method looks forsample_changer_hwobj
and call related method. I added argumentdevice_name
because it may happen that several sample mount devices are available.What do you think about this?
The text was updated successfully, but these errors were encountered: