/* 
 * File:   requests.h
 * Author: msach
 *
 * Created on September 16, 2011, 3:11 PM
 */

#ifndef REQUESTS_H
#define	REQUESTS_H

#include "ProcrContext.h"

typedef struct _InterMasterReqst InterMasterReqst;

//============= Requests ===========
//

//VMS Request is the carrier for Slave to Master requests
// it has an embedded sub-type request that is pulled out
// inside the plugin's request handler
enum VMSReqstType   //For Slave->Master requests
 { 
   semantic = 1,    //avoid starting enums at 0, for debug reasons
   createReq,
   dissipate,
   VMSSemantic      //goes with VMSSemReqst below
 };

struct _VMSReqst
 {
   enum VMSReqstType  reqType;//used for dissipate and in future for IO requests
   void              *semReqData;

   VMSReqst *nextReqst;
 };
//VMSReqst

//This is a sub-type of Slave->Master requests.
// It's for Slaves to invoke built-in VMS-core functions that have language-like
// behavior.
enum VMSSemReqstType   //These are equivalent to semantic requests, but for
 {                     // VMS's services available directly to app, like OS
   createProbe = 1,    // and probe services -- like a VMS-wide built-in lang
   openFile,
   otherIO
 };

typedef struct
 { enum VMSSemReqstType reqType;
   VirtProcr           *requestingPr;
   char                *nameStr;  //for create probe
 }
VMSSemReq;

//These are for Master to Master requests
// They get re-cast to the appropriate sub-type of request
enum InterMasterReqstType    //For Master->Master
 {
   destVMSCore = 1,          //avoid starting enums at 0, for debug reasons
   destPlugin
 };

struct _InterMasterReqst //Doing a trick to save space & time -- allocate
 {  // space for a sub-type then cast first as InterMaster then as sub-type
   enum InterMasterReqstType  reqType;
   InterMasterReqst *nextReqst;
 };
//InterMasterReqst  (defined above in typedef block)


//These are a sub-type of InterMaster requests.  The inter-master req gets
// re-cast to be of this type, after checking
//This ones for requests between internals of VMS-core.. such as malloc
enum InterVMSCoreReqType   
 {
   transfer_free_ptr = 1     //avoid starting enums at 0, for debug reasons
 };

//Doing a trick to save space & time -- allocate space
// for this, cast first as InterMaster then as this
typedef struct  
 {
   enum InterMasterReqstType  reqType;  //duplicate InterMasterReqst at top
   InterMasterReqst *nextReqst;
   
   enum InterVMSCoreReqType  secondReqType;
   void                     *freePtr;  //pile up fields, add as needed
 } InterVMSCoreReqst;

//This is for requests between plugins on different cores
// Here, after casting, the pluginReq is extracted and handed to plugin
//Doing a trick to save space & time -- allocate space
// for this, cast first as InterMaster then as this
typedef struct  
 {
   enum InterMasterReqstType  reqType;  //copy InterMasterReqst at top
   InterMasterReqst          *nextReqst;
   
   void                      *pluginReq; //plugin will cast to approp type
 } InterPluginReqst;

#endif	/* REQUESTS_H */

