MCPcopy Create free account
hub / github.com/Pulse-Eight/libcec / OpenConnection

Method OpenConnection

src/libcec/CECProcessor.cpp:159–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */)
160{
161 bool bReturn(false);
162 CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT);
163
164 // ensure that a previous connection is closed
165 if (m_communication)
166 Close();
167
168 // reset all member to the initial state
169 ResetMembers();
170
171 // check whether the Close() method deleted any previous connection
172 if (m_communication)
173 {
174 m_libcec->AddLog(CEC_LOG_ERROR, "previous connection could not be closed");
175 return bReturn;
176 }
177
178 // create a new connection
179 m_communication = CAdapterFactory(this->m_libcec).GetInstance(strPort, iBaudRate);
180
181 // open a new connection
182 unsigned iConnectTry(0);
183 while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open((timeout.TimeLeft() / CEC_CONNECT_TRIES), false, bStartListening)) == false)
184 {
185 m_libcec->AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
186 m_communication->Close();
187 CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT);
188 }
189
190 m_libcec->AddLog(CEC_LOG_NOTICE, "connection opened");
191
192 // mark as initialised
193 SetCECInitialised(true);
194
195 return bReturn;
196}
197
198bool CCECProcessor::CECInitialised(void)
199{

Callers

nothing calls this directly

Calls 6

CloseFunction · 0.85
CAdapterFactoryClass · 0.85
GetInstanceMethod · 0.80
AddLogMethod · 0.45
OpenMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected