/******************************************************************

  External task for the example Simple.
  threaded integration version for all OS.

  Creator: Telelogic AB
  #clearcase

Copyright by Telelogic AB 1999 - 2002


This Program is owned by Telelogic and is protected by national 
copyright laws and international copyright treaties. Telelogic 
grants you the right to use this Program on one computer or in 
one local computer network at any one time. 
Under this License you may only modify the source code for the purpose 
of adapting it to your environment. You must reproduce and include 
any copyright and trademark notices on all copies of the source code. 
You may not use, copy, merge, modify or transfer the Program except as
provided in this License.
Telelogic does not warrant that the Program will meet your
requirements or that the operation of the Program will be
uninterrupted and error free. You are solely responsible that the
selection of the Program and the modification of the source code 
will achieve your intended results and that the results are actually 
obtained.

*******************************************************************/

#include "scttypes.h"
#include "simple.ifc"

/****+***************************************************************
     Simple example: MyExtTask
********************************************************************/

void MyExtTask1 XPP(( void ))
{
  xSignalNode yInputSignalPtr, yOutputSignalPtr;
  xPrsIdNode MyPrsId;
  SDL_PId MyPId1;
  int i, param;

printf("Task1 started\n");

  /* Get an SDL_PId representing the External Task in the SDL system */
   MyPId1 = xThreadedRegExtTask();

  for(i=1;i<=1;i++) {
    if (i==1) {
      yOutputSignalPtr = xGetSignal(go,pr1[1],MyPId1);
      THREADED_ASSIGN_SDL_SIG_PARAMS(yOutputSignalPtr,go,1,startinstance1);
    } else {
      yOutputSignalPtr = xGetSignal(go,pr1[2],MyPId1);
      THREADED_ASSIGN_SDL_SIG_PARAMS(yOutputSignalPtr,go,1,startinstance2);
    }
    SDL_Output(yOutputSignalPtr, xSigPrioPar(xDefaultPrioSignal) (xIdNode *)0 );
  }

  for(i=1;i<=1;i++) {
    yInputSignalPtr = 0;
    yInputSignalPtr = xThreadedReceiveSDLSig(MyPId1);
    if(yInputSignalPtr->NameNode == ok) {
      THREADED_GET_SDL_SIG_PARAM(yInputSignalPtr,go,1,param);
      printf("Ok received in MyExtTask1 with parameter = %lu\n",
             param);
    }
    xReleaseSignalNotPara(&yInputSignalPtr);
  }
  THREADED_SUSPEND_THREAD
}

void MyExtTask2 XPP(( void ))
{
  xSignalNode yInputSignalPtr, yOutputSignalPtr;
  xPrsIdNode MyPrsId;
  SDL_PId MyPId;
  int i, param;
printf("Task2 started\n");

  MyPId = xThreadedRegExtTask();

  for(i=1;i<=1;i++) {
    if (i==1) {
      yOutputSignalPtr = xGetSignal(go,pr1[2],MyPId);
      THREADED_ASSIGN_SDL_SIG_PARAMS(yOutputSignalPtr,go,1,startinstance2);
    } else {
      yOutputSignalPtr = xGetSignal(go,pr1[2],MyPId);
      THREADED_ASSIGN_SDL_SIG_PARAMS(yOutputSignalPtr,go,1,startinstance2);
    }
    SDL_Output(yOutputSignalPtr, xSigPrioPar(xDefaultPrioSignal) (xIdNode *)0 );
  }

  for(i=1;i<=1;i++) {
    yInputSignalPtr = 0;
    yInputSignalPtr = xThreadedReceiveSDLSig(MyPId);
    if(yInputSignalPtr->NameNode == ok) {

      THREADED_GET_SDL_SIG_PARAM(yInputSignalPtr,go,1,param);
      printf("Ok received in MyExtTask2 with parameter = %lu\n",
             param);
    }
    xReleaseSignalNotPara(&yInputSignalPtr);
  }
  THREADED_SUSPEND_THREAD
}
