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
44 #elif defined(linux) || defined(CSRG_BASED)
59 #define STRDUP(string) (string ? strdup(string) : NULL)
60 #define STRCMP(s1, s2) (s1 && s2 ? strcmp(s1, s2) : (s1 ? 1 : -1))
61 #define STRLEN(string) (string ? strlen(string) : 0)
89 ALLOW_DIRECT_ENTRY = 1,
91 EDITABLE_AFTER_CREATE = 4,
92 EDITABLE_DURING_CREATE = 8,
103 MULTI_SELECT_MIN_RANGE,
104 MULTI_SELECT_MAX_RANGE,
108 #define AllowDirectEntry(attr) (attr->Mask & ALLOW_DIRECT_ENTRY)
109 #define IsRequired(attr) (attr->Mask & REQUIRED)
110 #define EditableAfterCreate(attr) (attr->Mask & EDITABLE_AFTER_CREATE)
111 #define EditableDuringCreate(attr) (attr->Mask & EDITABLE_DURING_CREATE)
112 #define EchoInput(attr) (attr->Mask & ECHO_INPUT)
118 Characteristics Mask;
123 char *DisplayDefaultValue;
125 char *ContextualHelp;
126 ValueList ValueListType;
129 // The base class initializes the next 4 variables
131 char **CompiledValueList;
132 char **CompiledDisplayValueList;
133 char **CompiledHelpValueList;
138 typedef int (*ActionHandler) (BaseObj *, char **output, BaseObj *requestor);
142 ActionHandler Handler;
147 char *ContextualHelp;
148 char *AcceleratorText;
150 boolean InputRequired;
154 extern const char *ACTION_NOT_FOUND;
165 Attribute **_attributes;
169 boolean _init_children;
170 boolean _init_attributes;
171 char *_lastActionName;
172 char *_lastActionOutput;
173 int _lastActionStatus;
175 BaseObj(BaseObj *parent,
179 void DeleteFromParent();
180 void DeleteAttribute(const char *ReferenceName);
181 void AddAttribute(const char *ReferenceName,
182 const char *DisplayName = NULL,
183 const char *Help = NULL,
184 const char *ContextualHelp = NULL,
185 Characteristics Mask = OPTIONAL,
186 ValueList ValueListType = NO_LIST,
187 const char *Listing = NULL,
188 const char *Dependancies = NULL,
189 const char *DefaultValue = NULL,
190 const char *DisplayDefaultValue = NULL);
191 void DeleteAction(const char *ReferenceName);
192 void AddAction(ActionHandler Handler,
193 const char *ReferenceName,
194 const char *DisplayName = NULL,
195 const char *Nmemonic = NULL,
196 const char *Help = NULL,
197 const char *ContextualHelp = NULL,
198 boolean InputRequired = false,
199 const char *AcceleratorText = NULL,
200 const char *Accelerator = NULL,
201 const char *Dependancies = NULL);
203 // Derived classes should redefine these functions
204 virtual void InitChildren() { _children = NULL; _numChildren = 0; }
205 virtual void InitDetails() { }
206 virtual void LoadAttributes(int /*n_attrs*/, Attribute ** /*attrs*/) { }
207 virtual void InitDisplayName() { }
209 // These messages are sent to all parents
210 virtual void NotifyCreate(BaseObj *) { } ;
211 virtual void NotifyDelete(BaseObj *) { } ;
215 virtual ~BaseObj(); // destructor
217 boolean HasAttribute(Attribute *action);
218 boolean HasAttribute(const char *ReferenceName);
219 boolean HasAttribute(const char *ReferenceName, Attribute **action);
220 boolean HasAction(Action *action);
221 boolean HasAction(const char *ReferenceName);
222 boolean HasAction(const char *ReferenceName, Action **action);
223 boolean SendAction(Action *action,
224 BaseObj *requestor = NULL);
225 boolean SendAction(const char *ReferenceName,
226 BaseObj *requestor = NULL);
228 char * LastActionName() { return _lastActionName; }
229 char * LastActionOutput() { return _lastActionOutput; }
230 int LastActionStatus() { return _lastActionStatus; }
232 const char * Name() { return _name; }
233 char * DisplayName();
235 char * AttributeValue(char *ReferenceName);
236 BaseObj * Parent() { return _parent; }
237 const int NumActions() { return _numActions; }
238 const int NumAttributes() { return _numAttributes; }
239 Action **Actions() { return _actions; }
240 Attribute **Attributes() { return _attributes; }
241 BaseObj ** Children();
243 void ReadAttributes();
244 void UpdateChildren();
245 void UpdateDetails();
246 void DeleteChildren();
247 void SetInitChildren() { _init_children = true; }
249 int RunCommand(const char *command,
250 char **std_out = NULL,
251 char **std_err = NULL);
253 // These are for children
254 BaseObj ** Siblings();
258 void Error(const char *message);
260 // Dumps object to stdout
261 void Dump(boolean verbose = false,
263 // Dumps object heirarchy to stdout
264 void DumpHierarchy(boolean verbose = false,
267 virtual const char *const ObjectClassName() { return "BaseObj"; }