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