Message queue

The music player opens a message queue to communicate with the Juke_Box custom server using the function in jb_shared.c. The Juke_Box custom server and the music player can both send messages to, and receive messages from each other.

When the music player is initialized, either successfully or unsuccessfully, it sends the message Q_MSG_TYPE_INITIALIZED to the Juke_Box custom server.

The music player sends the message Q_MSG_TYPE_EXITING to the Juke_Box custom server before terminating. It sends this message even if initialization failed, or the rest of the music player process was not executed.

The Juke_Box custom server can send the message Q_MSG_TYPE_TERMINATE to the music player at any time. The music player releases any resources it is using and terminates.

When a music player terminates, the Juke_Box custom server receives SIGCHLD signals. The Juke_Box custom server knows which music player has terminated, and cleans up its own internal data structures.

Messages sent to the music player by the Juke_Box custom server

Q_MSG_TYPE_TERMINATE
When this message is received, the music player releases any resources it is using, sends a message Q_MSG_TYPE_EXITING to the Juke_Box custom server, and terminates.

Messages sent to the Juke_Box custom server by the music player

Q_MSG_TYPE_INITIALIZED
If initialization is successful the code sent with this message is 0, if it is unsuccessful, the code sent is non-zero.
Q_MSG_TYPE_EXITING
The music player sends this message to the Juke_Box custom server when it is about to end. This is either in response to a Q_MSG_TYPE_TERMINATE message from the Juke_Box custom server or indicates a failure in the music player. A return code is also sent indicating the reason for the music player ending.