1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 #ifndef _NodeDefinition_h
14 #define _NodeDefinition_h
15 
16 
17 #include <Xm/Xm.h>
18 
19 #include "DXStrings.h"
20 #include "Dictionary.h"
21 #include "Definition.h"
22 #include "SIAllocatorDictionary.h" 	// For SIAllocator typedef
23 #include "CDBAllocatorDictionary.h" 	// For CDBAllocator typedef
24 #include "Cacheability.h"
25 
26 //
27 // Class name definition:
28 //
29 //
30 #define ClassNodeDefinition	"NodeDefinition"
31 
32 //
33 // Forward definitions
34 //
35 class Node;
36 class Definition;
37 class Network;
38 class StandIn;
39 class ConfigurationDialog;
40 class Dictionary;
41 class ParameterDefinition;
42 class Parameter;
43 
44 extern Dictionary *theNodeDefinitionDictionary;
45 
46 //
47 // NodeDefinition class definition:
48 //
49 class NodeDefinition : public Definition
50 {
51   private:
52     //
53     // Private member data:
54     //
55 
56     boolean uiLoadedOnly;	// Was this definition only loaded by the ui
57 
58   protected:
59     //
60     // Protected member data:
61     //
62     List	inputDefs;	// List of input parameter definitions.
63     List	outputDefs; 	// List of output parameter definitions.
64     Symbol	category;
65     long	mdf_flags;	// Bits representing FLAGS statement in mdf.
66     char	*description;	// A short description
67     int		input_repeats;	// The last n inputs are repeatable
68     int		output_repeats;	// the last n outputs are repeatable
69     char	*loadFile;	// Name of file containing loadable object
70     char	*outboardCommand;	// Name of executable file.
71     char	*outboardHost;
72 
73     boolean	userTool;  	// TRUE if defined by a user .mdf file and
74 			   	// defaults to TRUE
75 
76     boolean	writeableCacheability;   // Is the cacheability of this type of
77 					// node modifyable
78     Cacheability defaultCacheability;    // Is this module cached by default
79 
addIODef(List * l,ParameterDefinition * pd)80     virtual boolean addIODef(List *l, ParameterDefinition *pd)
81 	    	{ return l->appendElement((void*)pd); }
82 
83     //
84     // Increment this number to generate numbers for instances
85     // of the type that is being defined.
86     //
87     int		nodeInstanceNumbers;
88 
89     //
90     // Get the dictionary for this class.
91     // Must be defined by the derived classes
92     //
93 
94     //
95     // Returns the StandIn allocator for this node.
96     //
97     virtual SIAllocator getSIAllocator();
98 
99     //
100     // Returns the Configuration dialog box allocator for this node.
101     //
102     virtual CDBAllocator getCDBAllocator();
103 
104     //
105     // Allocate a new Node of the corresponding type.
106     //
107     virtual Node *newNode(Network *net, int instance = -1);
108 
109     //
110     // Get the MDF header (stuff before the INPUT/OUTPUT statements) for this
111     // NodeDefinition.
112     // The returned string must be delete by the caller.
113     //
114     char *getMDFHeaderString();
115     //
116     // Get the list of INPUT/OUTPUT lines in the MDF and the REPEAT if any
117     // The returned string must be delete by the caller.
118     //
119     char *getMDFParametersString(boolean inputs);
120 
121     //
122     // Set/clear one of the this->mdf_flag bits.
123     //
124     void setMDFFlag(boolean val, long flag);
125 
126 
127   public:
128     //
129     // Reset all the instance numbers in a dictionary of definitions.
130     //
131     static void ResetInstanceNumbers(Dictionary *d);
132 
133     //
134     // Allocate a new NodeDefinition.
135     // This function is intended to be used as an allocator in
136     // theNDAllocatorDictionary.
137     //
138     static NodeDefinition *AllocateDefinition();
139 
140     //
141     // Constructor:
142     //
143     NodeDefinition();
144 
145     //
146     // Destructor:
147     //
148     ~NodeDefinition();
149 
150     virtual boolean isDerivedFromMacro();
151 
152     //
153     // Instance number manipulations
154     //
newInstanceNumber()155     int 	newInstanceNumber() { return ++nodeInstanceNumbers; }
setNextInstance(int inst)156     void	setNextInstance(int inst) { nodeInstanceNumbers = inst - 1; }
getCurrentInstance()157     int		getCurrentInstance() { return this->nodeInstanceNumbers; }
158 
159     //
160     // Add an input or output to the list of i/o definitions
161     // (makes a copy of *pd).
162     //
addInput(ParameterDefinition * pd)163     boolean addInput(ParameterDefinition *pd)
164 		{ return addIODef(&inputDefs, pd); };
addOutput(ParameterDefinition * pd)165     boolean addOutput(ParameterDefinition *pd)
166 		{ return addIODef(&outputDefs, pd); };
167 
168     //
169     // Get the number of base (unrepeated) inputs/outputs for this node.
170     //
getInputCount()171     int	getInputCount() { return this->inputDefs.getSize(); }
getOutputCount()172     int	getOutputCount() { return this->outputDefs.getSize(); }
173 
174 
175     //
176     // Get the Nth Input or Output ParameterDefinition.
177     // n is indexed from 1.  If n is greater than the number of input/output
178     // defintions then it is a repeatable parameter, in which case we
179     // account for this to find the correct definition.
180     //
181     ParameterDefinition *getInputDefinition(int n);
182     ParameterDefinition *getOutputDefinition(int n);
183 
184     //
185     // Set/Get the repeat count for inputs/outputs
186     // FIXME: should the set*() be protected/friends.
187     //
setInputRepeatCount(int n)188     void setInputRepeatCount(int n)	{ input_repeats = n; }
getInputRepeatCount()189     int  getInputRepeatCount()		{ return input_repeats ; }
setOutputRepeatCount(int n)190     void setOutputRepeatCount(int n)	{ output_repeats = n; }
getOutputRepeatCount()191     int  getOutputRepeatCount()		{ return output_repeats ; }
isOutputRepeatable()192     boolean isOutputRepeatable() 	{ return output_repeats != 0; }
isInputRepeatable()193     boolean isInputRepeatable()	 	{ return input_repeats != 0; }
194 
195     //
196     // Manipulate the cacheability of the node
197     //
setWriteableCacheability(boolean v)198     void        setWriteableCacheability(boolean v)
199 				{ this->writeableCacheability= v; }
hasWriteableCacheability()200     boolean     hasWriteableCacheability()
201 				{ return this->writeableCacheability;}
setDefaultCacheability(Cacheability c)202     void        setDefaultCacheability(Cacheability c)
203 				{ this->defaultCacheability = c; }
getDefaultCacheability()204     Cacheability getDefaultCacheability()
205 				{ return this->defaultCacheability; }
206 
207     //
208     // Set/Get the category for this node
209     //
setCategory(Symbol c)210     void   setCategory(Symbol c) { category = c ; }
getCategorySymbol()211     Symbol getCategorySymbol() { return this->category; }
getCategoryString()212     const char *getCategoryString()
213 		{ return theSymbolManager->getSymbolString(this->category); }
214 
215     //
216     // Returns the name of executive module that is called to do the work
217     // for this type of node.
218     // Be default, that name is just the name of the Node.
219     //
220     virtual const char *getExecModuleNameString();
221 
222     //
223     // Set/Get short description for this node.
224     //
225     void setDescription(const char* d);
getDescription()226     const char *getDescription()
227 		{ return (description ? (const char*)description : "") ;  }
228 
229     //
230     // Create a new Node (not NodeDefinition) of this type.
231     // Node initialize() is done here and any other boiler plate as required.
232     //
233     virtual Node *createNewNode(Network *net, int instance = -1);
234 
235     //
236     // Called after the NodeDefinition has been parsed out of the mdf file
237     //
finishDefinition()238     virtual void finishDefinition() {}
239 
isAllowedInMacro()240     virtual boolean isAllowedInMacro() { return TRUE; }
241 
242     //
243     // Returns a pointer to the class name.
244     // This is an abstract class, enforce it by making this pure virtual.
245     //
getClassName()246     virtual const char* getClassName() { return ClassNodeDefinition; }
247 
248     //
249     // Get a new parameter for the node n that corresponds to this node
250     // definition. index is the one based index of the input/output parameter.
251     //
252     virtual Parameter *newParameter(ParameterDefinition *pd,
253 						Node *n, int index);
254 
255     void setMDFFlagERR_CONT(boolean val = TRUE);
256     boolean isMDFFlagERR_CONT();
257     void setMDFFlagSWITCH(boolean val = TRUE);
258     boolean isMDFFlagSWITCH();
259     void setMDFFlagPIN(boolean val = TRUE);
260     boolean isMDFFlagPIN();
261     void setMDFFlagSIDE_EFFECT(boolean val = TRUE);
262     boolean isMDFFlagSIDE_EFFECT();
263     void setMDFFlagASYNCHRONOUS(boolean val = TRUE);
264     boolean isMDFFlagASYNCHRONOUS();
265     void setMDFFlagPERSISTENT(boolean val = TRUE);
266     boolean isMDFFlagPERSISTENT();
267     void setMDFFlagREACH(boolean val = TRUE);
268     boolean isMDFFlagREACH();
269     void setMDFFlagREROUTABLE(boolean val = TRUE);
270     boolean isMDFFlagREROUTABLE();
271     void setMDFFlagLOOP(boolean val = TRUE);
272     boolean isMDFFlagLOOP();
273 
274 
275     boolean isOutboard();
276     void setDefaultOutboardHost(const char *host);
getDefaultOutboardHost()277     const char *getDefaultOutboardHost() { return this->outboardHost;}
278     void setOutboardCommand(const char *comand);
getOutboardCommand()279     const char *getOutboardCommand() { return this->outboardCommand;}
280 
281     boolean isDynamicallyLoaded();
282     void setDynamicLoadFile(const char *file);
283     const char *getDynamicLoadFile();
284 
285     //
286     // Get the MDF record for this Node definition.
287     // The returned string must be delete by the caller.
288     //
289     char *getMDFString();
290 
isUserTool()291     boolean isUserTool() { return this->userTool; }
292     void setUserTool(boolean setting = TRUE) { this->userTool = setting; }
293 
294     //
295     // Called after reading in a mdf record for this node definition.
296     // Calls finishDefinition() after installing the CDB and SI allocators
297     // for this node.
298     //
299     void	completeDefinition();
300 
301     boolean isUILoadedOnly();
302     void setUILoadedOnly();
303 
304     //
305     // Add a selectable value for the n'th input.
306     //
307     boolean addInputValueOption(int n, const char *value);
308 
309 
310 };
311 
312 
313 #endif // _NodeDefinition_h
314