#!/bin/bash
#
# Copyright(c) 2019 ADLINK Technology Limited and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v. 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
# v. 1.0 which is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#
ok=true
for sd in "" "-d1" "-d12" ; do
    for st in "" "-t" ; do
        for sT in "" "-T" ; do
            if [ "$st" = "-t" -o "$sT" = "-T" ] ; then
                maybeV=false
            else
                maybeV=true
            fi
            for sw in "" "-w" ; do
                for pt in "" "-t" ; do
                    for pp in "" "-p" ; do
                        if [ "$sT" = "" -a "$sd" != "" -a \( "$pt" = "-t" -o $maybeV = true \) ] ; then
                            if $ok ; then
                                echo "bin/InitSampleDelivSub $sw $sd $st $sT & bin/InitSampleDelivPub $pt $pp"
                                bin/InitSampleDelivSub $sw $sd $st $sT & spid=$!
                                bin/InitSampleDelivPub $pt $pp
                                wait $spid || ok=false
                            fi
                            if $ok ; then
                                echo "bin/InitSampleDelivPub $pt $pp & sleep 2 ; bin/InitSampleDelivSub $sw $sd $st $sT "
                                bin/InitSampleDelivPub $pt $pp & ppid=$!
                                sleep  2
                                bin/InitSampleDelivSub $sw $sd $st $sT & spid=$!
                                wait $spid || ok=false
                                wait
                            fi
                        fi
                    done
                done
            done
        done
    done
done
