2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: BaseObj.h /main/5 1998/04/06 13:34:28 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
39 #if (defined(sun) && OSMAJORVERSION <= 5 && OSMINORVERSION <= 3)|| defined(USL) || defined(__uxp__)
40 #include <sys/types.h>
41 #define boolean boolean_t
48 #elif defined(CSRG_BASED)
62 #define STRDUP(string) (string ? strdup(string) : NULL)
63 #define STRCMP(s1, s2) (s1 && s2 ? strcmp(s1, s2) : (s1 ? 1 : -1))
64 #define STRLEN(string) (string ? strlen(string) : 0)
92 ALLOW_DIRECT_ENTRY = 1,
94 EDITABLE_AFTER_CREATE = 4,
95 EDITABLE_DURING_CREATE = 8,
106 MULTI_SELECT_MIN_RANGE,
107 MULTI_SELECT_MAX_RANGE,
111 #define AllowDirectEntry(attr) (attr->Mask & ALLOW_DIRECT_ENTRY)
112 #define IsRequired(attr) (attr->Mask & REQUIRED)
113 #define EditableAfterCreate(attr) (attr->Mask & EDITABLE_AFTER_CREATE)
114 #define EditableDuringCreate(attr) (attr->Mask & EDITABLE_DURING_CREATE)
115 #define EchoInput(attr) (attr->Mask & ECHO_INPUT)
121 Characteristics Mask;
126 char *DisplayDefaultValue;
128 char *ContextualHelp;
129 ValueList ValueListType;
132 // The base class initializes the next 4 variables
134 char **CompiledValueList;
135 char **CompiledDisplayValueList;
136 char **CompiledHelpValueList;
141 typedef int (*ActionHandler) (BaseObj *, char **output, BaseObj *requestor);
145 ActionHandler Handler;
150 char *ContextualHelp;
151 char *AcceleratorText;
153 boolean InputRequired;
157 extern const char *ACTION_NOT_FOUND;
168 Attribute **_attributes;
172 boolean _init_children;
173 boolean _init_attributes;
174 char *_lastActionName;
175 char *_lastActionOutput;
176 int _lastActionStatus;
178 BaseObj(BaseObj *parent,
182 void DeleteFromParent();
183 void DeleteAttribute(const char *ReferenceName);
184 void AddAttribute(const char *ReferenceName,
185 const char *DisplayName = NULL,
186 const char *Help = NULL,
187 const char *ContextualHelp = NULL,
188 Characteristics Mask = OPTIONAL,
189 ValueList ValueListType = NO_LIST,
190 const char *Listing = NULL,
191 const char *Dependancies = NULL,
192 const char *DefaultValue = NULL,
193 const char *DisplayDefaultValue = NULL);
194 void DeleteAction(const char *ReferenceName);
195 void AddAction(ActionHandler Handler,
196 const char *ReferenceName,
197 const char *DisplayName = NULL,
198 const char *Nmemonic = NULL,
199 const char *Help = NULL,
200 const char *ContextualHelp = NULL,
201 boolean InputRequired = false,
202 const char *AcceleratorText = NULL,
203 const char *Accelerator = NULL,
204 const char *Dependancies = NULL);
206 // Derived classes should redefine these functions
207 virtual void InitChildren() { _children = NULL; _numChildren = 0; }
208 virtual void InitDetails() { }
209 virtual void LoadAttributes(int /*n_attrs*/, Attribute ** /*attrs*/) { }
210 virtual void InitDisplayName() { }
212 // These messages are sent to all parents
213 virtual void NotifyCreate(BaseObj *) { } ;
214 virtual void NotifyDelete(BaseObj *) { } ;
218 virtual ~BaseObj(); // destructor
220 boolean HasAttribute(Attribute *action);
221 boolean HasAttribute(const char *ReferenceName);
222 boolean HasAttribute(const char *ReferenceName, Attribute **action);
223 boolean HasAction(Action *action);
224 boolean HasAction(const char *ReferenceName);
225 boolean HasAction(const char *ReferenceName, Action **action);
226 boolean SendAction(Action *action,
227 BaseObj *requestor = NULL);
228 boolean SendAction(const char *ReferenceName,
229 BaseObj *requestor = NULL);
231 char * LastActionName() { return _lastActionName; }
232 char * LastActionOutput() { return _lastActionOutput; }
233 int LastActionStatus() { return _lastActionStatus; }
235 const char * Name() { return _name; }
236 char * DisplayName();
238 char * AttributeValue(char *ReferenceName);
239 BaseObj * Parent() { return _parent; }
240 const int NumActions() { return _numActions; }
241 const int NumAttributes() { return _numAttributes; }
242 Action **Actions() { return _actions; }
243 Attribute **Attributes() { return _attributes; }
244 BaseObj ** Children();
246 void ReadAttributes();
247 void UpdateChildren();
248 void UpdateDetails();
249 void DeleteChildren();
250 void SetInitChildren() { _init_children = true; }
252 int RunCommand(const char *command,
253 char **std_out = NULL,
254 char **std_err = NULL);
256 // These are for children
257 BaseObj ** Siblings();
261 void Error(const char *message);
263 // Dumps object to stdout
264 void Dump(boolean verbose = false,
266 // Dumps object heirarchy to stdout
267 void DumpHierarchy(boolean verbose = false,
270 virtual const char *const ObjectClassName() { return "BaseObj"; }