Code Monkey home page Code Monkey logo

ocaml-libmpdclient's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ryanakca yashrk

ocaml-libmpdclient's Issues

Improve the connection with lwt

when the lib is used in a synchrone way, a classical connection works like this:

  • write "mycommand args\n"
  • read "mpd responeOK\n" or "ACK {} ..."

in an asynchrone way:

  • there is a thread with the "idle" command
  • when the noidle command is send (that returns nothing) and then a new command is send, it occurs that the response is like this "OK\nOK\n".

if at this line,

let maxlen = 3 in

the maxlen of the buffer is > 3, the next read will loop and take one "OK\nOK\n" instead of two "OK\n".

It would be better to add a Buffer in the connection record and use bigger maxlen.

Find out all exceptions that could occur and caught them

  • Check all Unix and Lwt_unix functions for uncaugth exception
  • 8733902 -> catch possible exception from Unix.connect

next :

./_build/default/bin/ompdc.exe status -p 20
Connection refused connect 
ompdc: internal error, uncaught exception:
       Unix.Unix_error(Unix.ENOTCONN, "recv", "")

Ompdc fix issue with status command

⟩ ./_build/default/bin/ompdc.exe playback_options --mixrampdelay 1
Mpd server : OK MPD 0.20.0

~/Projets/OCaml/ocaml-libmpdclient · (master±)
⟩ ./_build/default/bin/ompdc.exe status --mixrampdelay
Mpd server : OK MPD 0.20.0

ompdc: internal error, uncaught exception:
       Failure("int_of_string")

Formalize the pattern of the different MPD responses for request

what is the form of the request that is recognized at the Connection level ?
what is the form of the request returned to the Client level ?
what is the form of the request recognized at the Client level ?

Do it both for the non-Lwt and Lwt connexion and client.

Ompdc idle command

Use Notty in order to display information and clean terminal (could be used for futur consol mpd client like ncmpcpp)

create 2 threads and run them with Lwt.join

  • one that redraw frequently the Notty.term
  • one that listen to the mpd events

for the first one thread, implementation idea :

for the second thread how to present data to the first thread ?

  • use a global reference (declare a reference in the global scope ?)
  • does Lwt offerts a way to exchange data between thread ?

Ompdc

Display error message when a command returns an Mpd error response.

Do full testing.

In travis, use docker and install mpd server in order to test all the commands.

  • Connection
  • Client
  • Playback
  • Playback_options

Ompdc idle command

The interface does not seem to redrawn as expected when resize events occur.

Test fails with docker

2 pbs:

In docker the tests for playback fail because the mpd server can not play any songs.
And it can not play because after

  • running an interactive session:
docker run --interactive --tty ocaml-libmpdclient/ubuntu-17.04
  • launching mpd
mpd
Jan 06 17:11 : server_socket: bind to '[::1]:6600' failed: Cannot assign requested address (continuing anyway, because binding to '127.0.0.1:6600' succeeded)
Jan 06 17:11 : errno: Failed to open /home/ocaml-libmpdclient/mpd/tag_cache: No such file or directory
  • loading the bach playlist and check to see if everything is ok:
ocaml-libmpdclient@422228ad13e0:~/ocaml-libmpdclient$ ./_build/default/samples/try_mpd_queries.exe "load bach"
received: OK MPD 0.19.0

received: OK

ocaml-libmpdclient@422228ad13e0:~/ocaml-libmpdclient$ ./_build/default/samples/try_mpd_queries.exe "playlist"
received: OK MPD 0.19.0

received: 0:file: kunst01.mp3
1:file: kunst02.mp3
2:file: kunst03.mp3
3:file: kunst04.mp3
4:file: kunst05.mp3
5:file: kunst06.mp3
6:file: kunst07.mp3
7:file: kunst08.mp3
8:file: kunst09.mp3
9:file: kunst10.mp3
10:file: kunst11.mp3
OK

When I try to play something and check the status:

ocaml-libmpdclient@422228ad13e0:~/ocaml-libmpdclient$ ./_build/default/samples/try_mpd_queries.exe "play"
received: OK MPD 0.19.0

received: OK

ocaml-libmpdclient@422228ad13e0:~/ocaml-libmpdclient$ ./_build/default/samples/try_mpd_queries.exe "status"
received: OK MPD 0.19.0

received: volume: -1
repeat: 0
random: 0
single: 0
consume: 0
playlist: 2
playlistlength: 11
mixrampdb: 0.000000
state: pause
song: 0
songid: 1
time: 0:230
elapsed: 0.000
bitrate: 0
audio: 22050:24:2
error: Failed to open audio output
nextsong: 1
nextsongid: 2
OK
  • Pb n 1 : It seems that the server was not able to open the audio output.
  • Pb n 2 : why the play command returns an OK while in the status there is obviously a pb ?

How to configure mpd ? is the current mpd.conf is enough ? is there any audio ouput in the default docker image ? should I create a dummy audio output (/dev/null)?
How to create a fake audio ouput?

Client_lwt.request issue

cedlemo/rameau#5 (comment)

A request to mpd returns something like "one or multiple lines" + "\nOK\n".

they are identified in https://github.com/cedlemo/OCaml-libmpdclient/blob/master/lib/Connection_lwt.ml#L152

with

let request_response mpd_data =
  let pattern = "\\(\\(\n\\|.\\)*OK\n\\)" in
  check_full_response mpd_data pattern 1 0

more globaly a request is done via https://github.com/cedlemo/OCaml-libmpdclient/blob/master/lib/Client_lwt.ml#L66

let request client cmd =
  let {connection = c; _} = client in
  Connection_lwt.write c (cmd ^ "\n")
  >>= fun _ ->
    Connection_lwt.read_request_response c
    >>= fun response ->
      let parsed_response = Protocol.parse_response response in
      Lwt.return parsed_response

And the request is parsed in order to see if Mpd returned an Error or an Ok response with:
https://github.com/cedlemo/OCaml-libmpdclient/blob/master/lib/Protocol.ml#L81

let parse_response mpd_response =
  let ok_response_reg = Str.regexp "\\(\\(\n\\|.\\)*\\)OK$" in
  if (Str.string_match ok_response_reg mpd_response 0 == true) then
    let str = Str.matched_group 1 mpd_response in
    if str = "" then Ok (None) else Ok (Some str)
  else
    Error (parse_error_response mpd_response)

which means that the response returned by parse_response can possibly have a "\n" at the end which when parsed by Music_database_lwt.list can generate for example an album name like "an_album\n".
This new line char break further request to mpd.

Change Protocol.response signature

from

type response = Ok of string | Error of (ack_error * int * string * string)

to

type response = Ok of string option | Error of (ack_error * int * string * string)

Best way to handle exception in Lwt based api

  1. None / Some

The functions of the API should :

  • when, an exception occurs,

    • print an explicit error message
    • return None with Lwt.return_none
  • on success.

    • return Some

It is then up to the user of the Api to exit with an error code in the thread launched in Lwt_main.run

  1. Create exceptions proper to the library.

The functions of the API should :

  • when, an exception occurs,

    • print an explicit error message
    • throws a libmpd exception with Lwt.fail
    • catch libmpd exceptin in the main thread and exit with an error code
  • on success.

    • return value normaly
  1. Let the user catch all the low level exception in the main thread.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.