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

Last change on this file since 21752 was 16321, checked in by davidb, 16 years ago

Introduction of 'collecthome' to support collections outside of 'gsdlhome'

  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
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
34configaction::configaction () {
35
36 recpt = NULL;
37
38 cgiarginfo arg_ainfo;
39 arg_ainfo.shortname = "a";
40 arg_ainfo.longname = "action";
41 arg_ainfo.multiplechar = true;
42 arg_ainfo.defaultstatus = cgiarginfo::weak;
43 arg_ainfo.argdefault = "config";
44 arg_ainfo.savedarginfo = cgiarginfo::must;
45 argsinfo.addarginfo (NULL, arg_ainfo);
46
47 /*
48 The cmd argument may be one of the following:
49 -- release-collection - release the collection specified by the "c"
50 argument
51 -- add-collection - add and configure a collection server for the
52 collection specified by the "c" argument
53 -- kill - if running as the local library this will kill the server
54 */
55 arg_ainfo.shortname = "cmd";
56 arg_ainfo.longname = "config command";
57 arg_ainfo.multiplechar = true;
58 arg_ainfo.defaultstatus = cgiarginfo::weak;
59 arg_ainfo.argdefault = g_EmptyText;
60 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
61 argsinfo.addarginfo (NULL, arg_ainfo);
62}
63
64configaction::~configaction () {
65}
66
67void configaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
68 response_t &response, text_t &response_data,
69 ostream &logout) {
70 response = content;
71 response_data = "text/html";
72}
73
74bool configaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
75 browsermapclass *browsers, displayclass &disp,
76 outconvertclass &outconvert, ostream &textout,
77 ostream &logout) {
78
79 if (recpt == NULL) return false;
80
81 if ((args["cmd"] == "add-collection") && (!args["c"].empty())) {
82 create_colservr(args["c"], logout);
83 textout << "configured add-collection\n";
84
85 } else if ((args["cmd"] == "release-collection") && (!args["c"].empty())) {
86 remove_colservr(args["c"], logout);
87 textout << "configured release-collection\n";
88
89 } else if (args["cmd"] == "kill") {
90 textout << "killed\n";
91#ifdef GSDL_LOCAL_LIBRARY
92 HWND gw = FindWindow("Greenstone Digital Library Software",
93 "Greenstone Digital Library Software");
94 PostMessage(gw, WM_DESTROY, 0, 0);
95#endif
96 }
97
98 return true;
99}
100
101
102// create and initialize a new collection server and
103// add it to the null protocol.
104void configaction::create_colservr (const text_t &collection, ostream &logout) {
105
106 // just in case we're adding a collection that already exists
107 recpt->uncache_collection(collection);
108
109 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
110 recptprotolistclass::iterator rprotolist_here = protos->begin();
111 recptprotolistclass::iterator rprotolist_end = protos->end();
112 while (rprotolist_here != rprotolist_end) {
113 comerror_t err = noError;
114 if ((*rprotolist_here).p != NULL) {
115 if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
116 // create collection server and add it to nullproto
117 (*rprotolist_here).p->add_collection(collection, recpt, gsdlhome, collecthome, gsdlhome);
118 // re-initialize the null protocol
119 if (!(*rprotolist_here).p->init(err, logout)) {
120 logout << "configaction::create_colservr: nullproto init failed\n";
121 }
122 return;
123 }
124 }
125 ++rprotolist_here;
126 }
127
128 logout << "configaction::create_colservr: no valid nullproto found\n";
129}
130
131// delete a collection server from the null protocol
132void configaction::remove_colservr (const text_t &collection, ostream &logout) {
133
134 recpt->uncache_collection(collection);
135
136 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
137 recptprotolistclass::iterator rprotolist_here = protos->begin();
138 recptprotolistclass::iterator rprotolist_end = protos->end();
139 while (rprotolist_here != rprotolist_end) {
140 comerror_t err = noError;
141 if ((*rprotolist_here).p != NULL) {
142 if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
143 (*rprotolist_here).p->remove_collection(collection, logout);
144 return;
145 }
146 }
147 ++rprotolist_here;
148 }
149
150 logout << "configaction::create_colserver: no valid nullproto found\n";
151}
Note: See TracBrowser for help on using the repository browser.