<class name="LocalMvS">
    <relationships>
        <association name="parent" class="MvKController" min="1" max="1"/>
    </relationships>
    <constructor>
        <parameter name="params"/>
        <body>
            <![CDATA[
            self.queue = []
            self.destinations = []
            import sys
            sys.path.append("../../state")
            from modelverse_state.main import ModelverseState
            self.mvs = ModelverseState(params[0])
            self.mvs_operations = {
               "CN": self.mvs.create_node,
               "CE": self.mvs.create_edge,
               "CNV": self.mvs.create_nodevalue,
               "CD": self.mvs.create_dict,

               "RV": self.mvs.read_value,
               "RO": self.mvs.read_outgoing,
               "RI": self.mvs.read_incoming,
               "RE": self.mvs.read_edge,
               "RD": self.mvs.read_dict,
               "RDN": self.mvs.read_dict_node,
               "RDNE": self.mvs.read_dict_node_edge,
               "RDE": self.mvs.read_dict_edge,
               "RRD": self.mvs.read_reverse_dict,
               "RR": self.mvs.read_root,
               "RDK": self.mvs.read_dict_keys,

               "DE": self.mvs.delete_edge,
               "DN": self.mvs.delete_node,

               "DUMP": self.mvs.dump_modelverse,
            }
            ]]>
        </body>
    </constructor>

    <method name="process_message">
        <parameter name="operation_name"/>
        <parameter name="parameters"/>
        <body>
            <![CDATA[
            op = self.mvs_operations[operation_name]
            return op(*parameters)
            ]]>
        </body>
    </method>

    <scxml initial="init">
        <state id="init">
            <transition target="../running">
                <raise event="http_client_ready" scope="narrow" target="'parent'"/>
            </transition>
        </state>

        <state id="running">
            <transition event="HTTP_input" target=".">
                <parameter name="data"/>
                <parameter name="destination"/>
                <script>
                    decoded_data = json.loads(data.split("=",1)[1])
                    result = []
                    for command, params in decoded_data:
                        result.append(self.process_message(command, params))
                    data = {"data": json.dumps(result)}
                </script>
                <raise event="HTTP_output" scope="narrow" target="destination">
                    <parameter expr="data"/>
                </raise>
            </transition>
        </state>
    </scxml>
</class>
