plc/machine.h

00001 /* $Id$
00002     Defines the PLC machine
00003  */
00004 
00005 #ifndef _MACHINE_H
00006 #define _MACHINE_H
00007 
00008 #include "gridlabd.h"
00009 #include "comm.h"
00010 
00011 typedef struct s_data {char *name; PROPERTYTYPE type; void *addr;} *PLCDATA;
00012 typedef int (*PLCINIT)();
00013 /* this structure must match the PLCDEV structure in plc/rt/include/plc.h */
00014 typedef struct {
00015     unsigned int time;
00016     struct {
00017         void (*send)(class machine*,char*,void*,unsigned int);
00018         int (*recv)(class machine*,char *,void*,unsigned int);
00019     } comm;
00020 } PLCDEV;
00021 typedef int (*PLCCODE)(void*,double,PLCDEV*);
00022 extern int load_library(char *, PLCCODE*, PLCINIT*, PLCDATA*);
00023 
00024 class machine {
00025 private:
00026     PLCDATA _data;  
00027     PLCINIT _init;  
00028     PLCCODE _code;  
00029     Queue _link;    
00030     class comm *net;        
00031     int wait;
00032 public:
00033     machine();
00034     ~machine();
00035 public:
00036     void send(Message *msg);
00037     Message *receive(void);
00038 protected:
00039     int compile(char *source);
00040     int init(OBJECT *parent);
00041     int run(double dt);
00042     void connect(comm *ptr);
00043     void deliver(Message *msg);
00044     void send(char *to, void *msg, size_t len=0);
00045 
00046     friend class plc;
00047     friend class comm;
00048 };
00049 
00050 #endif

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy