00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "converse.h"
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <stdio.h>
00021 #include <netinet/in.h>
00022
00023
00024 class PythonIterator {
00025
00026
00027
00028
00029
00030
00031 public:
00032
00033 virtual int size() {return sizeof(*this);};
00034
00035
00036
00037
00038 virtual char *pack() {
00039 void *memory = malloc(size());
00040 memcpy (memory, (void*)this, size());
00041 return (char *)memory;
00042 };
00043
00044
00045 virtual void unpack() {};
00046 };
00047
00048
00049
00050
00051
00052 class PythonAbstract {
00053 public:
00054
00055
00056 CmiUInt4 magic;
00057
00058 bool isFinished();
00059 bool isExecute();
00060 bool isPrint();
00061 void unpack();
00062 };
00063
00064
00065
00066
00067 class PythonExecute : private PythonAbstract {
00068 friend class PythonObject;
00069 friend class CpdPythonGroup;
00070 private:
00071 CmiUInt4 codeLength;
00072 union {
00073 char * code;
00074 char dummy[8];
00075 } code;
00076
00077
00078 union {
00079 char * methodName;
00080 char dummy[8];
00081 } methodName;
00082 CmiUInt4 methodNameLength;
00083 CmiUInt4 infoSize;
00084 union {
00085 PythonIterator *info;
00086 char dummy[8];
00087 } info;
00088
00089
00090
00091
00092 CmiUInt4 interpreter;
00093 unsigned char flags;
00094
00095
00096
00097
00098
00099
00100 static const unsigned char FLAG_PERSISTENT = 0x80;
00101 static const unsigned char FLAG_KEEPPRINT = 0x40;
00102 static const unsigned char FLAG_HIGHLEVEL = 0x20;
00103 static const unsigned char FLAG_ITERATE = 0x10;
00104 static const unsigned char FLAG_WAIT = 0x08;
00105 static const unsigned char FLAG_NOCHECK = 0x04;
00106 public:
00107 static const CmiUInt4 localmagic = 37492037;
00108
00109
00110
00111 PythonExecute(char *_code, bool _persistent=false, bool _highlevel=false, CmiUInt4 _interp=0);
00112 PythonExecute(char *_code, char *_method, PythonIterator *_info, bool _persistent=false, bool _highlevel=false, CmiUInt4 _interp=0);
00113 ~PythonExecute();
00114
00115
00116 void setCode(char *_set);
00117 void setMethodName(char *_set);
00118 void setIterator(PythonIterator *_set);
00119 void setPersistent(bool _set);
00120 void setIterate(bool _set);
00121 void setHighLevel(bool _set);
00122 void setKeepPrint(bool _set);
00123 void setWait(bool _set);
00124 void setInterpreter(CmiUInt4 i) { interpreter = i; };
00125 void setNoCheck(bool _set);
00126
00127 bool isPersistent() { return flags & FLAG_PERSISTENT; };
00128 bool isIterate() { return flags & FLAG_ITERATE; };
00129 bool isHighLevel() { return flags & FLAG_HIGHLEVEL; };
00130 bool isKeepPrint() { return flags & FLAG_KEEPPRINT; };
00131 bool isWait() { return flags & FLAG_WAIT; };
00132 CmiUInt4 getInterpreter() { return interpreter; };
00133 bool isNoCheck() { return flags & FLAG_NOCHECK; };
00134
00135 int size();
00136 char *pack();
00137 void unpack();
00138
00139 void print();
00140 };
00141
00142 class PythonPrint : private PythonAbstract {
00143 friend class PythonObject;
00144 private:
00145 CmiUInt4 interpreter;
00146 unsigned char flags;
00147
00148
00149
00150
00151 static const unsigned char FLAG_WAIT = 0x80;
00152 static const unsigned char FLAG_KILL = 0x40;
00153 public:
00154 static const CmiUInt4 localmagic = 989370215;
00155 PythonPrint(CmiUInt4 _interp, bool Wait=true, bool Kill=false);
00156
00157 void setWait(bool _set);
00158 bool isWait() { return flags & FLAG_WAIT; };
00159
00160 void setKill(bool _set);
00161 bool isKill() { return flags & FLAG_KILL; };
00162
00163
00164 int size() { return sizeof(*this); };
00165 char *pack() { magic = htonl(magic);
00166 return (char *)this; };
00167 void unpack() { interpreter = ntohl(interpreter); }
00168
00169 void print();
00170 };
00171
00172 class PythonFinished : private PythonAbstract {
00173 friend class PythonObject;
00174 private:
00175 CmiUInt4 interpreter;
00176 unsigned char flags;
00177
00178
00179
00180 static const unsigned char FLAG_WAIT = 0x80;
00181 public:
00182 static const CmiUInt4 localmagic = 738963580;
00183 PythonFinished(CmiUInt4 _interp, bool Wait=true);
00184
00185 void setWait(bool _set);
00186 bool isWait() { return flags & FLAG_WAIT; };
00187
00188 int size() { return sizeof(*this); };
00189 char *pack() { magic = htonl(magic);
00190 return (char *)this; };
00191 void unpack() { interpreter = ntohl(interpreter); }
00192
00193 void print();
00194 };