コード例 #1
0
 CError write(std::pair<K, V> const& val)
 {
    CError err = write(val.first);
    if (!err.isNoError())
       return err;
    err = write(val.second);
    if (!err.isNoError())
       return err;
    return CError::NoError(moduleName);
 }
コード例 #2
0
 CError read(std::pair<K, V> & val)
 {
    CError err = read(val.first);
    if (!err.isNoError())
       return err;
    err = read(val.second);
    if (!err.isNoError())
       return err;
    return CError::NoError(moduleName);
 }
コード例 #3
0
ファイル: CPmpProtocol.cpp プロジェクト: Vanuan/iviLink
      void CPmpProtocol::connect()
      {
         LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
         while (mBe)
         {
            LOG4CPLUS_INFO(msLogger, "connect attempt");
            UInt32 chid = 0;
            CError err = iviLink::ChannelSupervisor::allocateChannel(this,mTag.c_str(), chid);
            if (err.isNoError())
            {
               mChannelIdCond.lock();
               LOG4CPLUS_INFO(msLogger, "ok chid = " +
                     convertIntegerToString(static_cast<int>(chid)));
               mChannelId = chid;
               mChannelIdCond.broadcast();
               mChannelIdCond.unlock();

               mConnectionLostSem.wait();
            }
            else
            {
               LOG4CPLUS_INFO(msLogger, static_cast<std::string>(err));
               sleep(1);
            }
         }
      }
コード例 #4
0
 int CProfileRepoServerClb::loop()
 {
    CError err = CError::NoError("ProfileRepository","loop");
    for (int i = 1; ; ++i)
    {
       LOG4CPLUS_INFO(msLogger, "CProfileRepoServerClb::loop() : connection try number: "+
             convertIntegerToString(i));
       err = mpIpc->waitForConnection();
       LOG4CPLUS_INFO(msLogger, "CProfileRepoServerClb::loop() : waitForConnectionEnded()");
       if (err.isNoError())
       {
          LOG4CPLUS_INFO(msLogger,"CProfileRepoServerClb::loop() :: *** client connected to server ***");
          mConLostSem.wait();
          LOG4CPLUS_INFO(msLogger,"CProfileRepoServerClb::loop() :: *** connection lost, exiting ***");
          return 0;
       }
       else
       {
          LOG4CPLUS_INFO(msLogger, static_cast<std::string>(err));
       }
       LOG4CPLUS_INFO(msLogger, "failed connection");
       usleep (250000);
    }
    return 0;
 }
コード例 #5
0
CConnectivityAgentProxy::CConnectivityAgentProxy()
		: CThread("CallbackTread"), mpIpc(NULL)
{
	LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
	static char const* const arr[] =
	{ gpCA_UNIX_SOCK_PATH, first_lsn_path, second_lsn_path };

	for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i)
	{
		if (arr[i])
		{
			LOG4CPLUS_INFO(logger,
					"Trying to connect to connectivity agent using address " + std::string(arr[i]));
			CIpc* pipc = new CIpc(arr[i], *this);
			CError err = pipc->connect();
			if (err.isNoError())
			{
				mpIpc = pipc;
				break;
			} else
			{
				LOG4CPLUS_WARN(logger, static_cast<std::string>(err));
				delete pipc;
			}
		}
	}

	if (!mpIpc)
	{
		LOG4CPLUS_ERROR(logger, "Unable to connect to connectivity agent");
	}

	start();
}
コード例 #6
0
 void CAppManPmpIpcClient::loop()
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    mBe = true;
    CError err = CError::NoError("","");
    for (int i = 1;mBe ; ++i)
    {
       LOG4CPLUS_INFO(msLogger, "loop() : connect trying number : " + convertIntegerToString(i));
       err = mpIpc->connect();
       LOG4CPLUS_INFO(msLogger, "loop() : connect ended");
       if (mBe && err.isNoError())
       {
          mNoConnection = false;
          mConLostSem.wait();
          mNoConnection = true;
       }
       if (!mBe)
       {
          LOG4CPLUS_INFO(msLogger, "loop() :: mBe == false");
          break;
       }
       LOG4CPLUS_WARN(msLogger, "loop() :: connection failed");
       usleep(250000);
    }
 }
コード例 #7
0
ファイル: CPIM.cpp プロジェクト: Vanuan/iviLink
CPMALError CPIM::generatePIUID(iviLink::CUid const& profileUid,
      iviLink::Service::Uid const& serviceUID,
      iviLink::Profile::IUid & piuid)
{
   bool remote = false;

   mIncomingPrfMapMutex.lock();
   {
      if (!mIncomingPrfMap.empty())
      {
         tIncomingPrfMap::iterator it = mIncomingPrfMap.find(std::make_pair(serviceUID, profileUid));
         if (it != mIncomingPrfMap.end())
         {
            piuid = it->second;
            mIncomingPrfMap.erase(it);
            remote = true;
         }
      }
   }
   mIncomingPrfMapMutex.unlock();

   if (remote)
      return CPMALError::NoPMALError(gModuleName);

   CError err = PIM::getPIUID(piuid);
   if (!err.isNoError())
   {
      LOG4CPLUS_ERROR(logger, static_cast<std::string>(err));
      return CPMALError(CPMALError::ERROR_PIM_INTERNAL, gModuleName, "no piuid");
   }

   return CPMALError::NoPMALError(gModuleName);
}
コード例 #8
0
    bool connect()
    {
        CError err = CError::NoError();
        if (mpIpc == NULL)
        {
            char const * addr;
            if (gpNEGOTIATOR_IPC_ADDR != NULL)
            {
                addr = gpNEGOTIATOR_IPC_ADDR;
            } else
            {
                addr = ipcNegotiatorId;
            }
            mpIpc = new CIpc(addr, *this);
        }
        for (int tryNum = 1; tryNum <= MAX_TRY_COUNT; ++tryNum)
        {
            err = mpIpc->connect();
            if (err.isNoError())
            {
                return true;
            }

            sleep(2);
        }
        return false;
    }
コード例 #9
0
ファイル: CPIM.cpp プロジェクト: Vanuan/iviLink
void CPIM::unloadAll()
{
   LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
   typedef PIM::CProfileInstanceMap::tProfilesList PL;
   PL profiles;
   CError err = mInstanceMap.getAllRegisterd(profiles);
   if (!err.isNoError())
   {
      LOG4CPLUS_ERROR(logger, static_cast<std::string>(err));
      return;
   }

   IProfileManagerCallbacks* clbs = NULL;
   CPMALComponentMgr* mgr = CPMALComponentMgr::getInstance();
   if (mgr)
   {
      clbs = mgr->getProfileManagerCallbacks();
   }

   for (PL::iterator it = profiles.begin(); it != profiles.end(); ++it)
   {
      Profile::IUid const& piuid = it->first;
      Profile::CProfile* pp = static_cast<Profile::CProfile*>(it->second);

      unloadProfileThroughClient(clbs, pp, piuid);
   }
}
コード例 #10
0
void CMediaControlServerProfile::onDisable() {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    CError err = iviLink::Channel::deallocateChannel(mChannelID);
    if (!err.isNoError()) {
        LOG4CPLUS_WARN(msLogger, "Unable to deallocate channel: " + static_cast<std::string> (err));
    }
}
コード例 #11
0
void CClimateClientProfile::onDisable()
{
   CError err = iviLink::Channel::deallocateChannel(mChannelID);
   if (!err.isNoError())
   {
      LOG4CPLUS_WARN(msLogger, "Unable to deallocate channel: " + static_cast<std::string>(err));
   }
}
コード例 #12
0
   CError readContainer(InsertIter result)
   {
      typedef typename InsertIter::container_type::value_type tVal;
      UInt32 size = 0;

      CError err = read(size);
      if (!err.isNoError())
         return err;

      for (UInt32 i = 0; i < size; ++i)
      {
         tVal val;
         err = read(val);
         if (!err.isNoError())
            return err;
         *result++ = val;
      }
      return CError::NoError(moduleName);
   }
コード例 #13
0
   CError write(InputIter first, InputIter last)
   {
      UInt8* curPos = mpBuffer + mUsedSize;
      UInt32 size = 0;

      CError err = write(size);
      if (!err.isNoError())
         return err;

      for (; first != last; ++first, ++size)
      {
         err = write(*first);
         if (!err.isNoError())
            return err;
      }

      *reinterpret_cast<UInt32*>(curPos) = size;
      return CError::NoError(moduleName);
   }
コード例 #14
0
void ReceiverProfile<T,I>::onDisable()
{
    LOG4CPLUS_TRACE_METHOD( (logger<T,I>()), __PRETTY_FUNCTION__ );
    CError err = iviLink::Channel::deallocateChannel(mChannelID);
    if (!err.isNoError())
    {
        LOG4CPLUS_ERROR((logger<T,I>()), "Unable to deallocate channel: " + static_cast<std::string>(err));
    }
    else
        mChannelID = 0;
}
コード例 #15
0
void CMediaControlServerProfile::onChannelDeleted(const UInt32 channel_id) {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);

    if (mChannelID == channel_id)
        mChannelID = 0;

    CError err = iviLink::Channel::deallocateChannel(channel_id);
    if (!err.isNoError()) {
        LOG4CPLUS_WARN(msLogger, "Unable to deallocate channel: " + static_cast<std::string> (err));
    }
}
コード例 #16
0
void ReceiverProfile<T,I>::onChannelDeleted(const UInt32 channel_id)
{
    LOG4CPLUS_TRACE_METHOD((logger<T,I>()), __PRETTY_FUNCTION__ );

    if (mChannelID == channel_id)
        mChannelID = 0;

    CError err = iviLink::Channel::deallocateChannel(channel_id);
    if (!err.isNoError())
    {
        LOG4CPLUS_WARN((logger<T,I>()), "Unable to deallocate channel: " + static_cast<std::string>(err));
    }
}
コード例 #17
0
ファイル: CPIM.cpp プロジェクト: Vanuan/iviLink
void CPIM::unloadProfile(Profile::IUid const& piuid, Profile::CProfile *& profile)
{
   LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__ + (" piuid " + piuid.value() + " profile " + convertIntegerToString((intptr_t)profile)));

   CError err = mInstanceMap.unregisterProfile(profile);
   if (!err.isNoError())
   {
      // Someone was faster and already removed this profile
      LOG4CPLUS_DEBUG(logger, "unloadProfile: profile already unloaded, err = " + static_cast<std::string>(err));
      return;
   }

   PIM::CProfileEnabler::disable(profile);
   
   if (mRemoteDiedProfiles.erase(piuid) == 0)
   {
      CPMALComponentMgr *pMgr = CPMALComponentMgr::getInstance();
      if (pMgr)
      {
         IPMALIpcToPIM* ipc = pMgr->getIpcToPIM();
         if (ipc)
         {
            err = ipc->profileDied(piuid);
            if (!err.isNoError())
            {
               /// @todo what error handling can be here?
               LOG4CPLUS_INFO(logger, "todo what error handling can be here?");
               LOG4CPLUS_ERROR(logger, static_cast<std::string>(err));
            }
         }
      }
   }

   PIM::releasePIUID(piuid);
   PIM::CProfileDestroyer::destroy(profile);
   
   profile = NULL;
   PIM::unloadProfileLib(piuid);
}
コード例 #18
0
ファイル: buffer_helpers.cpp プロジェクト: Vanuan/iviLink
CError CBufferWriter::write<std::string>(std::string const& val)
{
   UInt32 valSize = val.size();
   CError err = write(valSize);
   if (!err.isNoError())
      return err;
   if (valSize > mFullSize - mUsedSize)
      return CError(1, moduleName, CError::ERROR, "insufficient buffer size (from std::string write)");

   memcpy(mpBuffer + mUsedSize, val.c_str(), valSize);
   mUsedSize += valSize;
   return CError::NoError(moduleName);
}
コード例 #19
0
ファイル: buffer_helpers.cpp プロジェクト: Vanuan/iviLink
CError CBufferReader::read<std::string>(std::string & val)
{
   UInt32 valSize = 0;
   CError err = read(valSize);
   if (!err.isNoError())
      return err;
   if (valSize > mFullSize - mUsedSize)
      return CError(1, moduleName, CError::ERROR, "insufficient buffer size (from std::string write)");

   val.assign(reinterpret_cast<char const*>(mpBuffer + mUsedSize), valSize);
   mUsedSize += valSize;

   return err;
}
コード例 #20
0
    void sendMessage(UInt8 const* pPayload, UInt32 payloadSize, UInt8* const pResponseBuffer,
            UInt32& bufferSize)
    {
        bool con_res = connect();
        assert(con_res);

        CError err = mpIpc->request(id++, pPayload, payloadSize, pResponseBuffer, bufferSize);
        if (err.isNoError())
        {
        } else
        {
        }
        mpIpc->disconnect();
    }
コード例 #21
0
ファイル: buffer_helpers.cpp プロジェクト: Vanuan/iviLink
CError CBufferWriter::write<iviLink::CUid>(iviLink::CUid const& val)
{
   UInt8 const* uid = NULL;
   UInt32 uidSize = val.getByteArray(uid);
   CError err = write(uidSize);
   if (!err.isNoError())
      return err;
   if (uidSize > mFullSize - mUsedSize)
      return CError(1, moduleName, CError::ERROR, "insufficient buffer size (from CUid write)");

   memcpy(mpBuffer + mUsedSize, uid, uidSize);
   mUsedSize += uidSize;
   return CError::NoError(moduleName);
}
コード例 #22
0
ファイル: buffer_helpers.cpp プロジェクト: Vanuan/iviLink
CError CBufferReader::read<iviLink::CUid>(iviLink::CUid & val)
{
   UInt32 uidSize = 0;
   CError err = read(uidSize);
   if (!err.isNoError())
      return err;
   if (uidSize > mFullSize - mUsedSize)
      return CError(1, moduleName, CError::ERROR, "insufficient buffer size (from CUid write)");

   err = val.fromByteArray(mpBuffer + mUsedSize, uidSize);
   mUsedSize += uidSize;

   return err;
}
コード例 #23
0
   CError readMap(InsertIter result)
   {
      typedef typename InsertIter::container_type::key_type tKey;
      typedef typename InsertIter::container_type::mapped_type tVal;
      UInt32 size = 0;

      CError err = read(size);
      if (!err.isNoError())
         return err;

      for (UInt32 i = 0; i < size; ++i)
      {
         tKey key;
         tVal val;
         err = read(key);
         if (!err.isNoError())
            return err;
         err = read(val);
         if (!err.isNoError())
            return err;
         *result++ = std::make_pair(key, val);
      }
      return CError::NoError(moduleName);
   }
コード例 #24
0
void CMediaControlServerProfile::handleRequest()
{
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    mpReqMutex->lock();
    std::string msg;
    msg = mReqQueue.front();
    mReqQueue.pop();
    mpReqMutex->unlock();

    CError err = iviLink::Channel::sendBuffer(mChannelID, msg.c_str(), msg.length());
    if (!err.isNoError())
    {
        LOG4CPLUS_INFO(msLogger, "CMediaSourceServerProfile::handleRequest() :: Send error"
                       + static_cast<std::string>(err));
    }
}
コード例 #25
0
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();
}
コード例 #26
0
ファイル: CSeatHUProfile.cpp プロジェクト: Vanuan/iviLink
void CSeatHUProfile::handleRequest()
{
   LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
   mpReqMutex->lock();
   Json::Value state = mSendState;
   mHasRequest = false;
   mpReqMutex->unlock();

   Json::StyledWriter writer;
   std::string data = writer.write(state);

   CError ret = iviLink::Channel::sendBuffer(mChannelID, data.c_str(), data.size() + 1);
   if(!ret.isNoError())
   {
       LOG4CPLUS_INFO(msLogger, "CSeatHUProfile::sendNotification() :: send error: "
         + static_cast<std::string>(ret));
   }
}
コード例 #27
0
void CClimateSenderProfile::handleRequest()
{
  buffer_t buf;
  {
    MutexLocker lock( mReqMutex );
    buf.swap( mReqQueue.front() );
    mReqQueue.pop();
  }

  CError err = iviLink::Channel::sendBuffer(mChannelID,
                                            reinterpret_cast<const void*>(buf.c_str()),
                                            static_cast<UInt32>(buf.size()));
  if (!err.isNoError())
  {
      LOG4CPLUS_INFO(msLogger, "CClimateSenderProfile::handleRequest() :: Send error"
                     + static_cast<std::string>(err));
  }

}
コード例 #28
0
ファイル: PIUIDGenerator.cpp プロジェクト: Vanuan/iviLink
CError iviLink::PMAL::PIM::getPIUID(IUid& uid)
{
   CPMALComponentMgr* mgr = CPMALComponentMgr::getInstance();
   if (!mgr)
      return CError(1, gModuleName, CError::ERROR);

   IPMALIpcToPIM* ipc = mgr->getIpcToPIM();

   Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("profileManager.PMAL.PIUIDGenerator"));
   CError err = ipc->generatePIUID(uid);
   if (!err.isNoError())
   {
      /// @todo error processing
      LOG4CPLUS_INFO(logger, "todo: error processing");
      return err;
   }

   return CError::NoError(gModuleName);
}
コード例 #29
0
ERROR_CODE CConnectivityAgentProxy::sendData(const UInt32 channel_id, UInt8 const* data,
		const UInt32 size)
{
	LOG4CPLUS_INFO(logger,
			"CConnectivityAgentProxy::sendData() => channel " + convertIntegerToString(channel_id)
					+ ", size " + convertIntegerToString(size));
	ERROR_CODE ret = ERR_FAIL;

	const int MAX_BUF_SIZE = 0xFFFF;

	if ((data != NULL) && ((Int32) size > 0) && (size < MAX_BUF_SIZE))
	{
		mRegistryMutex.lockRead();
		bool found = (mChannelRegistry.find(channel_id) != mChannelRegistry.end());
		mRegistryMutex.unlockRead();

		if (found)
		{
			CDataAccessor requestDA;
			requestDA.setChannelID(channel_id);
			requestDA.setOpCode(E_SEND_DATA);
			requestDA.setData(data, size);
			UInt8 buf[MAX_BUF_SIZE];
			requestDA.copyToRawArray(buf);
			assert(requestDA.getObjectSize() <= MAX_BUF_SIZE);
			if (requestDA.getObjectSize() > MAX_BUF_SIZE)
			{
				LOG4CPLUS_ERROR(logger,
						"CConnectivityAgentProxy::sendData() => ERROR:  \
                     requestDA.getObjectSize() > max buf size");
			}

			UInt32 respSize = 0;
			CError err = mpIpc->request(mMsgIdGen.next(), buf, requestDA.getObjectSize(), NULL,
					respSize);
			if (err.isNoError())
			{
				ret = ERR_OK;
			} else
			{
				LOG4CPLUS_WARN(logger, static_cast<std::string>(err));
			}
		} else
コード例 #30
0
ファイル: CPIM.cpp プロジェクト: Vanuan/iviLink
CPMALError CPIM::unloadProfile(Profile::CProfile *& profile)
{
   LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__ + (" " + convertIntegerToString((intptr_t)profile)));

   Profile::IUid piuid;
   CError err = mInstanceMap.find(profile, piuid);
   if (!err.isNoError())
   {
      /// @todo what error handling can be here?
      LOG4CPLUS_INFO(logger, "todo what error handling can be here?");

      LOG4CPLUS_ERROR(logger, static_cast<std::string>(err));
      return CPMALError(CPMALError::ERROR_WRONG_PARAM, gModuleName);
   }

   unloadProfile(piuid, profile);

   return CPMALError::NoPMALError(gModuleName);
}