#ifndef __SITECING_SCOREBOARD_H #define __SITECING_SCOREBOARD_H #include /** * @file * @brief the scoreboard manager. */ /** * @def MAX_SITECING_SCOREBOARD_SLOTS * The maximum number of slots scoreboard can hold. */ #define MAX_SITECING_SCOREBOARD_SLOTS 512 namespace sitecing { /** * The scoreboard slot. */ struct scoreboard_slot { /** * The state enumeration. */ enum _state { /** * The slot is free. */ state_free = 0, /** * The slot is allocated. */ state_allocated, /** * The process is idle. */ state_idle, /** * The process is accepting connection. */ state_accept, /** * The process is processing request. */ state_processing } state; /** * Process ID */ pid_t pid; }; /** * The scoreboard manager. */ class scoreboard { /** * shared memory id. */ int shmid; public: /** * Pointer to the scoreboard slots. */ scoreboard_slot *slots; scoreboard(); ~scoreboard(); /** * Allocate a scoreboard slot. * @return the slot number. */ int allocate_slot(); /** * Free the slot allocated. * @param slot the slot number. */ void free_slot(int slot); /** * Get the pointer to the slot. * @param slot the slot number. * @return the pointer. */ scoreboard_slot *get_slot(int slot); /** * Find the slot corresponding to the process ID. * @param pid the process id. * @return the slot number. */ int get_slot_by_pid(pid_t pid); /** * Count the slots in the particular state. * @param state the state. * @return the number of slots found. */ int count_slots(enum scoreboard_slot::_state state=scoreboard_slot::state_free); }; } #endif /* __SITECING_SCOREBOARD_H */