from abc import abstractmethod from enum import Enum from typing import Any, List, Dict, Set from primaite.simulator.system.software import IOSoftware class ApplicationOperatingState(Enum): """Enumeration of Application Operating States.""" CLOSED = 0 "The application is closed or not running." RUNNING = 1 "The application is running." INSTALLING = 3 "The application is being installed or updated." class Application(IOSoftware): """ Represents an Application in the simulation environment. Applications are user-facing programs that may perform input/output operations. """ operating_state: ApplicationOperatingState "The current operating state of the Application." execution_control_status: str "Control status of the application's execution. It could be 'manual' or 'automatic'." num_executions: int = 0 "The number of times the application has been executed. Default is 0." groups: Set[str] = set() "The set of groups to which the application belongs." @abstractmethod def describe_state(self) -> Dict: """ Describes the current state of the software. The specifics of the software's state, including its health, criticality, and any other pertinent information, should be implemented in subclasses. :return: A dictionary containing key-value pairs representing the current state of the software. :rtype: Dict """ pass def apply_action(self, action: List[str]) -> None: """ Applies a list of actions to the Application. :param action: A list of actions to apply. """ pass def reset_component_for_episode(self, episode: int): """ Resets the Application component for a new episode. This method ensures the Application is ready for a new episode, including resetting any stateful properties or statistics, and clearing any message queues. """ pass def send(self, payload: Any) -> bool: """ Sends a payload to the SessionManager The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. :param payload: The payload to send. :return: True if successful, False otherwise. """ pass def receive(self, payload: Any) -> bool: """ Receives a payload from the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. :param payload: The payload to receive. :return: True if successful, False otherwise. """ pass