root/main/trunk/greenstone2/runtime-src/src/recpt/configaction.cpp @ 22677

Revision 22677, 5.7 KB (checked in by ak19, 10 years ago)

More changes for making the collectdir movable (ticket 152): (1) Changes to GLI code so that llssite and glisite are updated to contain the COLLECTHOME property to tell server.exe where the new collect dir is. (2) server.exe must be told that it needs to restart (so it can read the new collecthome).

  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 * configaction.cpp --
4 * Copyright (C) 2003 DL Consulting Ltd
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26
27#include "configaction.h"
28
29#ifdef GSDL_LOCAL_LIBRARY
30// for PostMessage()
31#  include <windows.h>
32#endif
33
34// constant for restart/reconfigure windows message (same as in w32server/fnord)
35// http://msdn.microsoft.com/en-us/library/ms644931%28v=VS.85%29.aspx on WM_USER
36// (also RegisterWindowMessage Function at http://msdn.microsoft.com/en-us/library/ms644947%28v=VS.85%29.aspx
37// http://msdn.microsoft.com/en-us/library/ms644927%28v=VS.85%29.aspx)
38#define WM_RESTART WM_USER+1
39
40configaction::configaction () {
41
42  recpt = NULL;
43
44  cgiarginfo arg_ainfo;
45  arg_ainfo.shortname = "a";
46  arg_ainfo.longname = "action";
47  arg_ainfo.multiplechar = true;
48  arg_ainfo.defaultstatus = cgiarginfo::weak;
49  arg_ainfo.argdefault = "config";
50  arg_ainfo.savedarginfo = cgiarginfo::must;
51  argsinfo.addarginfo (NULL, arg_ainfo);
52
53  /*
54     The cmd argument may be one of the following:
55     -- release-collection - release the collection specified by the "c"
56        argument
57     -- add-collection - add and configure a collection server for the
58        collection specified by the "c" argument
59     -- kill - if running as the local library this will kill the server
60  */
61  arg_ainfo.shortname = "cmd";
62  arg_ainfo.longname = "config command";
63  arg_ainfo.multiplechar = true;
64  arg_ainfo.defaultstatus = cgiarginfo::weak;
65  arg_ainfo.argdefault = g_EmptyText;
66  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
67  argsinfo.addarginfo (NULL, arg_ainfo);
68}
69
70configaction::~configaction () {
71}
72
73void configaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
74                     response_t &response, text_t &response_data,
75                     ostream &logout) {
76  response = content;
77  response_data = "text/html";
78}
79
80bool configaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
81                  browsermapclass *browsers, displayclass &disp,
82                  outconvertclass &outconvert, ostream &textout,
83                  ostream &logout) {
84
85  if (recpt == NULL) return false;
86
87  if ((args["cmd"] == "add-collection") && (!args["c"].empty())) {
88    create_colservr(args["c"], logout);
89    textout << "configured add-collection\n";
90
91  } else if ((args["cmd"] == "release-collection") && (!args["c"].empty())) {
92    remove_colservr(args["c"], logout);
93    textout << "configured release-collection\n";
94
95  } else if ((args["cmd"] == "restart")) {
96    if(!args["c"].empty()) {
97        remove_colservr(args["c"], logout);
98        textout << "configured release-collection for reconfigure-restart\n";
99    }
100    textout << "reconfigure-restart\n";
101#ifdef GSDL_LOCAL_LIBRARY
102    HWND gw = FindWindow("Greenstone Digital Library Software",
103             "Greenstone Digital Library Software");
104    PostMessage(gw, WM_RESTART, 0, 0);
105#endif
106  } else if (args["cmd"] == "kill") {
107    textout << "killed\n";
108#ifdef GSDL_LOCAL_LIBRARY
109    HWND gw = FindWindow("Greenstone Digital Library Software",
110             "Greenstone Digital Library Software");
111    PostMessage(gw, WM_DESTROY, 0, 0);
112#endif
113  }
114
115  return true;
116}
117
118
119// create and initialize a new collection server and
120// add it to the null protocol.
121void configaction::create_colservr (const text_t &collection, ostream &logout) {
122
123  // just in case we're adding a collection that already exists
124  recpt->uncache_collection(collection);
125
126  recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
127  recptprotolistclass::iterator rprotolist_here = protos->begin();
128  recptprotolistclass::iterator rprotolist_end = protos->end();
129  while (rprotolist_here != rprotolist_end) {
130    comerror_t err = noError;
131    if ((*rprotolist_here).p != NULL) {
132      if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
133    // create collection server and add it to nullproto
134    (*rprotolist_here).p->add_collection(collection, recpt, gsdlhome, collecthome, gsdlhome);
135    // re-initialize the null protocol
136    if (!(*rprotolist_here).p->init(err, logout)) {
137      logout << "configaction::create_colservr: nullproto init failed\n";
138    }
139    return;
140      }
141    }
142    ++rprotolist_here;
143  }
144
145  logout << "configaction::create_colservr: no valid nullproto found\n";
146}
147
148// delete a collection server from the null protocol
149void configaction::remove_colservr (const text_t &collection, ostream &logout) {
150
151  recpt->uncache_collection(collection);
152
153  recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
154  recptprotolistclass::iterator rprotolist_here = protos->begin();
155  recptprotolistclass::iterator rprotolist_end = protos->end();
156  while (rprotolist_here != rprotolist_end) {
157    comerror_t err = noError;
158    if ((*rprotolist_here).p != NULL) {
159      if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
160    (*rprotolist_here).p->remove_collection(collection, logout);
161    return;
162      }
163    }
164    ++rprotolist_here;
165  }
166
167  logout << "configaction::create_colserver: no valid nullproto found\n";
168}
Note: See TracBrowser for help on using the browser.