Newsgroups: comp.os.parix
From: kba@hrz.tu-chemnitz.de (Karsten Baensch)
Subject: Re: Mailboxes on a PowerXplorer
Organization: University of Technology Chemnitz, FRG
Date: 20 Dec 95 08:06:03 GMT
Message-ID: <4b8k8n$dme@pyrrhus-f.hrz.tu-chemnitz.de>

e9218@mimas.hts.hsa.nl (T. van der Does) writes:

>Hello,

>Can anyone provide me with an example of sending and receiving with
>mailboxes on a Parsytec PowerXplorer? There are no examples provided
>of the PutMessage and GetMessage commandos in the ~/parix/examples 
>directory.

>Thanks!

>-- 

>CU Later!

>Tames van der Does.

>Fido: 2:285/210.11
>Internet: e9218@hts.hsa.nl

Attention! This is C++-Code!

// Let's assume there is a message dispatcher 'ProcControl' sitting on a
// node of the PowerXplorer, performing a message loop and so waiting for
// any incoming messages with MsgType of 'MSG_TYPE_PROCCONTROLMSGLOOP'. 
// 'AnalyzeMessage' is used to analyze the incoming messages and trigger
// the according actions. The message loop will be stopped when AnalyseMessage
// returns 'FALSE' (0).

CONTROL_RETURNVALUE ProcControl::MessageLoop()
{
    RR_Message_t MyMsg;

    do
    {
        GetMessage(-1, -1, MSG_TYPE_PROCCONTROLMSGLOOP, -1, &MyMsg);
    }
    while(AnalyseMessage(MyMsg));

    return CONTROL_OKAY;
}

// 'somefunction' gets a signal 'SIG_CONTROL_END' on the same node
// (second thread). However. The signal is handled by stopping the
// 'ProcControl::MessageLoop' on this node. (May be the correct
// action to shutdown the system.) To do so, a Message with ReqId
// 'MSG_REQ_PROCCONTROLMSGLOOP', with MsgType 'MSG_TYPE_PROCCONTROLMSGLOOP'
// and with Code 'MSG_CODE_CONTROL_END' is put into the local message box.

bool somefunction()
{
//...
        case SIG_CONTROL_END:
            Debug("Signal SIG_CONTROL_END received.");
            PutMessage(PC_MyProcID, MSG_REQ_PROCCONTROLMSGLOOP, MSG_TYPE_PROCCONTROLMSGLOOP, MSG_CODE_CONTROL_END, -1, NIL, 0);
            return FALSE;
//...
}

// ProcControl::AnalyseMessage returns 'FALSE', when the message contains
// a code of 'MSG_CODE_CONTROL_END'. In all the other cases it returns
// 'TRUE'.

bool ProcControl::AnalyseMessage(RR_Message_t& MyMsg)
{
    switch(MyMsg.Header.Code)
    {
//      ...
        case MSG_CODE_CONTROL_END:
            Debug("Message MSG_CODE_CONTROL_END received.");
            return FALSE;

        default:
            Warning("Unknown message code received!");
            return TRUE;
    }

    return TRUE;
}

//
// And here are the constant definitions:
//

typedef enum
{
    SIG_CONTROL_BASE        = 1000,
    SIG_CONTROL_END         = SIG_CONTROL_BASE + 1
//  ...,
} CONTROL_SIGNAL;

typedef enum
{
    CONTROL_OKAY                =  0,
    CONTROL_RETURNVALUE_BASE    = -10,
    INSUFFICIENT_MEMORY         = CONTROL_RETURNVALUE_BASE - 1
//  ...,
} CONTROL_RETURNVALUE;

typedef enum
{
    MSG_TYPE_BASE                   = MSG_TYPE_USER_START,
//  ...,
    MSG_TYPE_PROCCONTROLMSGLOOP     = MSG_TYPE_BASE + 2
//  ...,
} MSG_TYPE;

typedef enum
{
    MSG_CODE_BASE               = MSG_TYPE_BASE + 100,
    MSG_CODE_CONTROL_END        = MSG_CODE_BASE + 1
//  ...,
} MSG_CODE;

typedef enum
{
    MSG_REQ_BASE                    = MSG_TYPE_BASE + 200,
//  ...,  
    MSG_REQ_PROCCONTROLMSGLOOP      = MSG_REQ_BASE + 2
//  ...,
} MSG_REQUESTS;

Good luck!

Karsten Baensch
--
(  Email: Karsten.Baensch@hrz.tu-chemnitz.de                                ( 
 ) WWW:   http://www.tu-chemnitz.de/~kba/baensch.html                        )
(  Phone: (+49-) 0371/531-1252                                              ( 
 ) Mail:  Technical University, Computing Services, 09107 Chemnitz, Germany  )

