<?xml version="1.0" encoding="UTF-8"?>
<Domain
    xmlns="http://www.soti.net/connect-definitions"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.soti.net/connect-definitions ../../../Soti.Connect.ProtocolDefinitions/Soti.Connect.ProtocolDefinitions.Parser/protocol.xsd">
    <Imports>
        <xi:include href="./base-rest-protocol.xml" parse="xml" />
    </Imports>
    <Messages>
        <Message id="ZebraTcpCheckIn" />
        <Message id="ZebraTcpResult">
            <Object id="Resource">
                <DataPointReference id="device.product_name" path="base-module#model-id" />
                <DataPointReference id="device.unique_id" path="GenericDeviceState#serial-number" />
                <DataPointReference id="device.zuid" path="base-module#device-id" />
                <DataPointReference id="device.friendly_name" path="base-module#device-name" />
                <DataPointReference id="device.company_name" path="base-module#manufacturer" />
                <DataPointReference id="appl.name" path="base-module#version" />
                <DataPointReference id="interface.network.active.ip_addr" path="NetworkInfo#ipaddress" />
                <DataPointReference id="latest-response" path="ZebraTcp-Data#latest-response" />
            </Object>
        </Message>
        <Message id="ZebraTcpPushFile">
            <Object id="Resource">
                <Segment id="File" type="file" />
                <Segment id="ReadResponse" type="boolean" />
            </Object>
        </Message>
        <Message id="ZebraTcpPushCommand">
            <Object id="Resource">
                <Segment id="Text" type="string" />
                <Segment id="ReadResponse" type="boolean" />
            </Object>
        </Message>
        <Message id="ZebraTcpGetValue">
            <Object id="Resource">
                <Segment id="Text" type="string" />
            </Object>
        </Message>
    </Messages>

    <Transactions>
        <Transaction id="ZebraTcpPushFile" semanticid="ZebraTcp-Operations#ZebraTcp-Push-File" isMetaTransaction="true">
            <Blocks>
                <Block id="1">
                    <SendMessage id="ZebraTcpPushFile">
                        <UserAssignment actionArgName="File" path="Resource/File" />
                        <UserAssignment actionArgName="Wait For Response" path="Resource/ReadResponse" />
                    </SendMessage>
                    <Switch>
                        <SwitchOnMessage timeout="300000"> <!-- we are using it in PA to set a timeout for the whole operation -->
                            <MessageCase>
                                <ReceiveMessage id="Success" />
                                <BlockAction>
                                    <Terminate success="true" />
                                </BlockAction>
                            </MessageCase>
                            <MessageCase>
                                <ReceiveMessage id="Error">
                                    <VariableDefinition id="Resource" path="Resource" />
                                </ReceiveMessage>
                                <BlockAction>
                                    <Terminate success="false">
                                        <Log variableId="Resource" />
                                    </Terminate>
                                </BlockAction>
                            </MessageCase>
                        </SwitchOnMessage>
                    </Switch>
                </Block>
            </Blocks>
            <AlertBlocks>
                <!-- this timeout is for MS meta transaction -->
                <AlertBlock timeout="300" MessageId="ZebraTcpResult" timeoutAlertId="ZebraTcpTimeout" operationIdSource="ConnectSends">
                    <SuccessCase>
                        <Enumeration>
                            <Value>Success</Value>
                        </Enumeration>
                    </SuccessCase>
                    <FailureCase>
                        <Enumeration>
                            <Value>Failure</Value>
                        </Enumeration>
                    </FailureCase>
                </AlertBlock>
            </AlertBlocks>
        </Transaction>

        <Transaction id="ZebraTcpPushCommand" semanticid="ZebraTcp-Operations#ZebraTcp-Push-Command" isMetaTransaction="true">
            <Blocks>
                <Block id="1">
                    <SendMessage id="ZebraTcpPushCommand">
                        <UserAssignment actionArgName="Text" path="Resource/Text" />
                        <UserAssignment actionArgName="Wait For Response" path="Resource/ReadResponse" />
                    </SendMessage>
                    <Switch>
                        <SwitchOnMessage timeout="300000">
                            <MessageCase>
                                <ReceiveMessage id="Success" />
                                <BlockAction>
                                    <Terminate success="true" />
                                </BlockAction>
                            </MessageCase>
                            <MessageCase>
                                <ReceiveMessage id="Error">
                                    <VariableDefinition id="Resource" path="Resource" />
                                </ReceiveMessage>
                                <BlockAction>
                                    <Terminate success="false">
                                        <Log variableId="Resource" />
                                    </Terminate>
                                </BlockAction>
                            </MessageCase>
                        </SwitchOnMessage>
                    </Switch>
                </Block>
            </Blocks>
            <AlertBlocks>
                <AlertBlock timeout="300" MessageId="ZebraTcpResult" timeoutAlertId="ZebraTcpTimeout" operationIdSource="ConnectSends">
                    <SuccessCase>
                        <Enumeration>
                            <Value>Success</Value>
                        </Enumeration>
                    </SuccessCase>
                    <FailureCase>
                        <Enumeration>
                            <Value>Failure</Value>
                        </Enumeration>
                    </FailureCase>
                </AlertBlock>
            </AlertBlocks>
        </Transaction>

        <Transaction id="ZebraTcpGetValue" semanticid="ZebraTcp-Operations#ZebraTcp-Get-Value" isMetaTransaction="true">
            <Blocks>
                <Block id="1">
                    <SendMessage id="ZebraTcpGetValue">
                        <UserAssignment actionArgName="Text" path="Resource/Text" />
                    </SendMessage>
                    <Switch>
                        <SwitchOnMessage timeout="300000">
                            <MessageCase>
                                <ReceiveMessage id="Success" />
                                <BlockAction>
                                    <Terminate success="true" />
                                </BlockAction>
                            </MessageCase>
                            <MessageCase>
                                <ReceiveMessage id="Error">
                                    <VariableDefinition id="Resource" path="Resource" />
                                </ReceiveMessage>
                                <BlockAction>
                                    <Terminate success="false">
                                        <Log variableId="Resource" />
                                    </Terminate>
                                </BlockAction>
                            </MessageCase>
                        </SwitchOnMessage>
                    </Switch>
                </Block>
            </Blocks>
            <AlertBlocks>
                <AlertBlock timeout="300" MessageId="ZebraTcpResult" timeoutAlertId="ZebraTcpTimeout" operationIdSource="ConnectSends">
                    <SuccessCase>
                        <Enumeration>
                            <Value>Success</Value>
                        </Enumeration>
                    </SuccessCase>
                    <FailureCase>
                        <Enumeration>
                            <Value>Failure</Value>
                        </Enumeration>
                    </FailureCase>
                </AlertBlock>
            </AlertBlocks>
        </Transaction>
        
        <Transaction id="ZebraTcpCheckIn" semanticid="base-module#checkin" isMetaTransaction="true">
            <Blocks>
                <Block id="1">
                    <SendMessage id="ZebraTcpCheckIn" />
                    <Switch>
                        <SwitchOnMessage timeout="300000">
                            <MessageCase>
                                <ReceiveMessage id="Success" />
                                <BlockAction>
                                    <Terminate success="true" />
                                </BlockAction>
                            </MessageCase>
                            <MessageCase>
                                <ReceiveMessage id="Error">
                                    <VariableDefinition id="Resource" path="Resource" />
                                </ReceiveMessage>
                                <BlockAction>
                                    <Terminate success="false">
                                        <Log variableId="Resource" />
                                    </Terminate>
                                </BlockAction>
                            </MessageCase>
                        </SwitchOnMessage>
                    </Switch>
                </Block>
            </Blocks>
            <AlertBlocks>
                <AlertBlock timeout="300" MessageId="ZebraTcpResult" timeoutAlertId="ZebraTcpTimeout" operationIdSource="ConnectSends">
                    <SuccessCase>
                        <Enumeration>
                            <Value>Success</Value>
                        </Enumeration>
                    </SuccessCase>
                    <FailureCase>
                        <Enumeration>
                            <Value>Failure</Value>
                        </Enumeration>
                    </FailureCase>
                </AlertBlock>
            </AlertBlocks>
        </Transaction>

        <Transaction id="Ping" semanticid="Ping#Ping" isMetaTransaction="true">
            <Blocks>
                <Block id="1">
                    <SendMessage id="ZebraTcpCheckIn" />
                    <Switch>
                        <SwitchOnMessage timeout="300000">
                            <MessageCase>
                                <ReceiveMessage id="Success" />
                                <BlockAction>
                                    <Terminate success="true" />
                                </BlockAction>
                            </MessageCase>
                            <MessageCase>
                                <ReceiveMessage id="Error">
                                    <VariableDefinition id="Resource" path="Resource" />
                                </ReceiveMessage>
                                <BlockAction>
                                    <Terminate success="false">
                                        <Log variableId="Resource" />
                                    </Terminate>
                                </BlockAction>
                            </MessageCase>
                        </SwitchOnMessage>
                    </Switch>
                </Block>
            </Blocks>
            <AlertBlocks>
                <AlertBlock timeout="300" MessageId="ZebraTcpResult" timeoutAlertId="ZebraTcpTimeout" operationIdSource="ConnectSends">
                    <SuccessCase>
                        <Enumeration>
                            <Value>Success</Value>
                        </Enumeration>
                    </SuccessCase>
                    <FailureCase>
                        <Enumeration>
                            <Value>Failure</Value>
                        </Enumeration>
                    </FailureCase>
                </AlertBlock>
            </AlertBlocks>
        </Transaction>

        <Transaction id="Register" hint="TLS connections are only supported for devices that have a TLS certificate stored on the E: drive" >
            <Blocks>
                <Block id="1">
                    <SendMessage id="RegisterAPI">
                        <UserAssignment actionArgName="Host Address" path="Settings/ApiIpAddress" defaultValue="127.0.0.1:9100" hint="Address and port of device to connect to" />
                        <UserAssignment actionArgName="Use TLS" path="Settings/UseTls" defaultValue="false" optional="true" />
                    </SendMessage>
                    <Switch>
                        <SwitchOnMessage>
                            <MessageCase>
                                <ReceiveMessage id="RegisterAPISettings" />
                                <BlockAction>
                                    <Terminate success="true" />
                                </BlockAction>
                            </MessageCase>
                            <MessageCase>
                                <ReceiveMessage id="Error">
                                    <VariableDefinition id="Resource" path="Resource" />
                                </ReceiveMessage>
                                <BlockAction>
                                    <Terminate success="false">
                                        <Log variableId="Resource" />
                                    </Terminate>
                                </BlockAction>
                            </MessageCase>
                        </SwitchOnMessage>
                    </Switch>
                </Block>
            </Blocks>
        </Transaction>

        <Transaction id="ZebraTcpResult"
                     semanticid="ZebraTcp-Data#ZebraTcpResult">
            <Blocks>
                <Block id="1">
                    <ReceiveMessage id="ZebraTcpResult" />
                    <BlockAction>
                        <Terminate success="true" />
                    </BlockAction>
                </Block>
            </Blocks>
        </Transaction>

        <Transaction id="SearchNewDevices">
            <Blocks>
                <Block id="1">
                    <SendMessage id="SearchNewDevices">
                        <UserAssignment actionArgName="IP Range/Subnet Mask" path="Settings/AuxiliaryString1" optional="true" hint="Enter an IP range or subnet mask, if necessary separated by commas (i.e. 127.0.0.1-127.0.0.2,127.0.0.1/24). Otherwise, an empty input will search the /24 mask of the adapter's subnet." />
                    </SendMessage>
                    <Switch>
                        <SwitchOnMessage>
                            <MessageCase>
                                <ReceiveMessage id="Success" />
                                <BlockAction>
                                    <Terminate success="true" />
                                </BlockAction>
                            </MessageCase>
                            <MessageCase>
                                <ReceiveMessage id="Error">
                                    <VariableDefinition id="Resource" path="Resource" />
                                </ReceiveMessage>
                                <BlockAction>
                                    <Terminate success="false">
                                        <Log variableId="Resource" />
                                    </Terminate>
                                </BlockAction>
                            </MessageCase>
                        </SwitchOnMessage>
                    </Switch>
                </Block>
            </Blocks>
        </Transaction>

        <Transaction id="BulkImportDevices">
            <Blocks>
                <Block id="1">
                    <SendMessage id="BulkImportDevices">
                        <UserAssignment actionArgName="CSV File" path="Resource/InputFile" 
                                        hint="CSV format: Column 1 is IP:Port, and Column 2 is True or False for TLS." />
                    </SendMessage>
                    <Switch>
                        <SwitchOnMessage>
                            <MessageCase>
                                <ReceiveMessage id="Success" />
                                <BlockAction>
                                    <Terminate success="true" />
                                </BlockAction>
                            </MessageCase>
                            <MessageCase>
                                <ReceiveMessage id="Error">
                                    <VariableDefinition id="Resource" path="Resource" />
                                </ReceiveMessage>
                                <BlockAction>
                                    <Terminate success="false">
                                        <Log variableId="Resource" />
                                    </Terminate>
                                </BlockAction>
                            </MessageCase>
                        </SwitchOnMessage>
                    </Switch>
                </Block>
            </Blocks>
        </Transaction>
    </Transactions>

    <ProtocolDefinition id="70F1F3CC-FD93-4ADB-87B1-A9186FBDBA0D" name="Zebra TCP">
        <Protocol>
            <Transaction id="InitializeProtocol" hidden="true" />
            <Transaction id="Register" />
            <Transaction id="DiscoverDevices" instanceIdRequired="true" />
            <Transaction id="Unregister" instanceIdRequired="true" />
            <Transaction id="NewDevices" />
            <Transaction id="SearchNewDevices" />
            <Transaction id="BulkImportDevices" />
        </Protocol>

        <Devices>
            <Device id="tcp-zebra-printer">
                <ApiTypeId id="Connect@@ZebraTcpPrinter@@1"/>
                <Transaction id="ZebraTcpCheckIn" />
                <Transaction id="ZebraTcpGetValue" />
                <Transaction id="ZebraTcpPushCommand" />
                <Transaction id="ZebraTcpPushFile"/>
                <Transaction id="ZebraTcpResult" />
                <Transaction id="Ping" />
            </Device>
        </Devices>
    </ProtocolDefinition>


</Domain>