aboutsummaryrefslogblamecommitdiffstats
path: root/include/HandlerManager.h
blob: 4f63f176234995187ac8e2a54496b61686a7d2b6 (plain) (tree)
1
2
3
4
5
6
7
8







                          




                                                                              

            



                             
                                                                          


                               
           











                                                                               





                                                                               
                       
                                                    
                                                      
                                                                             

                                               




                                               
                                                     













                                                                                            
                                          





                                         

      
#pragma once

#include "Api.h"
#include "ObjectManager.h"

#include <string>
#include <vector>

/**
 * @file HandlerManager.h
 * @brief Declares handle allocation and release for authorized object access.
 */

namespace nt
{
    class IdentityManager;
    class LifecycleManager;
    class PermissionsManager;

    /** @brief Opens and closes authorized handles to registry objects. */
    class NT_API HandlerManager
    {
    public:
        /**
         * @brief Constructs a HandlerManager with shared runtime dependencies.
         *
         * All managers are injected so that state (registry entries, lifecycle
         * counters, permission policy) persists across calls rather than being
         * rebuilt per open/close.
         */
        HandlerManager(ObjectManager& objects,
                       PermissionsManager& permissions,
                       IdentityManager& identities,
                       LifecycleManager& lifecycles);

        /**
         * @brief Represents authorized access to an object in the registry.
         *
         * This increases the handle count in the object manager. We should
         * consider adding a vector to the object manager with all handles that
         * refer to an object.
         */
        struct handle {
            /** Object referenced by this handle. */
            ObjectManager::registry* object = nullptr;
            /** Connection metadata associated with the authorized access. */
            void* connection_context = nullptr;
        };

        /**
         * @brief Releases a handle allocation.
         * @param handle Handle to release.
         */
        void DeallocateHandle(struct handle* handle);

        /**
         * @brief Opens an object by path for a connection.
         * @param object_path Logical object path.
         * @param connection_context Connection metadata for the caller.
         * @return A valid handle pointer on success, or nullptr on failure.
         */
        struct handle* Open(std::vector<std::string> object_path, void* connection_context);

        /**
         * @brief Closes a previously opened handle.
         * @param handle Handle to close.
         * @return True when the handle was closed successfully.
         */
        bool Close(struct handle* handle);

    private:
        ObjectManager& objects_;
        PermissionsManager& permissions_;
        IdentityManager& identities_;
        LifecycleManager& lifecycles_;
    };
}