From 0d00402231355d6fafd89e555fd66eb835fa3152 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 21 Sep 2021 17:46:29 +0100 Subject: [PATCH] Minor code cleaning re: Messages --- boxstack.cc | 2 +- control.cc | 18 ++++------- message.h | 85 +++++++++++++++++++++++++--------------------------- osdopenvg.cc | 2 +- 4 files changed, 47 insertions(+), 60 deletions(-) diff --git a/boxstack.cc b/boxstack.cc index 248b17e..c5d6d9c 100644 --- a/boxstack.cc +++ b/boxstack.cc @@ -546,7 +546,7 @@ void BoxStack::processMessage(Message* m) { if (boxes[i] == m->to) { - LogNT::getInstance()->debug(TAG, "sending message from box {} to box {} {}", (void*)m->from, (void*)m->to, m->message); + LogNT::getInstance()->debug(TAG, "sending message {} from {} to {}", m->message, (void*)m->from, (void*)m->to); boxes[i]->processMessage(m); return; } diff --git a/control.cc b/control.cc index bfd761f..5bc2888 100644 --- a/control.cc +++ b/control.cc @@ -438,14 +438,9 @@ void Control::run() void Control::processMessage(Message* m) { - // FIXME - a slight modification - how if messagereceivers were to register - // themselves as receivers to avoid the calling-a-deleted-object problem - // then only deliver/register/unregister would have to be protected - logger->debug(TAG, "processing message {}", m->message); - - if ((m->p_to == Message::CONTROL) || (m->to == this)) // Maybe don't check m->to here? Always use predefined? + if (m->p_to == Message::CONTROL) { switch(m->message) { @@ -454,19 +449,14 @@ void Control::processMessage(Message* m) irun = false; break; } - // << FIXME OBSELETE case Message::STOP_PLAYBACK: { handleCommand(Input::STOP); // an odd way of doing it, but so simple break; } - // Also connection_lost comes from player - anywhere else? - // FIXME OBSELETE >> - - case Message::VDR_CONNECTED: { - doJustConnected(static_cast(m->from)); // FIXME delete from here? + doJustConnected(static_cast(m->from)); break; } case Message::SCREENSHOT: @@ -517,6 +507,8 @@ void Control::processMessage(Message* m) } case Message::NEW_PICTURE: { + // FIXME MQSUB + //Log::getInstance()->log("Control", Log::DEBUG, "TVMedia NEW_PICTURE"); OsdVector* osdv = dynamic_cast(Osd::getInstance()); if (osdv) osdv->informPicture(m->tag, reinterpret_cast(m->data)); @@ -628,7 +620,7 @@ void Control::sig1() #ifdef DEV Message* m = new Message(); // break into master mutex m->message = Message::SCREENSHOT; - m->to = this; + m->p_to = Message::CONTROL; postMessage(m); #endif } diff --git a/message.h b/message.h index 9b442f5..1b13703 100644 --- a/message.h +++ b/message.h @@ -22,21 +22,14 @@ #include -//class Message; #include "defines.h" -// Usage of messages is more dubious now that the single master mutex lock -// protects all gui actions. Reason(s) for usage: -// 1. View A wants something to be done by View B *after* View A has been deleted -// 2. A thread wants its object/view deleting *after* the thread has exited - -// Put a justification line after call to Message* m = new Message() line -// So that the sources can be grepped for proper message usage - class Message { public: + // Not using a pre-defined target if one is available is deprecated, and is now essential for CONTROL + enum PreDefinedTarget { NA = 0, @@ -50,46 +43,48 @@ class Message void* from{}; PreDefinedTarget p_to{NA}; // If this is set 'to' is ignored void* to{}; - ULONG message{}; + int message{}; ULONG parameter{}; ULONG tag{}; // use this for identifying which object / question is being replied to void* data{}; // Use this for anything. Int, pointer, pointer to memory to be freed by the recipient, etc. - const static ULONG QUESTION_YES = 1; - const static ULONG CLOSE_ME = 2; - const static ULONG PLAY_SELECTED_RECORDING = 3; - const static ULONG DELETE_SELECTED_RECORDING = 4; - const static ULONG SCREENSHOT = 5; - const static ULONG CHANNEL_CHANGE = 6; - const static ULONG RESUME_SELECTED_RECORDING = 7; - const static ULONG INPUT_EVENT = 8; - const static ULONG STOP_PLAYBACK = 9; - const static ULONG SERVER_SELECTED = 10; - const static ULONG VDR_CONNECTED = 11; - const static ULONG ADD_VIEW = 12; - const static ULONG REDRAW_LANG = 14; - const static ULONG EPG = 16; - const static ULONG CHANGED_OPTIONS = 18; - const static ULONG CONNECTION_LOST = 19; - const static ULONG MOVE_RECORDING = 20; - const static ULONG PLAYER_EVENT = 22; - const static ULONG AUDIO_CHANGE_CHANNEL = 23; - const static ULONG CHILD_CLOSE = 24; - const static ULONG MOUSE_MOVE = 25; - const static ULONG MOUSE_LBDOWN = 26; - const static ULONG CHANGE_LANGUAGE = 27; - const static ULONG LAST_VIEW_CLOSE = 28; - const static ULONG CHANGED_REMOTECONTROL = 29; - const static ULONG DELETE_SELECTED_TIMER = 30; - const static ULONG CHANGED_DEVICEOPTIONS = 31; - const static ULONG TELETEXTUPDATE = 32; - const static ULONG TELETEXTUPDATEFIRSTLINE = 33; - const static ULONG SUBTITLE_CHANGE_CHANNEL = 34; - const static ULONG MOUSE_SCROLL = 35; - const static ULONG NEW_PICTURE = 36; - const static ULONG NEW_PICTURE_STATIC = 37; - const static ULONG REDRAW = 38; - const static ULONG SHUTDOWN = 39; + // Never use the values, only the names + const static int INVALID = 0; + const static int QUESTION_YES = 1; + const static int CLOSE_ME = 2; + const static int PLAY_SELECTED_RECORDING = 3; + const static int DELETE_SELECTED_RECORDING = 4; + const static int SCREENSHOT = 5; + const static int CHANNEL_CHANGE = 6; + const static int RESUME_SELECTED_RECORDING = 7; + const static int INPUT_EVENT = 8; + const static int STOP_PLAYBACK = 9; + const static int SERVER_SELECTED = 10; + const static int VDR_CONNECTED = 11; + const static int ADD_VIEW = 12; + const static int REDRAW_LANG = 14; + const static int EPG = 16; + const static int CHANGED_OPTIONS = 18; + const static int CONNECTION_LOST = 19; + const static int MOVE_RECORDING = 20; + const static int PLAYER_EVENT = 22; + const static int AUDIO_CHANGE_CHANNEL = 23; + const static int CHILD_CLOSE = 24; + const static int MOUSE_MOVE = 25; + const static int MOUSE_LBDOWN = 26; + const static int CHANGE_LANGUAGE = 27; + const static int LAST_VIEW_CLOSE = 28; + const static int CHANGED_REMOTECONTROL = 29; + const static int DELETE_SELECTED_TIMER = 30; + const static int CHANGED_DEVICEOPTIONS = 31; + const static int TELETEXTUPDATE = 32; + const static int TELETEXTUPDATEFIRSTLINE = 33; + const static int SUBTITLE_CHANGE_CHANNEL = 34; + const static int MOUSE_SCROLL = 35; + const static int NEW_PICTURE = 36; + const static int NEW_PICTURE_STATIC = 37; + const static int REDRAW = 38; + const static int SHUTDOWN = 39; }; diff --git a/osdopenvg.cc b/osdopenvg.cc index 9e60663..a53df83 100644 --- a/osdopenvg.cc +++ b/osdopenvg.cc @@ -1448,7 +1448,7 @@ unsigned int OsdOpenVG::handleOpenVGCommand(OpenVGCommand& command) if (info->lindex & 0xffffffff) static_image = false; Message* m = new Message(); - // We have a pictures! send a message to ourself, to switch to gui thread + // We have a pictures! send a message to ourself, to switch to gui thread // FIXME MQSUB m->from = this; m->p_to = Message::CONTROL; m->data = reinterpret_cast(handle); -- 2.39.5