Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 827e3d5b authored by Amos Bianchi's avatar Amos Bianchi Committed by Gerrit Code Review
Browse files

Merge "Change argument of active services callback to bool."

parents f0b4ddc4 7a6cef97
Loading
Loading
Loading
Loading
+19 −13
Original line number Original line Diff line number Diff line
@@ -42,8 +42,7 @@ public:
     */
     */
    void forcePersist(bool persist);
    void forcePersist(bool persist);


    void setActiveServicesCountCallback(const std::function<bool(int)>&
    void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback);
                                        activeServicesCountCallback);


    bool tryUnregister();
    bool tryUnregister();


@@ -86,13 +85,16 @@ private:
    // count of services with clients
    // count of services with clients
    size_t mNumConnectedServices;
    size_t mNumConnectedServices;


    // previous value passed to the active services callback
    std::optional<bool> mPreviousHasClients;

    // map of registered names and services
    // map of registered names and services
    std::map<std::string, Service> mRegisteredServices;
    std::map<std::string, Service> mRegisteredServices;


    bool mForcePersist;
    bool mForcePersist;


    // Callback used to report the number of services with clients
    // Callback used to report if there are services with clients
    std::function<bool(int)> mActiveServicesCountCallback;
    std::function<bool(bool)> mActiveServicesCallback;
};
};


bool ClientCounterCallback::registerService(const sp<IBinder>& service, const std::string& name,
bool ClientCounterCallback::registerService(const sp<IBinder>& service, const std::string& name,
@@ -139,7 +141,7 @@ std::map<std::string, ClientCounterCallback::Service>::iterator ClientCounterCal


void ClientCounterCallback::forcePersist(bool persist) {
void ClientCounterCallback::forcePersist(bool persist) {
    mForcePersist = persist;
    mForcePersist = persist;
    if (!mForcePersist && mNumConnectedServices == 0) {
    if (!mForcePersist) {
        // Attempt a shutdown in case the number of clients hit 0 while the flag was on
        // Attempt a shutdown in case the number of clients hit 0 while the flag was on
        maybeTryShutdown();
        maybeTryShutdown();
    }
    }
@@ -185,8 +187,12 @@ void ClientCounterCallback::maybeTryShutdown() {
    }
    }


    bool handledInCallback = false;
    bool handledInCallback = false;
    if (mActiveServicesCountCallback != nullptr) {
    if (mActiveServicesCallback != nullptr) {
        handledInCallback = mActiveServicesCountCallback(mNumConnectedServices);
        bool hasClients = mNumConnectedServices != 0;
        if (hasClients != mPreviousHasClients) {
            handledInCallback = mActiveServicesCallback(hasClients);
            mPreviousHasClients = hasClients;
        }
    }
    }


    // If there is no callback defined or the callback did not handle this
    // If there is no callback defined or the callback did not handle this
@@ -238,9 +244,9 @@ void ClientCounterCallback::tryShutdown() {
    reRegister();
    reRegister();
}
}


void ClientCounterCallback::setActiveServicesCountCallback(const std::function<bool(int)>&
void ClientCounterCallback::setActiveServicesCallback(const std::function<bool(bool)>&
                                                           activeServicesCountCallback) {
                                                      activeServicesCallback) {
    mActiveServicesCountCallback = activeServicesCountCallback;
    mActiveServicesCallback = activeServicesCallback;
}
}


}  // namespace internal
}  // namespace internal
@@ -266,9 +272,9 @@ void LazyServiceRegistrar::forcePersist(bool persist) {
    mClientCC->forcePersist(persist);
    mClientCC->forcePersist(persist);
}
}


void LazyServiceRegistrar::setActiveServicesCountCallback(const std::function<bool(int)>&
void LazyServiceRegistrar::setActiveServicesCallback(const std::function<bool(bool)>&
                                                          activeServicesCountCallback) {
                                                     activeServicesCallback) {
    mClientCC->setActiveServicesCountCallback(activeServicesCountCallback);
    mClientCC->setActiveServicesCallback(activeServicesCallback);
}
}


bool LazyServiceRegistrar::tryUnregister() {
bool LazyServiceRegistrar::tryUnregister() {
+5 −6
Original line number Original line Diff line number Diff line
@@ -56,10 +56,10 @@ class LazyServiceRegistrar {
     void forcePersist(bool persist);
     void forcePersist(bool persist);


     /**
     /**
      * Set a callback that is executed when the total number of services with
      * Set a callback that is invoked when the active service count (i.e. services with clients)
      * clients changes.
      * registered with this process drops to zero (or becomes nonzero).
      * The callback takes an argument, which is the number of registered
      * The callback takes a boolean argument, which is 'true' if there is
      * lazy services for this process which have clients.
      * at least one service with clients.
      *
      *
      * Callback return value:
      * Callback return value:
      * - false: Default behavior for lazy services (shut down the process if there
      * - false: Default behavior for lazy services (shut down the process if there
@@ -73,8 +73,7 @@ class LazyServiceRegistrar {
      *
      *
      * This method should be called before 'registerService' to avoid races.
      * This method should be called before 'registerService' to avoid races.
      */
      */
     void setActiveServicesCountCallback(const std::function<bool(int)>&
     void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback);
                                         activeServicesCountCallback);


    /**
    /**
      * Try to unregister all services previously registered with 'registerService'.
      * Try to unregister all services previously registered with 'registerService'.