source: main/trunk/greenstone2/runtime-src/src/recpt/configaction.cpp@ 22822

Last change on this file since 22822 was 22822, checked in by ak19, 14 years ago

Further changes for ticket 152 (movable collectdir), to get server.exe to load all the collections in a non-standard collectdirectory. Previously the code read in collections in any collecthome property listed in a section OTHER THAN the default [gsdl] section of gli/llssite.cfg. Adjusted the code to handle a non-standard collecthome value specified in the [gsdl] section itself.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
RevLine 
[4290]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
[4401]29#ifdef GSDL_LOCAL_LIBRARY
30// for PostMessage()
31# include <windows.h>
32#endif
33
[22677]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
[4290]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
[4373]59 -- kill - if running as the local library this will kill the server
[4290]60 */
61 arg_ainfo.shortname = "cmd";
62 arg_ainfo.longname = "config command";
63 arg_ainfo.multiplechar = true;
64 arg_ainfo.defaultstatus = cgiarginfo::weak;
[7441]65 arg_ainfo.argdefault = g_EmptyText;
[4290]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
[22822]95 } else if ((args["cmd"] == "restart")) {
96 textout << "configured for restart\n";
[22677]97#ifdef GSDL_LOCAL_LIBRARY
98 HWND gw = FindWindow("Greenstone Digital Library Software",
99 "Greenstone Digital Library Software");
100 PostMessage(gw, WM_RESTART, 0, 0);
101#endif
[4373]102 } else if (args["cmd"] == "kill") {
[4401]103 textout << "killed\n";
104#ifdef GSDL_LOCAL_LIBRARY
105 HWND gw = FindWindow("Greenstone Digital Library Software",
106 "Greenstone Digital Library Software");
107 PostMessage(gw, WM_DESTROY, 0, 0);
108#endif
[4290]109 }
110
111 return true;
112}
113
114
115// create and initialize a new collection server and
116// add it to the null protocol.
117void configaction::create_colservr (const text_t &collection, ostream &logout) {
118
[4340]119 // just in case we're adding a collection that already exists
120 recpt->uncache_collection(collection);
121
[4290]122 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
123 recptprotolistclass::iterator rprotolist_here = protos->begin();
124 recptprotolistclass::iterator rprotolist_end = protos->end();
125 while (rprotolist_here != rprotolist_end) {
126 comerror_t err = noError;
127 if ((*rprotolist_here).p != NULL) {
128 if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
129 // create collection server and add it to nullproto
[16321]130 (*rprotolist_here).p->add_collection(collection, recpt, gsdlhome, collecthome, gsdlhome);
[4290]131 // re-initialize the null protocol
132 if (!(*rprotolist_here).p->init(err, logout)) {
133 logout << "configaction::create_colservr: nullproto init failed\n";
134 }
135 return;
136 }
137 }
[9620]138 ++rprotolist_here;
[4290]139 }
140
141 logout << "configaction::create_colservr: no valid nullproto found\n";
142}
143
144// delete a collection server from the null protocol
145void configaction::remove_colservr (const text_t &collection, ostream &logout) {
146
147 recpt->uncache_collection(collection);
148
149 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
150 recptprotolistclass::iterator rprotolist_here = protos->begin();
151 recptprotolistclass::iterator rprotolist_end = protos->end();
152 while (rprotolist_here != rprotolist_end) {
153 comerror_t err = noError;
154 if ((*rprotolist_here).p != NULL) {
155 if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
156 (*rprotolist_here).p->remove_collection(collection, logout);
157 return;
158 }
159 }
[9620]160 ++rprotolist_here;
[4290]161 }
162
163 logout << "configaction::create_colserver: no valid nullproto found\n";
164}
Note: See TracBrowser for help on using the repository browser.