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 libraries 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)
40 #include <sys/types.h>
41 #define boolean boolean_t
45 #include <sys/types.h>
46 #define boolean boolean_t
47 #if defined(__XOPEN_OR_POSIX)
49 #define false _B_FALSE
58 #elif defined(CSRG_BASED)
72 #define STRDUP(string) (string ? strdup(string) : NULL)
73 #define STRCMP(s1, s2) (s1 && s2 ? strcmp(s1, s2) : (s1 ? 1 : -1))
74 #define STRLEN(string) (string ? strlen(string) : 0)
102 ALLOW_DIRECT_ENTRY = 1,
104 EDITABLE_AFTER_CREATE = 4,
105 EDITABLE_DURING_CREATE = 8,
116 MULTI_SELECT_MIN_RANGE,
117 MULTI_SELECT_MAX_RANGE,
121 #define AllowDirectEntry(attr) (attr->Mask & ALLOW_DIRECT_ENTRY)
122 #define IsRequired(attr) (attr->Mask & REQUIRED)
123 #define EditableAfterCreate(attr) (attr->Mask & EDITABLE_AFTER_CREATE)
124 #define EditableDuringCreate(attr) (attr->Mask & EDITABLE_DURING_CREATE)
125 #define EchoInput(attr) (attr->Mask & ECHO_INPUT)
131 Characteristics Mask;
136 char *DisplayDefaultValue;
138 char *ContextualHelp;
139 ValueList ValueListType;
142 // The base class initializes the next 4 variables
144 char **CompiledValueList;
145 char **CompiledDisplayValueList;
146 char **CompiledHelpValueList;
151 typedef int (*ActionHandler) (BaseObj *, char **output, BaseObj *requestor);
155 ActionHandler Handler;
160 char *ContextualHelp;
161 char *AcceleratorText;
163 boolean InputRequired;
167 extern const char *ACTION_NOT_FOUND;
178 Attribute **_attributes;
182 boolean _init_children;
183 boolean _init_attributes;
184 char *_lastActionName;
185 char *_lastActionOutput;
186 int _lastActionStatus;
188 BaseObj(BaseObj *parent,
192 void DeleteFromParent();
193 void DeleteAttribute(const char *ReferenceName);
194 void AddAttribute(const char *ReferenceName,
195 const char *DisplayName = NULL,
196 const char *Help = NULL,
197 const char *ContextualHelp = NULL,
198 Characteristics Mask = OPTIONAL,
199 ValueList ValueListType = NO_LIST,
200 const char *Listing = NULL,
201 const char *Dependancies = NULL,
202 const char *DefaultValue = NULL,
203 const char *DisplayDefaultValue = NULL);
204 void DeleteAction(const char *ReferenceName);
205 void AddAction(ActionHandler Handler,
206 const char *ReferenceName,
207 const char *DisplayName = NULL,
208 const char *Nmemonic = NULL,
209 const char *Help = NULL,
210 const char *ContextualHelp = NULL,
211 boolean InputRequired = false,
212 const char *AcceleratorText = NULL,
213 const char *Accelerator = NULL,
214 const char *Dependancies = NULL);
216 // Derived classes should redefine these functions
217 virtual void InitChildren() { _children = NULL; _numChildren = 0; }
218 virtual void InitDetails() { }
219 virtual void LoadAttributes(int /*n_attrs*/, Attribute ** /*attrs*/) { }
220 virtual void InitDisplayName() { }
222 // These messages are sent to all parents
223 virtual void NotifyCreate(BaseObj *) { } ;
224 virtual void NotifyDelete(BaseObj *) { } ;
228 virtual ~BaseObj(); // destructor
230 boolean HasAttribute(Attribute *action);
231 boolean HasAttribute(const char *ReferenceName);
232 boolean HasAttribute(const char *ReferenceName, Attribute **action);
233 boolean HasAction(Action *action);
234 boolean HasAction(const char *ReferenceName);
235 boolean HasAction(const char *ReferenceName, Action **action);
236 boolean SendAction(Action *action,
237 BaseObj *requestor = NULL);
238 boolean SendAction(const char *ReferenceName,
239 BaseObj *requestor = NULL);
241 char * LastActionName() { return _lastActionName; }
242 char * LastActionOutput() { return _lastActionOutput; }
243 int LastActionStatus() { return _lastActionStatus; }
245 const char * Name() { return _name; }
246 char * DisplayName();
248 char * AttributeValue(char *ReferenceName);
249 BaseObj * Parent() { return _parent; }
250 const int NumActions() { return _numActions; }
251 const int NumAttributes() { return _numAttributes; }
252 Action **Actions() { return _actions; }
253 Attribute **Attributes() { return _attributes; }
254 BaseObj ** Children();
256 void ReadAttributes();
257 void UpdateChildren();
258 void UpdateDetails();
259 void DeleteChildren();
260 void SetInitChildren() { _init_children = true; }
262 int RunCommand(const char *command,
263 char **std_out = NULL,
264 char **std_err = NULL);
266 // These are for children
267 BaseObj ** Siblings();
271 void Error(const char *message);
273 // Dumps object to stdout
274 void Dump(boolean verbose = false,
276 // Dumps object heirarchy to stdout
277 void DumpHierarchy(boolean verbose = false,
280 virtual const char *const ObjectClassName() { return "BaseObj"; }