-
Notifications
You must be signed in to change notification settings - Fork 6
DRAFT: Add optional curl usage #11
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
Conversation
|
I think it might be worth making libcurl an optional dependency, i.e. the curl specific code could be in a separate file that gets compiled only if |
|
@EmilioPeJu I think it's a good idea. In order to make that in the less invasive way I can think of I intend to put some class declaration stuff into a header file. I will open another PR for that. |
Also change the DRIVER_MODIFICATION number even though I'm not sure if this should be done since this shouldn't change anything in the driver per se.
Add WITH_CURL compilation option. If compiled with WITH_CURL = YES, CurlUsage.template file will be added and it's records will be created. curl.h will be included. First record - UseCurl - should futurely toggle curl usage in the Driver.
No need to use getIntegerParam in this context if we already have the value argument.
Using this along with to-be-added CURLOPT_PASSWORD would expose credentials in the network. I leave it in the driver as a means to completely express the API functionalities, but there should be better ways of setting your credentials if you mean to. Probably will add a configuration file for that in the future.
Same warning about last commit: this shouldn't be used but it's left here as an option for quick testing and better expressing the API functionalities. For actual credentials usage future records should add a path for a configuration file containing the credentials.
Should be used to load the file contents and put them into the correct parameters. Uses a very similar mechanism from NDFile.template and functions from asynNDArrayDriver. For now it just checks if the file exists and is accessible, but not it's contents.
Add CurlLoadConfig record and loadConfigFile function. loadConfigFile() calls writeInt32 and writeOctet for all parameters it can recognize, except username and password. For those, loadConfigFile() calls curl_easy_setopt without ever setting the parameter value. This means setpoint and RBV values for all parameters can be different, so I add readback values for all records. writeInt32 and writeOctet are called inside loadConfigFile(), which is called inside writeInt32. In my understanding this cannot lead to any infinite loop since CurlLoadConfig record has no "ASYN_" prepending it's name, so it's impossible for it to call writeInt32 on itself. Also, I think this is thread safe because the function is only supposed to be called inside writeInt32, which is supposed to be already locked.
Readbuffer is a char vector just so we can copy all needed bytes to it. writeCallback should simply add stuff to the buffer. readImage clears buffer before adding to it. Unfortunately I think clear cant be called inside writeCallback because it's called more than one time per read.
This is obviously needed and acquisition will fail without this.
WITH_CURL = YES/NO is used to tell the compiler to use or not use curl. I add an example in configure/CONFIG_SITE to make it easy for people to enable/disable this in future.
Curl is added as an option both at compile and at runtime. If compiled with WITH_CURL = YES at configure/CONFIG_SITE.local, curl option will be enabled at runtime but default will still be UseCurl = NO. If record $(P)$(R)UseCurl = YES, then code will get image from URL using libCurl instead of graphicsMagick. Some curlOptions are configurable as records. More can be easily added. The CurlConfigFile.template is based on NDFile.template, but a bit different, so I preferred to create a new one instead of including the one that already exists. Maybe this can be modified in future.
33886ac to
32681b4
Compare
|
@EmilioPeJu I'm closing this pull request since I changed a lot about the overall structure in new branches. Will open a new one afterwards. |
This pull request is a draft with an initial idea about how to improve the usage.
Long story short is: it adds curl as an option (that is, the default operation still uses pure graphicsmagick) to grab the image and pass it as a Blob to GraphicsMagick, but I'm not sure if this is a good design. Another idea would be to simply create another driver (maybe ADCURL?) with just curl functionalities.
If any of these two options make sense, I can keep working on it until it's acceptable for merging. If not, I will close the PR.
Context is: me and Tomasz Brys were trying to integrate a Hikivision Speed Dome camera but were unable to find it's direct image or video stream URL, if there is any available at all. The camera does provide a web service with a video stream, but the url is hidden by some sort of redirection or something that I cannot fully understand. Trying to access it with graphicsmagick didn't work in any way we tried, always yielding:
but curl managed to get the frame.
Since libCurl is fairly easy to manage, we added it to the driver. All curl options that I needed can be accessed as records and it is relatively easy to add new ones if needed. Only the HTTP authentication password and username options are in a TOML file instead of record, in order to not expose the credentials for everyone in the network.
libcurl and toml used documentation:
https://toruniina.github.io/toml11/docs/
https://curl.se/libcurl/c/
A typical acquisition with this module would be something like: