| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#ifndef VMTMPFIL_H |
| 35 |
#define VMTMPFIL_H |
| 36 |
|
| 37 |
#include "t3std.h" |
| 38 |
#include "vmtype.h" |
| 39 |
#include "vmglob.h" |
| 40 |
#include "vmobj.h" |
| 41 |
#include "vmundo.h" |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
struct vm_tmpfil_ext |
| 60 |
{ |
| 61 |
|
| 62 |
static vm_tmpfil_ext *alloc_ext( |
| 63 |
VMG_ class CVmObjTemporaryFile *self, const char *filename); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
char filename[1]; |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
class CVmObjTemporaryFile: public CVmObject |
| 82 |
{ |
| 83 |
friend class CVmMetaclassTemporaryFile; |
| 84 |
|
| 85 |
public: |
| 86 |
|
| 87 |
static class CVmMetaclass *metaclass_reg_; |
| 88 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 89 |
|
| 90 |
|
| 91 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 92 |
{ |
| 93 |
|
| 94 |
return (meta == metaclass_reg_ |
| 95 |
|| CVmObject::is_of_metaclass(meta)); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
static int is_tmpfil_obj(VMG_ vm_obj_id_t obj) |
| 100 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
const char *get_fname() const |
| 107 |
{ |
| 108 |
const char *f = get_ext()->filename; |
| 109 |
return f[0] != 0 ? f : 0; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 114 |
uint argc); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 121 |
const uchar **pc_ptr, uint *argc, |
| 122 |
vm_prop_id_t prop) |
| 123 |
{ |
| 124 |
return CVmObject:: |
| 125 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
void notify_delete(VMG_ int in_root_set); |
| 130 |
|
| 131 |
|
| 132 |
void set_prop(VMG_ class CVmUndo *undo, |
| 133 |
vm_obj_id_t self, vm_prop_id_t prop, const vm_val_t *val); |
| 134 |
|
| 135 |
|
| 136 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 137 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
void notify_new_savept() { } |
| 144 |
|
| 145 |
|
| 146 |
void apply_undo(VMG_ struct CVmUndoRecord *rec); |
| 147 |
|
| 148 |
|
| 149 |
void discard_undo(VMG_ struct CVmUndoRecord *); |
| 150 |
|
| 151 |
|
| 152 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 153 |
|
| 154 |
|
| 155 |
void mark_refs(VMG_ uint) { } |
| 156 |
|
| 157 |
|
| 158 |
void remove_stale_weak_refs(VMG0_) { } |
| 159 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 160 |
|
| 161 |
|
| 162 |
void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz); |
| 163 |
|
| 164 |
|
| 165 |
void reload_from_image(VMG_ vm_obj_id_t self, |
| 166 |
const char *ptr, size_t siz); |
| 167 |
|
| 168 |
|
| 169 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 170 |
|
| 171 |
|
| 172 |
void save_to_file(VMG_ class CVmFile *fp); |
| 173 |
|
| 174 |
|
| 175 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 176 |
class CVmFile *fp, class CVmObjFixup *fixups); |
| 177 |
|
| 178 |
|
| 179 |
int is_changed_since_load() const { return FALSE; } |
| 180 |
|
| 181 |
protected: |
| 182 |
|
| 183 |
vm_tmpfil_ext *get_ext() const { return (vm_tmpfil_ext *)ext_; } |
| 184 |
|
| 185 |
|
| 186 |
void load_image_data(VMG_ const char *ptr, size_t siz); |
| 187 |
|
| 188 |
|
| 189 |
CVmObjTemporaryFile() { ext_ = 0; } |
| 190 |
|
| 191 |
|
| 192 |
CVmObjTemporaryFile(VMG_ const char *fname); |
| 193 |
|
| 194 |
|
| 195 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 196 |
|
| 197 |
|
| 198 |
int getp_getFilename(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 199 |
|
| 200 |
|
| 201 |
int getp_deleteFile(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 202 |
|
| 203 |
|
| 204 |
static int (CVmObjTemporaryFile::*func_table_[])(VMG_ vm_obj_id_t self, |
| 205 |
vm_val_t *retval, uint *argc); |
| 206 |
}; |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
class CVmMetaclassTemporaryFile: public CVmMetaclass |
| 214 |
{ |
| 215 |
public: |
| 216 |
|
| 217 |
const char *get_meta_name() const { return "tempfile/030000"; } |
| 218 |
|
| 219 |
|
| 220 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 221 |
{ |
| 222 |
new (vmg_ id) CVmObjTemporaryFile(); |
| 223 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 228 |
{ |
| 229 |
new (vmg_ id) CVmObjTemporaryFile(); |
| 230 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 235 |
{ return CVmObjTemporaryFile::create_from_stack(vmg_ pc_ptr, argc); } |
| 236 |
|
| 237 |
|
| 238 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 239 |
const uchar **pc_ptr, uint *argc, |
| 240 |
vm_prop_id_t prop) |
| 241 |
{ |
| 242 |
return CVmObjTemporaryFile:: |
| 243 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 244 |
} |
| 245 |
}; |
| 246 |
|
| 247 |
#endif |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
VM_REGISTER_METACLASS(CVmObjTemporaryFile) |