pymasep.application =================== .. py:module:: pymasep.application Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pymasep/application/connected_sub_app_info/index /autoapi/pymasep/application/sub_app/index /autoapi/pymasep/application/sub_app_state/index Classes ------- .. autoapisummary:: pymasep.application.SubApp pymasep.application.SubAppState pymasep.application.ConnectedSubAppInfo Package Contents ---------------- .. py:class:: SubApp(app, received_q_id, cfg) Bases: :py:obj:`threading.Thread` Part of the application as a Thread. Usually a sub application is the engine or the interface. :param App app: main application :param received_q_id: id of the queue used by the sub app to receive messages. :param cfg: configuration of the sub application .. py:attribute:: id :type: str id of the sub application .. py:attribute:: config configuration of the sub application .. py:attribute:: app main application pointer .. py:attribute:: messages_received_q_id id of the queue used to receive messages .. py:attribute:: messages_received :type: queue.Queue queue used to receive messages .. py:attribute:: connected_sub_app dict of sub applications information connected to this sub application .. py:attribute:: current_event :type: Optional[pymasep.communication.message.Message] :value: None Last message received by the sub application .. py:attribute:: app_states possible states of the sub application .. py:attribute:: current_app_states :type: List[pymasep.application.sub_app_state.SubAppState] :value: [] Stack of the current state of the sub application .. py:attribute:: logger :type: logging.Logger logger for the sub application .. py:attribute:: environment :type: Optional[pymasep.common.environment.Environment] :value: None environment used to run the sub application .. py:attribute:: remote_communication :type: Optional[pymasep.communication.base_threaded_communication.BaseThreadedCommunication] :value: None the remote communication of the sub application as a BaseThreadedCommunication (Client or Server) .. py:method:: __del__() Delete the instance. Close the logger .. py:method:: register_connected_sub_app(sub_app_id, role, sent_q = None) Register a sub application connected to self with a rale, and optionally a queue (if it's the same process). :param sub_app_id: Connected sub app id :param role: role of the connected sub app. See ConnectedSubAppInfo. :param sent_q: Queue of the connected sub app used to send messages (for sub apps in the same process) .. py:method:: get_connected_id_from_agent_fname(agent_fname) get the connected sub app that handles an agent :param agent_fname: the agent full name (ex. state.agent_name) :return: the id of the sub app associated to the agent .. py:method:: send_message(message, subapp_id) Send messages to a sub app from its id. Send by queue or by socket according to the connection between the tow sub app :param message: Message to send :param subapp_id: destination sub app id .. py:method:: send_message_to_queue(message, q) :staticmethod: Send a message to a queue. The message is put in the queue as byte :param message the message to send :param q the queue .. py:method:: wait_message(wanted_messages, block = True, most_recent = False, keep_all = None) Wait for a message of certain types. The wait can be blocked or not. The received message is put in self.current_event :param wanted_messages: List of wanted messages types. :param block: True if the method blocks until a message arrives :param most_recent: True makes the function to get the most recent message in the queue and empty the queue :param keep_all: List of message types that will not be skipped when most_recent is True. All messages after the message with type in keep_all, are kept in the queue. :return: The received message .. py:method:: get_current_app_state() Get the current sub app state :return: The current sub app state as SubAppState .. py:method:: push_state(sbapp_state) Push a new state in the head state. Pause the current state and init the new one. :param sbapp_state: New state to push .. py:method:: set_state(sbapp_state) Set a new state. Remove the ald current and push the new one. :param sbapp_state: New state to set .. py:method:: pop_state() Clean and remove the current state .. py:class:: SubAppState(sub_application) This class implements the concept (pretty much) of Game State but in the sub app level. :param pymasep.application.SubApp sub_application: the sub application where the state is defined .. py:attribute:: sub_application the sub application where the state is defined .. py:attribute:: active :value: False if the state is active or not .. py:method:: init() Initialisation of the state .. py:method:: update() :abstractmethod: the update phase of the state, where variables change .. py:method:: render(time_delta) :abstractmethod: the render part : how to display the state :param time_delta: the time delta since the last render .. py:method:: pause() Pause the state .. py:method:: clean() The state is destroyed. Clean all elements of the state .. py:class:: ConnectedSubAppInfo(sub_app_id, role, msg_queue = None, agent_fname = None) Information of a sub application connected to another one. :param sub_app_id: the id of the connected sub app. :param role: the role of the connected sub app. See ROLE_* bellow for more information. :param msg_queue: the queue to send messages (in the case of intra process sub app). :param agent_fname: the agent fullname managed by the sub app (for interface connected sup app, None otherwise). .. py:attribute:: ROLE_NONE :value: 'None' No role. Testing only .. py:attribute:: ROLE_OBSERVER :value: 'Observer' The connected sub app is an Interface as observer. No action cannot be send to engine. .. py:attribute:: ROLE_ACTOR :value: 'Actor' The connected sub app is an Interface as actor. Engine will take into account the action send. .. py:attribute:: ROLE_SERVER :value: 'Server' The connected sub app is the engine .. py:attribute:: id :type: str the id of the connected sub app .. py:attribute:: role :type: str The role of the connected sub app .. py:attribute:: queue :type: queue.Queue The queue to send message (for the case of intra process sub app) .. py:attribute:: agent_fname The agent fullname managed by the sub app (for interface) .. py:attribute:: last_info_sent data about sent information to this sub_app by the engine