/**
 * Callback that should be invoked when the data is received
 */
void CNaviReceiverProfileImpl::onBufferReceived(const tChannelId channel, CBuffer const& buffer)
{
   LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
   UInt8 *incomingData = buffer.getBuffer();
   int read_size = buffer.getSize();
   std::string json((char*)incomingData, read_size);
   LOG4CPLUS_TRACE(msLogger, "got string:");
   LOG4CPLUS_TRACE(msLogger, json);
   Json::Value root; // will contain the root value after parsing.
   Json::Reader reader;
   bool parsingSuccessful = reader.parse(json.c_str(), root);
   if (parsingSuccessful) {
      std::deque<std::string> tracks;
      Json::Value list=root["play"];
      Json::Value::UInt index=0;
      LOG4CPLUS_TRACE(msLogger, "tracks to play:");
      for(index=0;index<list.size();index++){
         LOG4CPLUS_TRACE(msLogger, list[index].asString());
         tracks.push_back(list[index].asString());
      }
      mpAppCallbacks->playTracks(tracks);
   } else {
      LOG4CPLUS_ERROR(msLogger, "Failed to parse tracklist!");
   }
}
CClimateClientProfile::~CClimateClientProfile()
{
   LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
   mBe = false;

   mpSenderThread->disconnect();
   delete mpSenderThread;
   delete mpReqMutex;

   while (!mReqQueue.empty())
   {
      CBuffer buf = mReqQueue.front();
      mReqQueue.pop();
      delete [] buf.getBuffer();
   }
}
void CClimateClientProfile::handleRequest()
{
   mpReqMutex->lock();
   CBuffer buf = mReqQueue.front();
   mReqQueue.pop();
   mpReqMutex->unlock();

   CError err = iviLink::Channel::sendBuffer(mChannelID, buf);
   if (!err.isNoError())
   {
      LOG4CPLUS_INFO(msLogger, "CClimateClientProfile::handleRequest() :: Send error"
         + static_cast<std::string>(err));
   }

   delete [] buf.getBuffer();
}
Exemple #4
0
/**
 * Sends buffer object to serial port
 * @param buffer
 * @return  none
 */
int CSerCom::sendBuffer(CBuffer &buffer) {

    if (!isOpen()) {
        throw string("Port closed.");
    }


    size_t len = buffer.getLength();

    unsigned char *tempBuf = new unsigned char[len];

//    cout << "++++++sending buffer: "; //@TODO remove it
    for (size_t i = 0; i < len; i++) {
        tempBuf[i] = buffer.getBuffer()[i];
//        cout << (int) tempBuf[i] << "[0x" << hex << (int) tempBuf[i] << dec << "] | ";
//        cout << (int) tempBuf[i] << "[0x" << hex << (int) tempBuf[i] << dec << "]("<<tempBuf[i]<<") | ";
    }
//    cout << endl;

    sendBuffer(tempBuf, len);
    delete[] tempBuf;
    return 0;
}