cosmetics
[deb_libcec.git] / src / lib / adapter / USBCECAdapterCommunication.cpp
index 0134751d31b2b05f8eb4f88f3320ff9b09fba686..12b8eacde7f70b2197656cf78d8a6cd7c33576d5 100644 (file)
@@ -55,12 +55,6 @@ CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(CCECProcessor *processo
 CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void)
 {
   Close();
-
-  if (m_port)
-  {
-    delete m_port;
-    m_port = NULL;
-  }
 }
 
 bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = 10000 */)
@@ -143,6 +137,12 @@ void *CUSBCECAdapterCommunication::Process(void)
   if (m_outBuffer.Pop(msg))
     msg->condition.Broadcast();
 
+  if (m_port)
+  {
+    delete m_port;
+    m_port = NULL;
+  }
+
   return NULL;
 }
 
@@ -412,9 +412,7 @@ bool CUSBCECAdapterCommunication::SetLineTimeout(uint8_t iTimeout)
 bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask)
 {
   bool bReturn(false);
-  CStdString strLog;
-  strLog.Format("setting ackmask to %2x", iMask);
-  CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str());
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask);
 
   CCECAdapterMessage *output = new CCECAdapterMessage;
 
@@ -432,6 +430,27 @@ bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask)
   return bReturn;
 }
 
+
+bool CUSBCECAdapterCommunication::SetControlledMode(bool controlled)
+{
+  bool bReturn(false);
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off");
+
+  CCECAdapterMessage *output = new CCECAdapterMessage;
+
+  output->PushBack(MSGSTART);
+  output->PushEscaped(MSGCODE_SET_CONTROLLED);
+  output->PushEscaped(controlled);
+  output->PushBack(MSGEND);
+  output->isTransmission = false;
+
+  if ((bReturn = Write(output)) == false)
+    CLibCEC::AddLog(CEC_LOG_ERROR, "could not set controlled mode");
+  delete output;
+
+  return bReturn;
+}
+
 bool CUSBCECAdapterCommunication::IsOpen(void)
 {
   return !IsStopped() && m_port->IsOpen() && IsRunning();
@@ -586,9 +605,7 @@ void CUSBCECAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg)
 
   if (m_port->Write(msg->packet.data, msg->Size()) != (ssize_t) msg->Size())
   {
-    CStdString strError;
-    strError.Format("error writing to serial port: %s", m_port->GetError().c_str());
-    CLibCEC::AddLog(CEC_LOG_ERROR, strError);
+    CLibCEC::AddLog(CEC_LOG_ERROR, "error writing to serial port: %s", m_port->GetError().c_str());
     msg->state = ADAPTER_MESSAGE_STATE_ERROR;
   }
   else