File: savers.pike

package info (click to toggle)
roxen 1.2beta2-2
  • links: PTS
  • area: contrib
  • in suites: hamm
  • size: 16,948 kB
  • ctags: 8,589
  • sloc: ansic: 89,632; asm: 8,431; sh: 2,915; makefile: 1,787; cpp: 377
file content (112 lines) | stat: -rw-r--r-- 2,537 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* $Id: savers.pike,v 1.6 1997/10/12 21:10:29 grubba Exp $ */
#include <confignode.h>
#include <module.h>

string module_short_name(object m, object cf)
{
  string sn;
  mapping mod;
  int i;
  if(!objectp(m))
    error("module_short_name on non object.\n");

  sn=cf->otomod[ m ];
  mod=cf->modules[ sn ];

  if(!mod) error("No such module!\n");

  if(!mod->copies) return sn+"#0";

  if((i=search(mod->copies, m)) >= 0)
    return sn+"#"+i;

  error("Module not found.\n");
}

inline int is_module(object node)
{
  if(!node) return 1;
  switch(node->type)
  {
   case NODE_MODULE_COPY:
   case NODE_MODULE_MASTER_COPY:
    return 1;
  }
}

void save_module_variable(object o)
{
  object module;
  
  module = o;

  while(!is_module(module))
    module = module->up;

  if(!module)
    module = this_object()->root;

  if(objectp(module->data))
    module->data->set(o->data[VAR_SHORTNAME], o->data[VAR_VALUE]);
  else if(mappingp(module->data) && module->data->master)
    module->data->master->set(o->data[VAR_SHORTNAME], o->data[VAR_VALUE]);
  else if(o->config())
    o->config()->set(o->data[VAR_SHORTNAME], o->data[VAR_VALUE]);
  else
    roxen->set(o->data[VAR_SHORTNAME], o->data[VAR_VALUE]);
      
  if(o->changed) o->change(-o->changed);
}


void save_global_variables(object o)
{
  roxen->store("Variables", roxen->variables, 0, 0);
  roxen->initiate_configuration_port();
  roxen->set_u_and_gid();
  init_logger();
  roxen->initiate_supports();
  roxen->reinit_garber();
  if(o->changed) o->change(-o->changed);
}

void save_module_master_copy(object o, object config)
{
  string s;
  object n;

  roxen->current_configuration = config;
  roxen->store(s=o->data->sname+"#0", o->data->master->query(), 0, o->config());
  o->data->master->start(2, config);
  o->config()->invalidate_cache();
  if(o->changed) o->change(-o->changed);
}

void save_configuration_global_variables(object o, object config)
{
  roxen->store("spider#0", o->config()->variables, 0, o->config());
  if(o->changed) o->change(-o->changed);
  o->config()->start(2, config);
}

void save_configuration(object o, object config)
{
  if(o->changed) o->change(-o->changed);
  config->invalidate_cache();
//o->config()->start(2, config);
}

void save_module_copy(object o, object config)
{
  string s;
  object cf;
  s=module_short_name(o->data, cf=o->config());

  if(!s) error("Fop fip.\n");

  cf->invalidate_cache();
  
  roxen->store(s, o->data->query(), 0, cf);
  if(o->data->start) o->data->start(2, config);
  if(o->changed) o->change(-o->changed);
}