Mobileread
Smart Device App questions
#1  pazos 05-24-2020, 04:19 PM
Hi. I'm playing a bit with the API of "smart device app" to improve KOReader wirelessly connection with calibre. So far so good but I have a couple of questions related to free space on disk:

1. It seems that the smart device app ignores reported free space. It does not raise FreeSpaceError as indicated in https://github.com/kovidgoyal/calibre/blob/master/src/calibre/devices/interface.py#L389

2. I can live with (1) because calibre reports the length in bytes of each file, so I can compare it with device free space. I don't know if there's a way to tell calibre that one or more specific files were not received by the client.

In the best case scenario I would want the server to report issues like "connect to folder" device is doing (in attachment) but I'm fine if the server doesn't report any error as long as it could report the files already on-device.

This is my first attempt to look at calibre/python code. Please forgive me if I mis something obvious. Also please forgive my english. I hope my question can be understood.
2020-05-24_22-03.png 
Reply 

#2  chaley 05-24-2020, 07:32 PM
It is true that the smart device driver does not raise that exception. It is possible that it could, but I need to look at what the implications are.

I am not sure what question you are asking. It is up to the device to report what files are on the device.
Reply 

#3  pazos 05-25-2020, 08:12 AM
Hi chaley, thanks for your help.

When calibre sends the opcode "SEND_BOOK" I check if the book fits in the device. If it fits then I store it on disk and update my local database accordly.

calibre expects a client response per book. I send an opcode "OK" and no data if the book was stored fine. I would like to know how to notify calibre that a specific book in a batch was not received by the client. I tried to send "NOOP" but calibre thinks the book is on device until I disconnect the client and connect it again.
Reply 

#4  chaley 05-25-2020, 10:02 AM
Quote pazos
Hi chaley, thanks for your help.

When calibre sends the opcode "SEND_BOOK" I check if the book fits in the device. If it fits then I store it on disk and update my local database accordly.

calibre expects a client response per book. I send an opcode "OK" and no data if the book was stored fine. I would like to know how to notify calibre that a specific book in a batch was not received by the client. I tried to send "NOOP" but calibre thinks the book is on device until I disconnect the client and connect it again.
The protocol is weak here. The response to SEND_BOOK is processed before the book is actually sent and there is no way to tell the driver not to send the book. FYI: the response is used to tell calibre the device path (lpath) in case the device changes it.

I have to be very careful about what I change in order to avoid breaking other clients. That said, I can do two things, tested using CC:I have committed the above changes. Once Kovid accepts them then they will be in calibre source for you to test.
Reply 

#5  pazos 05-26-2020, 09:13 AM
Quote chaley
I have committed the above changes. Once Kovid accepts them then they will be in calibre source for you to test.
Thank you!!!

With the sanity check in place everything seems to work just fine. In order to test the user feedback I modified the reported free disk space in response to FREE_SPACE opcode. It works too (attachment #1)

For legacy calibre versions I didn't found a better way to handle no disk space than send all binary data to the void and report a message asking the user for disconnect and connect again (attachment #2). Obviously it would be better if I could manage to send the book count again without reconnecting, but I'm fine with the solution.

Again, thanks for your work!
2020-05-26_15-00.png 2020-05-26_15-07.png 
Reply 

#6  pazos 05-28-2020, 12:41 PM
Another thing I noticed: the wireless server doesn't notify clients when its "ejecting" the drive. It just closes the socket.

It would be amazing to send a new opcode to figure out that the user intention is to disconnect the "disk" and it isn't just a temporarily failure on talking with the server.
Reply 

#7  chaley 05-28-2020, 01:00 PM
Quote pazos
Another thing I noticed: the wireless server doesn't notify clients when its "ejecting" the drive. It just closes the socket.

It would be amazing to send a new opcode to figure out that the user intention is to disconnect the "disk" and it isn't just a temporarily failure on talking with the server.
This one is more difficult because a new opcode coming from calibre could break all the existing clients. We got away with ERROR because calibre never sends it.

What I can do: when calibre tells the device to eject, send a NOOP with an argument {'ejecting': True} just before I close the socket. Existing clients shouldn't break (CC won't). This won't prevent calibre from simply closing the socket sometimes because there are ways for the driver to be shutdown without being told why.

Is this OK? If so I will submit changes.
Reply 

#8  pazos 05-28-2020, 02:32 PM
Quote chaley
This one is more difficult because a new opcode coming from calibre could break all the existing clients. We got away with ERROR because calibre never sends it.

What I can do: when calibre tells the device to eject, send a NOOP with an argument {'ejecting': True} just before I close the socket. Existing clients shouldn't break (CC won't). This won't prevent calibre from simply closing the socket sometimes because there are ways for the driver to be shutdown without being told why.

Is this OK? If so I will submit changes.
Totally OK!

Thank you!!!
Reply 

#9  chaley 05-28-2020, 02:47 PM
Quote pazos
Totally OK!

Thank you!!!
Submitted. Kovid will probably merge the change tomorrow.
Reply 

Today's Posts | Search this Thread | Login | Register