PVM_CODEC

List of ancestors:
messages.h, tppvm.h, tpobj.h,
Files:
tpcodec.cpp
Desc. & Idea Warnings Methods Atributes


Description

This object is designed for message buffering, adding message handling features (including retrieving messages with specified attributes) other process IDs management etc.

Up.gif (1072 bytes)


Warnings

Changes since the last version :

Up.gif (1072 bytes)


Methods

Public:
============= Constructors and Destructors ============
PVM_CODEC (int procType);
~PVM_CODEC ();

============= General functions =============
int startProcess (char *fileName, char **argv, int taskAmount);
int startProcess (char *fileName, char **argv, char *hostName, int taskAmount, int *procPids);
int getProcessType ();

============= Coating functions =============
BOOL getPids (int **pids, int **procTypes, int *pidAmount);
BOOL getParentPids (int **pids, int *pidAmount);
BOOL getChildPids (int **pids, int *pidAmount);
BOOL getApplicationPids (int **pids, int *pidAmount);
int getMaxBufByPid (int procPid);
void setMaxBufByPid (int procPid, int maxAmount);
void setMaxBufByType (int procType, int maxAmount);
void setMaxBufToAll (int maxAmount);
int getRecMsgAmount (int priority);

============= Receiving =============
BOOL retrieveMsgs ();
BOOL getSpecificMsg (int senderPid, int senderType, int priorityLow, int priorityHigh, int msgTag, int msgSpecTag, BYTE **msg);
BOOL peekSpecificMsg (int senderPid, int senderType, int priorityLow, int priorityHigh, int msgTag, int msgSpecTag, BYTE **msg);
BOOL getNextRecMsg (int priority, BYTE **msg);
BOOL peekNextRecMsg (int priority, BYTE **msg);
void wasteNextRecMsg (int priority);
void wasteRecMsgs (int priority);
void wasteAllMsgs ();
void* getMsgDataPtr (void *msg);
MSG_COMMON* getMsgInfoPtr (void *msg);
int getMsgTag (void *msg);
int getMsgPriority (void *msg);
int getMsgSenderType (void *msg);
int getMsgSpecTag (void *msg);
int getMsgLen (void *msg);
int getMsgSenderPid (void *msg);
int getMsgContentType (void *msg);
int getMsgDataAmount (void *msg);
BOOL isRecMsg (int priority);

============= Sending =============
BOOL sendTypes (int destProc, int senderType, int priority, int msgTag, int specMsgTag, BYTE type, void *types, int typeAmount);
BOOL multicastTypes (int *destProc, int destProcAmount, int senderType, int priority, int msgTag, int specMsgTag, BYTE type, void *types, int typeAmount);
BOOL sendBytes (int destProc, int senderType, int priority, int msgTag, int specMsgTag, BYTE *lpBytes, int byteAmount);
BOOL multicastBytes (int *destProc, int destProcAmount, int senderType, int priority, int msgTag, int specMsgTag, BYTE *lpBytes, int byteAmount);
BOOL sendTypeMap (int destProc, int senderType, int priority, int msgTag, int specMsgTag, void *lpMap, int mapLen);
BOOL multicastTypeMap (int *destProc, int destProcAmount, int senderType, int priority, int msgTag, int specMsgTag, void *lpMap, int mapLen);
void flushPid (int pid);
void flushAll ();

Protected:
int getPidIndex (int pid);

Private:
void checkMyMsgs ();



PVM_CODEC (int procType);

Initializes internal attributes and then then acts depending on the "procType" value :

Arguments:

procType..................type of process (one of the above)

Returns:

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


~PVM_CODEC ();

Frees all allocated memory. In the current version it carries out no addition action (like telling other process to deregister this task)

Arguments:

none

Returns:

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int startProcess (char *fileName, char **argv, int taskAmount);

This function calls its overloaded predecessor "startProcess". Then according to the value of "processType" it sends a notification message to other tasks.
Type of process :

Arguments:

fileName ................ file name of the executable file
argv .................... standard C argument strings (can be NULL)
taskAmount .............. amount of processes to be started

Returns:

Positive if OK, 0 if some error occured (memory) or PVM return value (see PVM_COVER.html)

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int startProcess (char *fileName, char **argv, char *hostName, int taskAmount, int *procPids);

This function does the same as the function above, but the caller can specify on which machine the process should be started (hostName == "ulab-10").

Arguments:

fileName ................ file name of the executable file
argv .................... standard C argument strings (can be NULL)
hostName ................ name of the host to start processes on
taskAmount .............. amount of processes to be started
procPids ................ array of ints to receive the info about created pids

Returns:

Positive if OK, 0 if some error occured (memory) or PVM return value (see PVM_COVER.html)

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int getProcessType ();

This function decides whether this process is a parent, child or an application.

Arguments:

none

Returns:

One of the following : PROCTYPE_PARENT, PROCTYPE_CHILD, PROCTYPE_APPLICATION.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL getPids (int **pids, int **procTypes, int *pidAmount);

This function returns an array of registered tasks depending on the process type. Type of process and registered tasks :

Arguments:

pids ........ array of process IDs (is allocated here)
procTypes .... array of process type identifiers (above) (is allocated here)
pidAmount ... amount of processes

Returns:

TRUE if there are any processes registered

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL getParentPids (int **pids, int *pidAmount);
BOOL getChildPids (int **pids, int *pidAmount);
BOOL getApplicationPids (int **pids, int *pidAmount);

See function above. Each of these 3 functions return pids of registered tasks of specific type.

Arguments:

pids ........ array of process IDs (is allocated here)
pidAmount ... amount of processes

Returns:

TRUE if there are any processes registered

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int getMaxBufByPid (int procPid);

This function retrieves the maximum amount of messages allowed to buffer to one message. This number can be different for different tasks.

Arguments:

procPid.................pid of the task to get info about

Returns:

The maximum amount of messages to the specified task allowed to buffer to one message.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


void setMaxBufByPid (int procPid, int maxAmount);
void setMaxBufByType (int procType, int maxAmount);
void setMaxBufToAll (int maxAmount);

These functions set the maximum amount of messages allowed to buffer for specific set of tasks. Either to one task, or to all tasks of specified type, or to all tasks.

Arguments:

procPid......................task pid this relies to
procType.....................type of pids this relies to
maxAmount....................the new amount

Returns:

void

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int getRecMsgAmount (int priority);

There are buffers for receiving messages. Each layer in our system has its special priority (for example : PRIORITY_LGA). This function retrieves the amount of messages received to a specific receive buffer.

Arguments:

priority................specifies the layer this info relies to (defined in messages.h)

Returns:

Amount of received messages in one of the buffers.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL retrieveMsgs ();

This function in one of the most important functions in PVM_CODEC. It is designed to retrieve messages from PVM_COVER (eventually unbuffer buffered messages) and place them in an appropriate receive buffer (distinguishing depends on the value of "priority" in message head (e.g. PRIORITY_LGA - all priorities defined in messages.h).

Arguments:

none

Returns:

TRUE if there is any new message. FALSE if there isn't or an error occured.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL getSpecificMsg (int senderPid, int senderType, int priorityLow, int priorityHigh, int msgTag, int msgSpecTag, BYTE **msg);
BOOL peekSpecificMsg (int senderPid, int senderType, int priorityLow, int priorityHigh, int msgTag, int msgSpecTag, BYTE **msg);

These functions do exactly the same as their PVM_COVER equivalents. You can specify "-1" instead of any of the message attributes. (e.g. getSpecificMsg (-1, SENDER_PARENT, -1, -1, MT_PID, 0, msg);)

Arguments:

senderPid ........... process ID of the sender
senderType .............. type of the sending process (see above)
priorityLow ............. lowest priority of the message
priorityHigh ............. highest priority of the message
msgTag .................. message tag
msgSpecTag .............. specific message tag
msg ..................... a place to put the message to (is allocated here)

Returns:

TRUE if the message was successfully retrieved. FALSE if either there is insufficient memory or there is no message in the buffer

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL getNextRecMsg (int priority, BYTE **msg);
BOOL peekNextRecMsg (int priority, BYTE **msg);

Both the above functions retrieve the first message from appropriate receive buffer (specified by "priority"). The first function removes the message from the buffer, the second doesn't.

Arguments:

priority................specified the receive buffer to get message from (defined in messages.h)
msg ........ address of pointer to the retrieved message (is allocated here)

Returns:

TRUE if the appropriate buffer contains any message.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


void wasteNextRecMsg (int priority);
void wasteRecMsgs (int priority);
void wasteAllMsgs ();

Each of the above functions removes a message or messages from some buffers. "wasteAllMsgs" removes all messages from all buffers.

Arguments:

priority................specified the receive buffer to retrieve from (defined in messages.h)

Returns:

void

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


void* getMsgDataPtr (void *msg);

Every message consists of its message head (MSG_COMMON) and message data. This function only returns the pointer to the data part of the message.

Arguments:

msg .......... the message to get data pointer from

Returns:

The pointer to the message data.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


MSG_COMMON* getMsgInfoPtr (void *msg);

This function in fact only converts the specified pointer to pointer to message header struct (MSG_COMMON)

Arguments:

msg .......... the message to get header pointer from

Returns:

The pointer to the message header.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int getMsgTag (void *msg);
int getMsgPriority (void *msg);
int getMsgSenderType (void *msg);
int getMsgSpecTag (void *msg);
int getMsgLen (void *msg);
int getMsgSenderPid (void *msg);
int getMsgContentType (void *msg);
int getMsgDataAmount (void *msg);

Any of these functions return some information retrieved from the message header (MSG_COMMON)

Arguments:

msg .......... the message to retrieve info from

Returns:

The value of requested atribute

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL isRecMsg (int priority);

This function detects presence of a message in a buffer.

Arguments:

priority................specifies the receive buffer (defined in messages.h)

Returns:

TRUE is any message is currently present in the appropriate buffer.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL sendTypes (int destProc, int senderType, int priority, int msgTag, int specMsgTag, BYTE type, void *types, int typeAmount);
BOOL multicastTypes (int *destProc, int destProcAmount, int senderType, int priority, int msgTag, int specMsgTag, BYTE type, void *types, int typeAmount);
BOOL sendBytes (int destProc, int senderType, int priority, int msgTag, int specMsgTag, BYTE *lpBytes, int byteAmount);
BOOL multicastBytes (int *destProc, int destProcAmount, int senderType, int priority, int msgTag, int specMsgTag, BYTE *lpBytes, int byteAmount);
BOOL sendTypeMap (int destProc, int senderType, int priority, int msgTag, int specMsgTag, void *lpMap, int mapLen);
BOOL multicastTypeMap (int *destProc, int destProcAmount, int senderType, int priority, int msgTag, int specMsgTag, void *lpMap, int mapLen);

These function do similar actions as their PVM_COVER equivalents, but instead of direct sending they buffer the messages up to maximum allowed amount of messages in specific sending buffer (see above)

Arguments:

destProc ........ array of process IDs of the destination processes
destProcAmount .. number of destination processes
senderType ...... type of the sending process (see above)
priority ........ priority of the message
msgTag .......... message tag
specMsgTag ...... special message tag (designed for use by a future user)
type ............ destinguishes the data type
types ........... array of constants of the specified data type
typeAmount ...... number of constants in the array
lpMap ........... address of the type map
mapLen .......... length of the type map

Returns:

TRUE if the message was successfully retrieved. FALSE if either there is insufficient memory or there is no message in the specified buffer

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


void flushPid (int pid);

This function sends the contents of the sending buffer identified by pid to the destination.

Arguments:

pid .......... process ID of the process to flush buffer to

Returns:

void

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


void flushAll ();

This function only calls "flushPid" for all registered processes.

Arguments:

none

Returns:

void

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int getPidIndex (int pid);

This function only returns the index of pid as found in "procPid" array.

Arguments:

pid ................. process ID to look for

Returns:

The index of specified ID (returns -1 if not found).

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


void checkMyMsgs ();

This function checks for all msgs that have the priority set to PRIORITY_CODEC and produces them. None of the above layers of our system is expected to call this function, it is called automatically in "retrieveMsgs".

Arguments:

none

Returns:

void

arrow3u.gif (362 bytes) Up.gif (1072 bytes)




Atributes

Public:
BYTE *
recBuffers[PRIORITY_PAMOUNT];
int recBufLens[PRIORITY_PAMOUNT], recMsgAmounts[PRIORITY_PAMOUNT];
int processType;
int *procPids, *procTypes, procAmount;
Protected:
Private:
BYTE **sendBuffers;
int *sendBufLens, *sendMsgAmounts, *maxBufMsgAmounts;



BYTE *recBuffers[PRIORITY_PAMOUNT];

Buffers for receiving messages. Every layer of our system has a separate buffer (which message where is told by the "priority" attribute in MSG_COMMON).

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int recBufLens[PRIORITY_PAMOUNT], recMsgAmounts[PRIORITY_PAMOUNT];

Attributes of the receive buffers

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int processType;

Type of process the PVM_CODEC belongs to. It is set in the constructor and must one of the following : PROCTYPE_PARENT, PROCTYPE_CHILD, PROCTYPE_APPLICATION.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int *procPids, *procTypes, procAmount;

Arrays of process IDs and process types of all registered processes and the amount of registered processes. See getPids for more information.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BYTE ** sendBuffers;

Buffers used for buffering of messages to be sent. There is exactly "procAmount" of these buffers and the amount can be changed in run-time by parent process.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


int *sendBufLens, *sendMsgAmounts, *maxBufMsgAmounts;

Attributes of the sending buffers. The "maxBufMsgAmounts" determines the maximum allowed amount of messages to buffer to one message before sending. This number can be changed freely in run-time and can be different for every registered task.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)