2 * Copyright 1993 Jeff Hollingsworth. All rights reserved.
7 static char Copyright[] = "@(#) Copyright (c) 1993 Jeff Hollingsowrth\
10 static char rcsid[] = "@(#) $Header: /home/jaw/CVSROOT_20081103/CVSROOT/core/paradynd/src/resource.C,v 1.3 1994/02/24 04:32:36 markc Exp $";
14 * resource.C - handle resource creation and queries.
16 * $Log: resource.C,v $
17 * Revision 1.3 1994/02/24 04:32:36 markc
18 * Changed header files to reflect igen changes. main.C does not look at the number of command line arguments now.
20 * Revision 1.2 1994/02/01 18:46:55 hollings
21 * Changes for adding perfConsult thread.
23 * Revision 1.1 1994/01/27 20:31:41 hollings
24 * Iinital version of paradynd speaking dynRPC igend protocol.
26 * Revision 1.3 1993/07/13 18:30:02 hollings
27 * new include file syntax.
28 * expanded tempName to 255 chars for c++ support.
30 * Revision 1.2 1993/06/08 20:14:34 hollings
31 * state prior to bc net ptrace replacement.
33 * Revision 1.1 1993/03/19 22:45:45 hollings
46 #include "dyninstRPC.SRVR.h"
49 HTable <resource> allResources;
52 * handle the notification of resource creation and deletion.
56 _resourceRec rootNode(False);
58 resource rootResource = &rootNode;
60 resourceList getRootResources()
62 return(rootResource->children);
65 char *getResourceName(resource r)
70 resource getResourceParent(resource r)
75 resourceList getResourceChildren(resource r)
80 int getResourceCount(resourceList rl)
82 return(rl ? rl->count: 0);
85 resource getNthResource(resourceList rl, int n)
88 return(rl->elements[n]);
94 resourceInfo *getResourceInfo(resource r)
99 resourceList createResourceList()
103 ret = (resourceList) xcalloc(sizeof(struct _resourceListRec), 1);
107 Boolean addResourceList(resourceList rl, resource r)
110 if (rl->count == rl->maxItems) {
113 rl->elements = (resource *)
114 xrealloc(rl->elements, sizeof(resource) * rl->maxItems);
116 rl->elements = (resource *) xmalloc(sizeof(resource) * rl->maxItems);
119 rl->elements[rl->count] = r;
124 Boolean initResourceRoot;
126 resource newResource(resource parent,
137 if (!initResourceRoot) {
138 initResourceRoot = True;
139 rootNode.info.name = "";
140 rootNode.info.fullName = "";
141 rootNode.info.creation = 0.0;
142 rootNode.parent = NULL;
143 rootNode.handle = NULL;
144 rootNode.children = NULL;
147 iName = pool.findAndAdd(name);
149 /* first check to see if the resource has already been defined */
150 if (parent->children) {
151 for (curr=parent->children->elements, c=0;
152 c < parent->children->count; c++) {
153 if (curr[c]->info.name == iName) {
158 parent->children = (resourceList)
159 xcalloc(sizeof(struct _resourceListRec), 1);
162 ret = new(_resourceRec);
163 ret->parent = parent;
164 ret->handle = handle;
166 sprintf(tempName, "%s/%s", parent->info.fullName, name);
167 ret->info.fullName = pool.findAndAdd(tempName);
168 ret->info.name = iName;
170 ret->info.creation = creation;
172 addResourceList(parent->children, ret);
173 allResources.add(ret, (void *) ret->info.fullName);
175 /* call notification upcall */
176 tp->resourceInfoCallback(0, parent->info.fullName, ret->info.name,
182 resource findChildResource(resource parent, char *name)
188 iName = pool.findAndAdd(name);
190 if (!parent || !parent->children) return(NULL);
191 for (curr=parent->children->elements, c=0;
192 c < parent->children->count; c++) {
193 if (curr[c]->info.name == iName) {
200 void printResources(resource r)
206 printf("%s\n", r->info.fullName);
208 for (curr=r->children->elements, c=0;
209 c < r->children->count; c++) {
210 printResources(curr[c]);
216 void printResourceList(resourceList rl)
221 for (i=0; i < rl->count; i++) {
222 printf(rl->elements[i]->info.fullName);
223 if (i!= rl->count-1) printf(",");
229 * Convinence function.
232 Boolean isResourceDescendent(resource parent, resource child)
235 if (child == parent) {
238 child = getResourceParent(child);
245 // Find this passed focus if its resource compoents are valid for this paradynd.
246 // We treat "unknown" top level resources as a specical case since the
247 // meaning is that we are at the top level of refinement of an unsupported
248 // resource hierarchy. In this case, we simply create the resource, and
249 // the focus is valid. Any other resource that can't be found results in
250 // an invalid focus. jkh 1/29/94.
252 resourceList findFocus(int count, char **data)
259 rl = createResourceList();
260 for (i=0; i < count; i++) {
261 iName = pool.findAndAdd(data[i]);
262 res = allResources.find(iName);
263 if (!res && (strchr(iName, '/') == strrchr(iName, '/'))) {
264 res = newResource(rootResource, NULL, ++iName, 0.0);
268 addResourceList(rl, res);
273 resource findResource(char *name)
279 return(rootResource);
281 iName = pool.findAndAdd(name);
282 res = allResources.find(iName);