7 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8 * Copyright (C) 2009, MinGW Project
11 * Public interface for the package directory management routines;
12 * declares the XML data structures, and their associated class APIs,
13 * which are used to describe packages and their interdependencies.
16 * This is free software. Permission is granted to copy, modify and
17 * redistribute this software, under the provisions of the GNU General
18 * Public License, Version 3, (or, at your option, any later version),
19 * as published by the Free Software Foundation; see the file COPYING
20 * for licensing details.
22 * Note, in particular, that this software is provided "as is", in the
23 * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
24 * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
25 * PARTICULAR PURPOSE. Under no circumstances will the author, or the
26 * MinGW Project, accept liability for any damages, however caused,
27 * arising from the use of this software.
37 # define EXTERN_C extern "C"
43 class pkgXmlNode : public TiXmlElement
45 /* A minimal emulation of the wxXmlNode class, founded on
46 * the tinyxml implementation of the TiXmlElement class, and
47 * subsequently extended by application specific features.
52 inline pkgXmlNode( const char* name ):TiXmlElement( name ){}
53 inline pkgXmlNode( const pkgXmlNode& src ):TiXmlElement( src ){}
57 inline const char* GetName()
59 /* Retrieve the identifying name of the XML tag;
60 * tinyxml calls this the element "value"...
64 inline pkgXmlNode* GetParent()
66 /* wxXmlNode provides this equivalant of tinyxml's
69 return (pkgXmlNode*)(Parent());
71 inline pkgXmlNode* GetChildren()
73 /* wxXmlNode provides only this one method to access
74 * the children of an element; it is equivalent to the
75 * FirstChild() method in tinyxml's arsenal.
77 return (pkgXmlNode*)(FirstChild());
79 inline pkgXmlNode* GetNext()
81 /* This is wxXmlNode's method for visiting other children
82 * of an element, after the first found by GetChildren();
83 * it is equivalent to tinyxml's NextSibling().
85 return (pkgXmlNode*)(NextSibling());
87 inline const char* GetPropVal( const char* name, const char* subst )
89 /* tinyxml has no direct equivalent for this wxXmlNode method,
90 * (which substitutes default "subst" text for an omitted property),
91 * but it may be trivially emulated, using the Attribute() method.
93 const char* retval = Attribute( name );
94 return retval ? retval : subst;
97 /* Additional methods specific to the application.
99 inline bool IsElementOfType( const char* tagname )
101 /* Confirm if the owner XML node represents a data element
102 * with the specified "tagname".
104 return strcmp( GetName(), tagname ) == 0;
107 /* The following pair of methods provide an iterator
108 * for enumerating the contained nodes, within the owner,
109 * which themselves exhibit a specified tagname.
111 pkgXmlNode* FindFirstAssociate( const char* tagname );
112 pkgXmlNode* FindNextAssociate( const char* tagname );
114 /* Specific to XML node elements of type "release",
115 * the following pair of methods retrieve the actual name of
116 * the release tarball, and its associated source code tarball,
117 * as they are named on the project download servers.
119 const char* ArchiveName();
120 const char* SourceArchiveName();
125 /* A class implementing a bi-directionally linked list of
126 * "action" descriptors, which is to be associated with the
127 * pkgXmlDocument class, specifying actions to be performed
128 * on the managed software installation.
131 /* Pointers to predecessor and successor in the linked list
132 * comprising the schedule of action items.
137 /* Flags define the specific action associated with this item.
141 /* Criteria for selection of package versions associated with
144 const char* min_wanted;
145 const char* max_wanted;
147 /* Pointer to the XML database entry for the package selected
148 * for processing by this action.
150 pkgXmlNode* selection;
152 /* Method for retrieving packages from a distribution server.
154 void DownloadArchiveFiles( pkgActionItem* );
159 pkgActionItem( pkgActionItem* = NULL, pkgActionItem* = NULL );
161 /* Methods for assembling action items into a linked list.
163 pkgActionItem* Append( pkgActionItem* = NULL );
164 pkgActionItem* Insert( pkgActionItem* = NULL );
166 /* Methods for compiling the schedule of actions.
168 pkgActionItem* GetReference( pkgActionItem& );
169 pkgActionItem* Schedule( unsigned long, pkgActionItem& );
171 /* Methods for defining the selection criteria for
172 * packages to be processed.
174 const char* SetRequirements( pkgXmlNode* );
175 pkgXmlNode* SelectIfMostRecentFit( pkgXmlNode* );
177 /* Method specifying where downloaded packages are stored.
179 const char* ArchivePath();
181 /* Method for processing all scheduled actions.
186 class pkgXmlDocument : public TiXmlDocument
188 /* Minimal emulation of the wxXmlDocument class, founded on
189 * the tinyxml implementation of the TiXmlDocument class.
194 inline pkgXmlDocument( const char* name )
196 /* tinyxml has a similar constructor, but unlike wxXmlDocument,
197 * it DOES NOT automatically load the document; force it.
201 /* Always begin with an empty actions list.
210 /* tinyxml doesn't have this, but instead provides a complementary
211 * `Error()' indicator, so to simulate `IsOk()'...
215 inline pkgXmlNode* GetRoot()
217 /* This is wxXmlDocument's method for locating the document root;
218 * it is equivalent to tinyxml's RootElement() method.
220 return (pkgXmlNode *)(RootElement());
224 /* Properties specifying the schedule of actions.
226 unsigned long request;
227 pkgActionItem* actions;
229 /* Method to synchronise the state of the local package manifest
230 * with the master copy held on the distribution server.
232 void SyncRepository( const char*, pkgXmlNode* );
235 /* Method to merge content from repository-specific package lists
236 * into the central XML package database.
238 pkgXmlNode* BindRepositories( bool );
240 /* Method to locate the XML database entry for a named package.
242 pkgXmlNode* FindPackageByName( const char*, const char* = NULL );
244 /* Method to resolve the dependencies of a specified package,
245 * by walking the chain of references specified by "requires"
246 * elements in the respective package database entries.
248 void ResolveDependencies( pkgXmlNode*, pkgActionItem* = NULL );
250 /* Methods for compiling a schedule of actions.
252 void Schedule( unsigned long, const char* );
253 pkgActionItem* Schedule( unsigned long, pkgActionItem&, pkgActionItem* = NULL );
255 /* Method to execute a sequence of scheduled actions.
257 inline void ExecuteActions(){ actions->Execute(); }
260 EXTERN_C const char *xmlfile( const char*, const char* = NULL );
261 EXTERN_C int has_keyword( const char*, const char* );
264 bool match_if_explicit( const char *value, const char *proto )
266 /* Helper to compare a pair of "C" strings for equality,
267 * accepting NULL as a match for anything.
269 return (value == NULL) || (proto == NULL) || (strcmp( value, proto ) == 0);
272 #endif /* PKGBASE_H: $RCSfile$: end of file */