jeudi 1 novembre 2018

Sending Notification to Actual caller.

I have an API currentFuelPrice() and this api is singleton supported. In my code i made singleton. Lets say Two caller A1 and A2 is added as observer. Now when A1 calls on CurrentFuelPrice(). oncurrentFuelPrice() is received. Since it is singleton it will send a NotifyFuelCurrentPrice to both caller A1 and A2. How can i notfiy to actual caller ie. A1 only.

Below is my code.

//single ton
FuelService* FuelService::Create() {
  return (!m_instanceSingleton) ?
        m_instanceSingleton = new FuelService() : 
        m_instanceSingleton;
}

//Register to service 
FuelService::FuelService()
    : FuelProxy(),
      Listener(Listener_path)
 {
  registerListener((IOnFuel*)this);
  fuel_obj = FuelProxy::getInstance();
}

FuelService::~FuelService() {}

// adding observer
void FuelService::AddObserver(
    FuelProxy::FuelNotification* observer) {
  observer.push_back(observer);
}

// calling the API
void FuelService::CurrentFuelPrice(const uint32_t& sessionId) {
  fuel_obj->currentFuelPrice(sessionId);
}

// Getting response send back to caller
void FuelService::oncurrentFuelPrice(const uint32_t& sessionId,const uint32_t&price) {
    std::vector<FuelNotification*>::iterator it = observer.begin();
  for (; it != observer.end(); ++it)
    (*it)->NotifyFuelCurrentPrice(price);
}

Aucun commentaire:

Enregistrer un commentaire