22 #include "mythprotoevent.h" 23 #include "../private/debug.h" 24 #include "../private/socket.h" 25 #include "../private/os/threads/mutex.h" 26 #include "../private/builtin.h" 34 void __tokenize(
const std::string& str,
const char *delimiters, std::vector<std::string>& tokens,
bool trimnull =
false)
36 std::string::size_type pa = 0, pb = 0;
39 while ((pb = str.find_first_of(delimiters, pb)) != std::string::npos && ++n < 255)
41 tokens.push_back(str.substr(pa, pb - pa));
46 while (trimnull && str.find_first_of(delimiters, pb) == pb);
48 tokens.push_back(str.substr(pa));
56 ProtoEvent::ProtoEvent(
const std::string& server,
unsigned port)
61 bool ProtoEvent::Open()
65 if (!OpenConnection(PROTO_EVENT_RCVBUF))
68 if (m_protoVersion >= 75)
77 void ProtoEvent::Close()
84 bool ProtoEvent::Announce75()
86 OS::CLockGuard lock(*m_mutex);
88 std::string cmd(
"ANN Monitor ");
89 cmd.append(m_socket->GetMyHostName()).append(
" 1");
90 if (!SendCommand(cmd.c_str()))
94 if (!
ReadField(field) || !IsMessageOK(field))
103 SignalStatusPtr ProtoEvent::RcvSignalStatus()
109 std::vector<std::string> tokens;
111 __tokenize(field,
" ", tokens,
false);
113 if (tokens.size() > 1)
116 if (tokens[0] ==
"slock")
117 signal->lock = (tokens[1] ==
"1" ? true :
false);
118 else if (tokens[0] ==
"signal")
119 signal->signal = (0 == string_to_int64(tokens[1].c_str(), &tmpi) ? (int)tmpi : 0);
120 else if (tokens[0] ==
"snr")
121 signal->snr = (0 == string_to_int64(tokens[1].c_str(), &tmpi) ? (int)tmpi : 0);
122 else if (tokens[0] ==
"ber")
123 signal->ber = (0 == string_to_int64(tokens[1].c_str(), &tmpi) ? (long)tmpi : 0);
124 else if (tokens[0] ==
"ucb")
125 signal->ucb = (0 == string_to_int64(tokens[1].c_str(), &tmpi) ? (long)tmpi : 0);
133 OS::CLockGuard lock(*m_mutex);
137 int r = m_socket->Listen(&tv);
142 pmsg->event = EVENT_UNKNOWN;
143 pmsg->subject.clear();
144 pmsg->program.reset();
145 pmsg->signal.reset();
146 if (RcvMessageLength() &&
ReadField(field) && field ==
"BACKEND_MESSAGE")
151 __tokenize(field,
" ", pmsg->subject,
false);
152 n = (unsigned)pmsg->subject.size();
153 DBG(DBG_DEBUG,
"%s: %s (%u)\n", __FUNCTION__, field.c_str(), n);
155 if (pmsg->subject[0] ==
"UPDATE_FILE_SIZE")
156 pmsg->event = EVENT_UPDATE_FILE_SIZE;
157 else if (pmsg->subject[0] ==
"DONE_RECORDING")
158 pmsg->event = EVENT_DONE_RECORDING;
159 else if (pmsg->subject[0] ==
"QUIT_LIVETV")
160 pmsg->event = EVENT_QUIT_LIVETV;
161 else if (pmsg->subject[0] ==
"LIVETV_WATCH")
162 pmsg->event = EVENT_LIVETV_WATCH;
163 else if (pmsg->subject[0] ==
"LIVETV_CHAIN")
164 pmsg->event = EVENT_LIVETV_CHAIN;
165 else if (pmsg->subject[0] ==
"SIGNAL")
167 pmsg->event = EVENT_SIGNAL;
168 pmsg->signal = RcvSignalStatus();
170 else if (pmsg->subject[0] ==
"RECORDING_LIST_CHANGE")
172 pmsg->event = EVENT_RECORDING_LIST_CHANGE;
173 if (n > 1 && pmsg->subject[1] ==
"UPDATE")
174 pmsg->program = RcvProgramInfo();
176 else if (pmsg->subject[0] ==
"SCHEDULE_CHANGE")
177 pmsg->event = EVENT_SCHEDULE_CHANGE;
178 else if (pmsg->subject[0] ==
"ASK_RECORDING")
180 pmsg->event = EVENT_ASK_RECORDING;
181 pmsg->program = RcvProgramInfo();
183 else if (pmsg->subject[0] ==
"CLEAR_SETTINGS_CACHE")
184 pmsg->event = EVENT_CLEAR_SETTINGS_CACHE;
185 else if (pmsg->subject[0] ==
"GENERATED_PIXMAP")
186 pmsg->event = EVENT_GENERATED_PIXMAP;
187 else if (pmsg->subject[0] ==
"SYSTEM_EVENT")
188 pmsg->event = EVENT_SYSTEM_EVENT;
190 pmsg->event = EVENT_UNKNOWN;
195 return (
m_hang ? -(ENOTCONN) : 1);
200 return ((ProtoBase::IsOpen() && !
m_hang) ? 0 : -(ENOTCONN));
bool m_hang
Connection hang: while true allow retry.
bool ReadField(std::string &field)
This is the main namespace that encloses all public classes.
bool m_tainted
Connection has hung since last reset.
int RcvBackendMessage(unsigned timeout, EventMessage **msg)
Wait for new backend message from event connection.