File: DataToolManager.cc

package info (click to toggle)
metview 5.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 44,932 kB
  • sloc: cpp: 211,811; ansic: 33,467; xml: 3,942; sh: 2,942; yacc: 1,183; fortran: 762; lex: 761; perl: 700; python: 340; f90: 236; makefile: 92
file content (147 lines) | stat: -rw-r--r-- 3,905 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/***************************** LICENSE START ***********************************

 Copyright 2012 ECMWF and INPE. This software is distributed under the terms
 of the Apache License version 2.0. In applying this license, ECMWF does not
 waive the privileges and immunities granted to it by virtue of its status as
 an Intergovernmental Organization or submit itself to any jurisdiction.

 ***************************** LICENSE END *************************************/

#include "DataToolManager.h"
#include "MvServiceTask.h"

int main(int argc,char **argv)
{
	// Set option -debug to true
	// This is needed in order to force the Save Request command
	// to save the hidden parameters too (underscore parameters).
	option opts[] = {"debug","MARS_DEBUG","-debug","1",t_boolean,
			 sizeof(boolean),OFFSET(globals,debug)};

	MvApplication theApp(argc,argv,NULL,&mars,1,opts);

//	DataToolManager vis1("GRIB");
	DataToolManager vis1("ODB_DB");
//	DataToolManager vis2("GEOPOINTS");
//	DataToolManager vis3("NETCDF");

	// The applications don't try to read or write from pool, this
	// should not be done with the new PlotMod.
	vis1.saveToPool(false);

	theApp.run();
}

//-------------------------------------------------------------

DataToolManager::DataToolManager(const char* kw): MvService(kw)
{
//empty
}

void DataToolManager::serve(MvRequest& in,MvRequest& out)
{
cout << "DataToolManager::serve in" << endl;
in.print();

	// Call function to process the request
        DataToolService::Instance().CallDataTool ( in,out );

	return;
}

//--------------------------------------------------------

// Methods for the DataToolService class
//

// --- METHOD:  Instance
//
// --- PURPOSE: Provide access to the singleton
//              DataToolService class 

DataToolService&
DataToolService::Instance()
{
	static DataToolService dataToolServiceInstance_;
	return dataToolServiceInstance_;
}

DataToolService::DataToolService ()
{
	// Empty
}

DataToolService::~DataToolService()
{
	// Empty
}

// --- METHOD:  CallDataTool
//
// --- PURPOSE: Calls DataTool
//
// --- INPUT:   (a) Request containing an action for DataTool to process
void
DataToolService::CallDataTool ( MvRequest& in, MvRequest& out)
{
	// Use system command to start the appropriate DataTool service. 
	// The service will fork, register itself and read the initial request 
	// to be processed. This request is stored in a temporary file whose 
	// filename is passed to the service in the command line argument.

	// Save request to be processed by the appropriate service
	const char* ftemp = marstmp();
	in.save(ftemp);

	// Tell the caller that the request was done
	// The problem here is that the icon will be green even if uPlot
	// can not process the request.
	// WE NEED TO FIND A BETTER SOLUTION!!!!!!!
	out.setVerb("REPLY");
	out("TARGET") = "MetviewUI";   //????????????

	// Start the approriate service
	char cmd[1024];
	/*if ( strcmp(in.getVerb(),"GRIB") == 0 )
	{
		sprintf(cmd,"$metview_command $METVIEW_BIN/GribTool %s -stylesheet $METVIEW_DIR_SHARE/app-defaults/metview.qss&",ftemp);
	}*/

#ifdef METVIEW_EXPERIMENTAL

	if( strcmp(in.getVerb(),"ODB_DB") == 0 )
	{
		sprintf(cmd,"$metview_command $METVIEW_BIN/OdbToolBox %s $METVIEW_QT_APPLICATION_FLAGS &",ftemp);
	}

	system(cmd);
#endif

}

void
DataToolService::endOfTask ( MvTask* task )
{
cout << " END OF CALLDATATOOL " << endl;
	// If error, send a message and return 
	if ( task->getError() != 0 )
	{
		//int i = 0;
		//const char* msg = 0;
		//while ( msg = task->getMessage (i++ ) )
		
//		PlotMod::MetviewError ( "uPlot crashed" );
		cout << "DataTool crashed" << endl;
	}

	// Retrieve the reply request
	MvServiceTask* serviceTask = ( MvServiceTask* ) task;

	MvRequest replyRequest = serviceTask->getReply();
replyRequest.print();

	// Execute the callback procedure
	// Call uPlot
//	MvApplication::callService ( "uPlot", replyRequest, 0 );
}