Пример #1
0
void FreeThreadData (
    IN  LPLOG_THREAD_DATA    pThisThread
)
{
    if (pThisThread->next != NULL) {
        // free the "downstream" entries
        FreeThreadData (pThisThread->next);
        pThisThread->next = NULL;
    }
    // now free this entry
    if (pThisThread->mszCounterList != NULL) {
        G_FREE (pThisThread->mszCounterList);
        pThisThread->mszCounterList = NULL;
    }

    if (pThisThread->hExitEvent != NULL) {
        CloseHandle (pThisThread->hExitEvent);
        pThisThread->hExitEvent = NULL;
    }

    if (pThisThread->hKeyQuery != NULL) {
        RegCloseKey (pThisThread->hKeyQuery);
        pThisThread->hKeyQuery = NULL;
    }

    G_FREE (pThisThread);
}
Пример #2
0
void cmd_osdel(CMDObjectSet objects, int *iret)
/*****************************************************************************
 * cmd_osdel
 *
 * Deletes the given CMDObjectSet and any associated structures
 *
 * Input parameters:
 *  objects CMDObjectSet    CMDObjectSet to delete
 *
 * Output parameters:
 *  *iret       int     Return code
 *                          0 = Function successful
 *                         -1 = Invalid pointer in arguments
 **
 * Log:
 * S.Danz/AWC            2/06   Created
 ****************************************************************************/
{
    int                     object;
    CMDObjectSetContainer   *o;
/*---------------------------------------------------------------------*/

    o = (CMDObjectSetContainer*)objects;
    if (o) {
        *iret = 0;
        for (object = 0; object < o->total; object++) {
            cmd_obclear(o->objects[object]);
            G_FREE(o->objects[object], CMDObjectContainer);
        }

        G_FREE(o->objects, CMDObjectContainer*);

        G_FREE(o, CMDObjectSetContainer);
    } else {
Пример #3
0
void cap_psdel(PlacementSet placements, int *iret)
/*****************************************************************************
 * cap_psdel
 *
 * Deletes the given PlacementSet and any associated structures
 *
 * Input parameters:
 *  placements  PlacementSet    Placement set to delete
 *
 * Output parameters:
 *  *iret       int     Return code
 *                          0 = Function successful
 *                         -1 = Invalid pointer in arguments
 **
 * Log:
 * S.Danz/AWC            2/06   Created
 ****************************************************************************/
{
    int                     place;
    PlacementSetContainer   *p = (PlacementSetContainer*)placements;
/*---------------------------------------------------------------------*/

    if (p) {
        *iret = 0;
        for (place = 0; place < p->total; place++) {
            G_FREE(p->places[place], PlaceInfoContainer);
        }

        G_FREE(p->places, PlaceInfoContainer*);

        G_FREE(p, PlacementSetContainer);
    } else {
Пример #4
0
int main(int argc,char **argv) {
  int i,j,p,n;
  double **a,*b, count=1.0;
  unsigned int t1,t2;
  MAIN_INITENV
  if (argc!=3) {
     printf("Usage: pbksb P N\nAborting...\n");
     exit(0);
  }
  gm = (GM*)G_MALLOC(sizeof(GM));
  p = gm->p = atoi(argv[1]);
  gm->n = atoi(argv[2]);
  assert(p > 0);
  assert(p <= 8);
  n = gm->n;
  a = gm->a = (double**)G_MALLOC(n*sizeof(double*));
  for(i = 0; i < n; i++) {
    a[i] = (double*)G_MALLOC(n*sizeof(double));
    for(j = i;j < n;j++){
       a[i][j] = count;
       count++;
    }
  }

  //-----------------------------------------------
  // Create 1D array a_prime and map a to a_prime
  //-----------------------------------------------
  gm->a_prime = (double*)G_MALLOC((n+1)*n/2*sizeof(double))
  mapping();

  b = gm->b = (double*)G_MALLOC(n*sizeof(double));
  for(i = 0; i < n; i++) {
    b[i] = count;
    count++;
  }
  gm->pse = (char*)G_MALLOC(n*sizeof(char));
  for(i = 0; i < n; i++)
    CLEARPAUSE(gm->pse[i])
  for(i = 0; i < p-1; i++)
    CREATE(pbksb)
  CLOCK(t1)
  pbksb();
  WAIT_FOR_END(p-1)
  CLOCK(t2)
  printf("Elapsed: %u us\n",t2-t1);
  for(i = 0; i < n; i++) printf("%lf ", gm->b[i]);
  printf("\n");
  for(i = 0; i < n; i++)
    G_FREE(a[i],n*sizeof(double))
  G_FREE(a,n*sizeof(double*))
  G_FREE(b,n*sizeof(double))
  G_FREE(gm->a_prime, (n+1)*n/2*sizeof(double))
  MAIN_END
  return 0;
}
Пример #5
0
PDH_FUNCTION
PdhExpandCounterPathA (
    IN      LPCSTR  szWildCardPath,
    IN      LPSTR   mszExpandedPathList,
    IN      LPDWORD pcchPathListLength
)
{
    LPWSTR              szWideWildCardPath = NULL;
    DWORD               dwSize;
    PDH_STATUS          pdhStatus;

    __try {
        dwSize = lstrlenA (szWildCardPath);
        szWideWildCardPath = G_ALLOC (GPTR, ((dwSize+1) * sizeof (WCHAR)));
        if (szWideWildCardPath == NULL) {
            pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
        } else {
            mbstowcs (szWideWildCardPath, szWildCardPath, (dwSize+1));
            pdhStatus = PdhiExpandCounterPath (
                szWideWildCardPath,
                (LPVOID)mszExpandedPathList,
                pcchPathListLength,
                FALSE);
        }
    } __except (EXCEPTION_EXECUTE_HANDLER) {
        pdhStatus = PDH_INVALID_ARGUMENT;
    }

    if (szWideWildCardPath != NULL) G_FREE (szWideWildCardPath);

    return pdhStatus;
}
Пример #6
0
static struct p_page * AddPage(size_t type_id, size_t n)
{
	struct p_page *p = malloc(sizeof *p);
	void *heap = malloc(P_PAGE_SIZE);

	if (!p || !heap)
	{
		G_FREE(p);
		G_FREE(heap);
		return G_ERROR;
	}

	p->next  = p_glbpool[type_id].pages;
	p->index = 0;
	p->len   = n;
	p->heap  = heap;
	
	p_glbpool[type_id].pages = p;
	p_glbpool[type_id].page_count++;
	return p;
}
void FreeAllocatedMemory()
{
   {
      PMEMORY_ALLOC_BLOCK pNextMab, pMab;

      pMab = mabListHead.pNext;

      while (pMab != NULL)
      {
         pNextMab = pMab->pNext;
         G_FREE (pMab);
         pMab = pNextMab;
      }

      mabListHead.pNext = NULL;
   }
}
Пример #8
0
PDH_STATUS
ConnectMachine (
    PPERF_MACHINE   pThisMachine
)
{
    LONGLONG    llCurrentTime;
    PDH_STATUS  pdhStatus;
    LONG        lStatus;

    // only one thread at a time can try to connect to a machine.

    WAIT_FOR_AND_LOCK_MUTEX(pThisMachine->hMutex);

    // get the current time
    GetLocalFileTime (&llCurrentTime);

    if (pThisMachine->llRetryTime < llCurrentTime) {
        if (pThisMachine->llRetryTime != 0) {
            // connect to system's performance registry
            if (lstrcmpiW(pThisMachine->szName, szStaticLocalMachineName) == 0) {
                // this is the local machine so use the local reg key
                pThisMachine->hKeyPerformanceData = HKEY_PERFORMANCE_DATA;
            } else {
                __try {
                    // close any open keys
                    if (pThisMachine->hKeyPerformanceData != NULL) {
                        RegCloseKey (pThisMachine->hKeyPerformanceData);
                        pThisMachine->hKeyPerformanceData = NULL;
                    }
                } __except (EXCEPTION_EXECUTE_HANDLER) {
                    lStatus = GetExceptionCode();
                }

                // now try to connect

                __try {
                    // this can generate exceptions in some error cases
                    // so trap them here and continue
                    // remote machine so try to connect to it.
                    lStatus = RegConnectRegistryW (
                        pThisMachine->szName,
                        HKEY_PERFORMANCE_DATA,
                        &pThisMachine->hKeyPerformanceData);
                } __except (EXCEPTION_EXECUTE_HANDLER) {
                    lStatus = GetExceptionCode();
                }
                if (lStatus != ERROR_SUCCESS) {
                    pThisMachine->hKeyPerformanceData = NULL;
                }
            }

            if (pThisMachine->hKeyPerformanceData != NULL) {
                // successfully connected to computer's registry, so
                // get the performance names from that computer and cache them

                if (pThisMachine->szPerfStrings != NULL) {
                    // reload the perf strings, incase new ones have been
                    // installed
                    G_FREE (pThisMachine->szPerfStrings);
                    pThisMachine->szPerfStrings = NULL;
                }

                pThisMachine->szPerfStrings = BuildNameTable (
                    (pThisMachine->hKeyPerformanceData == HKEY_PERFORMANCE_DATA ?
                        NULL : pThisMachine->szName),
                    NULL,
                    &pThisMachine->dwLastPerfString);

                if (pThisMachine->szPerfStrings != NULL) {
                    pdhStatus = ERROR_SUCCESS;
                    pThisMachine->dwStatus = ERROR_SUCCESS;
                } else {
                    // unable to read system counter name strings
                    pdhStatus = PDH_CANNOT_READ_NAME_STRINGS;
                    pThisMachine->dwStatus = PDH_CSTATUS_NO_MACHINE;
                }
            } else {
                // unable to connect to remote machine
                pdhStatus = PDH_CANNOT_CONNECT_MACHINE;
                pThisMachine->dwStatus = PDH_CSTATUS_NO_MACHINE;
            }
        } else {
            // already connected
            // (note: is there a way to test this?)
            pdhStatus = ERROR_SUCCESS;
            pThisMachine->dwStatus = ERROR_SUCCESS;
        }

        if (pdhStatus != ERROR_SUCCESS) {
            // this attempt didn't work so reset retry counter  to
            // wait some more for the machine to come back up.
            pThisMachine->llRetryTime = llCurrentTime + RETRY_TIME_INTERVAL;
        } else {
            // clear the retry counter to allow function calls
            pThisMachine->llRetryTime = 0;
        }
    } else {
Пример #9
0
void xml_value(	const char	*xmlBuf,
       		const char	*elementName, 
       		int 		elementNumber, 
		const char	*childName,
		int		childNumber,
		char		**value,
       		int		*iret )
/************************************************************************
 * xml_value                                                            *
 *                                                                      *
 * This function returns the value of the specified element that is     *
 * contained in an xml file.   						*
 * 									*
 * The input element is actually part of an XPath expression.  This     *
 * expression by default assumes the searched for element is a child    *
 * of the root node of the xml document (/root/elementName).  The root  *
 * node should not be specified in elementName, however.  This routine  *
 * will prepend "[slash]*[slash]" to the beginning of the element name, *
 * thus always matching the root.					* 
 *                                                                      *
 * See additional documentation and usage examples of this and other    *
 * cgemlib/xml library routines at:					*
 *									*
 *	$NAWIPS/doc/Prog_guid/xml/cgemlibxml.sxw.			*
 *									*
 *                                                                      *
 * int xml_value( xmlBuf, elementName, elementNumber, childName,        *
 *			childNumber, value, iret ) 			*
 *                                                                      *
 * Input parameters:                                                    *
 *      *xmlBuf		const char	buffer containing xml document  *
 *	*elementName	const char	element name to be counted	* 
 *	elementNumber 	int       	element number or 0         	*
 *      *childName   	const char	name of child element or NULL   *
 *	childNumber 	int       	child number or 0          	*
 *                                                                      *
 * Output parameters:                                                   *
 *	**value		char		value of element (calling 	*
 *					  routine must free memory)	*
 *      *iret           int             Return code                     *
 *					  1 = non-fatal xpath error     *
 *					       see Valid Inputs above   *
 *                                        0 = normal                    *
 *                                       -1 = bad xmlBuf pointer (NULL) *
 *                                       -2 = bufSize <= 0              *
 *					 -3 = fatal error creating      *
 *					       XPath expression		*
 *					-15 = error executing xpath expr*
 *                                       -9 = node list is empty        *
 *                                      -16 = xpath expr returned more  *
 *						than one node		*
 *					 -9 = selected node is empty	*
 **                                                                     *
 * Log:                                                                 *
 * E. Safford/SAIC	11/05	initial coding (adapted from tutorial   *
 *				 by Aleksey Sanin, Copyright 2004, used *
 *                               under GNU Free Documentation License)  *
 * E. Safford/SAIC	04/06	correct error codes with xml.err	*
 ***********************************************************************/
{
    int 		ier, bufSize = 0, size = 0;
    xmlChar		*xpathExpr = NULL;
    xmlXPathObjectPtr	xpathObj;
    xmlNodeSetPtr	nodes;
    xmlNodePtr 		curNode;
    xmlDocPtr 		doc; 

 /*--------------------------------------------------------------------*/

    *iret = 0;

    /*
     *  sanity check on parameters
     */ 
    if( xmlBuf == NULL ) {
	*iret = -1;
	return;
    }
    
    bufSize = strlen( xmlBuf );

    if( bufSize <= 0 ) {
	*iret = -2;
	return;
    }


    /* 
     * Init libxml 
     */
    xmlInitParser();


    /*
     * Make the xpath expression
     */
    xml_makeXpathExpr( elementName, elementNumber, childName, 
    		       childNumber, NULL, &xpathExpr, &ier );

    if( ier < 0 ) {
	*iret = -3;
	G_FREE( xpathExpr, xmlChar );
	return;
    }
    else if( ier > 0 ) {
	*iret = 1;
    }


    xml_executeXpathExpr( xmlBuf, bufSize, xpathExpr, &doc, &xpathObj, &ier );
    if( ier != 0 ) {
        *iret = -15;
    }
    else {
        nodes = xpathObj->nodesetval;
        if( nodes ) {
            size = nodes->nodeNr;
        }


        /*
         *  Size indicates the number of nodes returned from the XPath 
	 *  expression.  This should be 1 and only 1; both 0 and > 1 are 
	 *  errors.  0 means the XPath expression didn't match anything, 
	 *  and > 1 means it matched too many things and we can't identify
	 *  a unique value to return.
         */
        if( size <= 0 ) {
	    *iret = -9;
        }

        if( size > 1 ) {
	    *iret = -16;
        }
    }


    if( *iret >= 0 ) {

        /*
         *  Return the content of the node.  This must be an XML_TEXT_NODE and 
	 *  it must have non-NULL content.  Any other condition is an error.
         */
        curNode = nodes->nodeTab[0];

        if( curNode->type == XML_ELEMENT_NODE ) {
	    curNode= curNode->children;
        }

	if( ( curNode->type == XML_TEXT_NODE ) && curNode->content ) {
	    *value = malloc( (strlen( (char *)(curNode->content) ) + 1) * 
	    			sizeof( char ));
	    strcpy( *value, (char *)curNode->content );
        }
        else {
	    *iret = -9;
        }
    }

    /* 
     * Shutdown libxml and clean up
     */
    xmlCleanupParser();
    G_FREE( xpathExpr, xmlChar );

    xmlXPathFreeObject( xpathObj );
    xmlFreeDoc( doc ); 
    
    return;
}
Пример #10
0
static
PDH_STATUS
PdhiExpandCounterPath (
    IN      LPCWSTR szWildCardPath,
    IN      LPVOID  pExpandedPathList,
    IN      LPDWORD pcchPathListLength,
    IN      BOOL    bUnicode
)
{
    PPERF_MACHINE       pMachine;
    PPDHI_COUNTER_PATH  pWildCounterPath = NULL;
    WCHAR               szWorkBuffer[MAX_PATH];
    WCHAR               szCounterName[MAX_PATH];
    WCHAR               szInstanceName[MAX_PATH];
    LPWSTR              szEndOfObjectString;
    LPWSTR              szInstanceString;
    LPWSTR              szCounterString;
    LPVOID              szNextUserString;
    PERF_OBJECT_TYPE    *pObjectDef;
    PERF_OBJECT_TYPE    *pParentObjectDef;
    PERF_COUNTER_DEFINITION *pCounterDef;
    PERF_INSTANCE_DEFINITION *pInstanceDef;
    PERF_INSTANCE_DEFINITION *pParentInstanceDef;

    DWORD               dwBufferRemaining;
    DWORD               dwSize;
    DWORD               dwSizeReturned = 0;
    PDH_STATUS          pdhStatus = ERROR_SUCCESS;

    DWORD               dwCtrNdx, dwInstNdx;
    BOOL                bMoreData = FALSE;

    // allocate buffers
    pWildCounterPath = G_ALLOC (GPTR, PDHI_COUNTER_PATH_BUFFER_SIZE);

    if (pWildCounterPath == NULL) {
      // unable to allocate memory so bail out
      pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
    } else {
      __try {
        dwBufferRemaining = *pcchPathListLength;
        szNextUserString = pExpandedPathList;
      } __except (EXCEPTION_EXECUTE_HANDLER) {
        pdhStatus = PDH_INVALID_ARGUMENT;
      }
    }

    if (pdhStatus == ERROR_SUCCESS) {
      // Parse wild card Path 
                  
      dwSize = G_SIZE (pWildCounterPath);
      if (ParseFullPathNameW (szWildCardPath, &dwSize, pWildCounterPath)) {
        // get the machine referenced in the path
        pMachine = GetMachine (pWildCounterPath->szMachineName, 0);
        if (pMachine != NULL) {
          if (wcsncmp (cszDoubleBackSlash, szWildCardPath, 2) == 0) {
            // the caller wants the machine name in the path so
            // copy it to the work buffer
            lstrcpyW (szWorkBuffer, pWildCounterPath->szMachineName);
          } else {
            *szWorkBuffer = 0;
          }
          // append the object name (since wild card objects are not
          // currently supported.

          lstrcatW (szWorkBuffer, cszBackSlash);
          lstrcatW (szWorkBuffer, pWildCounterPath->szObjectName);
          szEndOfObjectString = &szWorkBuffer[lstrlenW(szWorkBuffer)];
          
          // get object pointer (since objects are not wild)
          pObjectDef = GetObjectDefByName (
            pMachine->pSystemPerfData,
            pMachine->dwLastPerfString,
            pMachine->szPerfStrings,
            pWildCounterPath->szObjectName);

          if (pObjectDef != NULL) {
            // for each counters and identify matches
            pCounterDef = FirstCounter (pObjectDef);
            for (dwCtrNdx = 0; dwCtrNdx < pObjectDef->NumCounters; dwCtrNdx++) {
              // for each counter check instances (if supported) 
              //  and keep matches
              if ((pCounterDef->CounterNameTitleIndex > 0) &&
                  (pCounterDef->CounterNameTitleIndex < pMachine->dwLastPerfString ) &&
                  (!((pCounterDef->CounterType & PERF_DISPLAY_NOSHOW) &&
                     // this is a hack because this type is not defined correctly
                    (pCounterDef->CounterType != PERF_AVERAGE_BULK)))) {
                // look up name of each object & store size
                lstrcpyW (szCounterName,
                  pMachine->szPerfStrings[pCounterDef->CounterNameTitleIndex]);
                if (WildStringMatchW(pWildCounterPath->szCounterName, szCounterName)) {
                  // if this object has instances, then walk down
                  // the instance list and save any matches
                  if (pObjectDef->NumInstances != PERF_NO_INSTANCES) {
                    // then walk instances to find matches
                    pInstanceDef = FirstInstance (pObjectDef);
                    if (pObjectDef->NumInstances > 0) {
                      for (dwInstNdx = 0;
                        dwInstNdx < (DWORD)pObjectDef->NumInstances;
                        dwInstNdx++) {
                        szInstanceString = szEndOfObjectString;
                        if (pInstanceDef->ParentObjectTitleIndex > 0) {
                          // then add in parent instance name
                          pParentObjectDef = GetObjectDefByTitleIndex (
                            pMachine->pSystemPerfData,
                            pInstanceDef->ParentObjectTitleIndex);
                          if (pParentObjectDef != NULL) {
                            pParentInstanceDef = GetInstance (
                              pParentObjectDef,
                              pInstanceDef->ParentObjectInstance);
                            if (pParentInstanceDef != NULL) {
                              GetInstanceNameStr (pParentInstanceDef,
                                szInstanceName,
                                pObjectDef->CodePage);
                              if (WildStringMatchW (pWildCounterPath->szParentName, szInstanceName)) {
                                // add this string
                                szInstanceString = szEndOfObjectString;
                                lstrcpyW (szInstanceString, cszLeftParen);
                                lstrcatW (szInstanceString, szInstanceName);
                                lstrcatW (szInstanceString, cszSlash);
                              } else {
                                // get next instance and continue 
                                pInstanceDef = NextInstance(pInstanceDef);
                                continue;
                              }
                            } else {
                              // unable to locate parent instance
                              // so cancel this one, then 
                              // get next instance and continue 
                              pInstanceDef = NextInstance(pInstanceDef);
                              continue;
                            }
                          } else {
                            // unable to locate parent object
                            // so cancel this one, then 
                            // get next instance and continue 
                            pInstanceDef = NextInstance(pInstanceDef);
                            continue;
                          }
                        } else {
                          // no parent name so continue
                          szInstanceString = szEndOfObjectString;
                          lstrcpyW (szInstanceString, cszSlash);
                        }
                        GetInstanceNameStr (pInstanceDef,
                          szInstanceName,
                          pObjectDef->CodePage);

                        //
                        //  BUGBUG: need to do something with indexes.
                        //
                        // if this instance name matches, then keep it
                        if (WildStringMatchW (pWildCounterPath->szInstanceName, szInstanceName)) {
                          lstrcatW (szInstanceString, szInstanceName);
                          lstrcatW (szInstanceString, cszRightParenBackSlash);
                          // now append this counter name
                          lstrcatW (szInstanceString, szCounterName);

                          // add it to the user's buffer if there's room
                          dwSize = lstrlenW(szWorkBuffer) + 1;
                          if (!bMoreData && (dwSize  < dwBufferRemaining)) {
                            if (bUnicode) {
                                lstrcpyW ((LPWSTR)szNextUserString, szWorkBuffer);
                                (LPBYTE)szNextUserString += dwSize * sizeof(WCHAR);
                            } else {
                                wcstombs ((LPSTR)szNextUserString, szWorkBuffer, dwSize);
                                (LPBYTE)szNextUserString += dwSize * sizeof(CHAR);
                            }
                            dwSizeReturned += dwSize;
                            dwBufferRemaining -= dwSize;
                          } else {
                            // they've run out of buffer so just update the size required
                            bMoreData = TRUE;
                            dwSizeReturned += dwSize;
                          }
                        } else {
                          // they don't want this instance so skip it
                        }
                        pInstanceDef = NextInstance (pInstanceDef);
                      } // end for each instance in object
                    } else {
                      // this object supports instances, 
                      // but doesn't currently have any
                      // so do nothing.
                    }
                  } else {
                    // this object does not use instances so copy this
                    // counter to the caller's buffer.
                    szCounterString = szEndOfObjectString;
                    lstrcpyW (szCounterString, cszBackSlash);
                    lstrcatW (szCounterString, szCounterName);
                    dwSize = lstrlenW(szWorkBuffer) + 1;
                    if (!bMoreData && (dwSize  < dwBufferRemaining)) {
                      if (bUnicode) {
                        lstrcpyW ((LPWSTR)szNextUserString, szWorkBuffer);
                        (LPBYTE)szNextUserString += dwSize * sizeof(WCHAR);
                      } else {
                        wcstombs ((LPSTR)szNextUserString, szWorkBuffer, dwSize);
                        (LPBYTE)szNextUserString += dwSize * sizeof(CHAR);
                      }
                      dwSizeReturned += dwSize;
                      dwBufferRemaining -= dwSize;
                    } else {
                      // they've run out of buffer so bail out of this loop
                      bMoreData = TRUE;
                      dwSizeReturned += dwSize;
                    }
                  }
                } else {
                  // this counter doesn't match so skip it
                }
              } else {
                // this counter string is not available
              }
              pCounterDef = NextCounter(pCounterDef);
            } // end for each counter in this object
            if (bUnicode) {
                *(LPWSTR)szNextUserString = 0;  // MSZ terminator
            } else {
                *(LPSTR)szNextUserString = 0;  // MSZ terminator
            }
            *pcchPathListLength = dwSizeReturned;
            if (bMoreData) {
              pdhStatus = PDH_MORE_DATA;
            } else {
              pdhStatus = ERROR_SUCCESS;
            }
          } else {
            // unable to find object
            pdhStatus = PDH_INVALID_PATH;
          }
        } else {
          // unable to connect to machine.
          pdhStatus = PDH_CANNOT_CONNECT_MACHINE;
        }
      } else {
        // unable to read input path string
          pdhStatus = PDH_INVALID_PATH;
      }
    }

    if (pWildCounterPath != NULL) G_FREE (pWildCounterPath);

    return pdhStatus;
}
Пример #11
0
PDH_FUNCTION
WriteTextLogHeader (
    IN  PLOG_INFO   pLog
)
{
    LONG      pdhStatus = ERROR_SUCCESS;
    PLOG_COUNTER_INFO   pThisCounter;
    CHAR            cDelim;
    CHAR            szLeadDelim[4];
    DWORD           dwLeadSize;
    CHAR            szTrailDelim[4];
    DWORD           dwTrailSize;
    DWORD           dwBytesWritten;
    PPDH_COUNTER_INFO_A  pCtrInfo;
    DWORD           dwCtrInfoSize;
    BOOL            bResult;

    pCtrInfo = G_ALLOC (8192);

    if (pCtrInfo == NULL) {
        return PDH_MEMORY_ALLOCATION_FAILURE;
    }

    cDelim = (LOWORD(pLog->dwLogFormat) == OPD_CSV_FILE) ? COMMA_DELIMITER :
            TAB_DELIMITER;

    szLeadDelim[0] = cDelim;
    szLeadDelim[1] = DOUBLE_QUOTE;
    szLeadDelim[2] = 0;
    szLeadDelim[3] = 0;
    dwLeadSize = 2;

    szTrailDelim[0] = DOUBLE_QUOTE;
    szTrailDelim[1] = 0;
    szTrailDelim[2] = 0;
    szTrailDelim[3] = 0;
    dwTrailSize = 1;


    // write the logfile header record
    bResult = WriteFile (pLog->hLogFileHandle,
        (LPCVOID)&szTrailDelim[0],
        1,
        &dwBytesWritten,
        NULL);

    if (!bResult) {
        pdhStatus = GetLastError();
    }

    if (pdhStatus == ERROR_SUCCESS) {
        // write the time stamp title
        bResult = WriteFile (pLog->hLogFileHandle,
            (LPCVOID)szTimeStampLabel,
            dwTimeStampLabelLength,
            &dwBytesWritten,
            NULL);

        if (!bResult) {
            pdhStatus = GetLastError();
        }
    }

    if (pdhStatus == ERROR_SUCCESS) {
        // check each counter in the list of counters for this query and
        // write them to the file

        // output the path names
        pThisCounter = pFirstCounter;

        if (pThisCounter != NULL) {
            do {
                // write  the leading delimiter
                bResult = WriteFile (pLog->hLogFileHandle,
                    (LPCVOID)szLeadDelim,
                    dwLeadSize,
                    &dwBytesWritten,
                    NULL);

                if (!bResult) {
                    pdhStatus = GetLastError();
                    break; // out of the Do Loop
                }

                // get the counter path information from the counter
                dwCtrInfoSize = 8192;
                pdhStatus = PdhGetCounterInfoA (
                    pThisCounter->hCounter,
                    FALSE,
                    &dwCtrInfoSize,
                    pCtrInfo);

                if (pdhStatus == ERROR_SUCCESS) {
                    // write the counter name
                    bResult = WriteFile (pLog->hLogFileHandle,
                        (LPCVOID)pCtrInfo->szFullPath,
                        lstrlen(pCtrInfo->szFullPath),
                        &dwBytesWritten,
                        NULL);

                    if (!bResult) {
                        pdhStatus = GetLastError();
                        break; // out of the Do Loop
                    }
                } else {
                    // unable to get counter information so bail here
                    break;
                }

                // write  the trailing delimiter
                bResult = WriteFile (pLog->hLogFileHandle,
                    (LPCVOID)szTrailDelim,
                    dwTrailSize,
                    &dwBytesWritten,
                    NULL);


                if (!bResult) {
                    pdhStatus = GetLastError();
                    break; // out of the Do Loop
                }

                pThisCounter = pThisCounter->next;
            } while (pThisCounter != NULL);
        }
    }

    if (pdhStatus == ERROR_SUCCESS) {
        // write  the record terminator
        bResult = WriteFile (pLog->hLogFileHandle,
            (LPCVOID)szRecordTerminator,
            dwRecordTerminatorLength,
            &dwBytesWritten,
            NULL);
        if (!bResult) {
            pdhStatus = GetLastError();
        }
    }

    G_FREE (pCtrInfo);

    return pdhStatus;
}
Пример #12
0
void cvg_load ( char *fname, Boolean selflag, Boolean wrtflg, 
			Boolean plotflg, int layer, int icol, int *iret )
/************************************************************************
 * cvg_load								*
 *									*
 * This function loads data from a VGF formatted file and converts 	*
 * encountered records to a set of actions that display the feature	*
 * to an appropriate driver.  The parameter icol controls whether the	*
 * graphics will be plotted with the file-specified colors (icol=0)	*
 * or whether the VGF file will be plotted monochrome (icol=other).	*
 *									*
 * void cvg_load ( fname, selflag, wrtflg, plotflg, layer, icol, iret )	*
 *									*
 * Input parameters:							*
 *	*fname		char		Name of file to load		*
 *	selflag		Boolean		Are elements "selectable"	*
 *	wrtflg		Boolean		Write flag for file		*
 *	plotflg		Boolean		Display the elements or not	*
 *	layer		int		Layer the file contents will be	*
 *					   assigned to			*
 *	icol		int		Plot color			*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  1 = elms in file exceeded 	*
 *				              (MAX_EDITABLE_ELEMS)	*
 *					 -1 = error opening VG file	*
 *					 -2 = error closing VG file	*
 *					 -4 = error reading el hdr      *
 *					 -5 = VG file is empty		*
 **									*
 * Log:									*
 * E. Wehner/EAi	10/96	Created					*
 * D. Keiser/GSC	 1/97	Clean up				*
 * E. Wehner/EAi	 2/97	Added selection flag.			*
 * E. Wehner/EAi	 5/97	Add double tier loading 		*
 * E. Wehner/EAi	 5/97	Stop loading if > MAX_EDITABLE_ELEMS	*
 * E. Wehner/EAi	 5/97	Added refresh after displaying 		*
 * D. Keiser/GSC	 5/97	Change cvg_dsply to cds_dspvg		*
 * S. Jacobs/NCEP	 6/97	Added write flag			*
 * C. Lin/NCEP	 	 6/97	Bug fix in calling cfl_ropn 		*
 * E. Wehner/EAi	 6/97	Added check to not load header		*
 * E. Wehner/EAi	 7/97	Filled areas on all elements		*
 * E. Wehner/EAi	 8/97	Removed the graphics info record.	*
 * E. Wehner/EAi	 9/97	Allow NULL file name			*
 * F. Yen/NCEP		 1/98	Updated calls for crg library cleanup	*
 * I. Durham/GSC	 5/98	Changed underscore decl. to an include	*
 * F. J. Yen/NCEP	 5/98	Updated cds function names		*
 * E. Safford/GSC	10/98	added display levels revised file reads *
 * T. Piper/GSC		10/98	Prolog update				*
 * E. Safford/GSC	12/98	move display levels to pgprm.h		*
 * S. Jacobs/NCEP	 3/99	Added symbols to the last display level	*
 * A. Hardy/GSC          1/01   changed fptr from int to FILE           *
 * J. WU/SAIC           11/01   change prototype & add plotflg param	*
 * J. WU/SAIC           12/01   add layer param to feed crg_set()	*
 * J. WU/SAIC           12/01   locate displaying level	with cvg_level  *
 * T. Lee/SAIC		11/03	changed .DEFAULT.vgf to work_file	*
 * T. Lee/SAIC		11/03	used cvgcmn.h				*
 * M. Li/SAIC		08/04	Added time filter			*
 * B. Yin/SAIC          08/04   Added code to free TCA memory           *
 * B. Yin/SAIC          08/04   changed pgtca_freeBkpts to cvg_freeBkpts*
 * J. Wu/SAIC		10/04	free GFA block pointers			*
 * S. Danz/AWC          03/06   Call autoplacement if enabled           *
 * J. Wu/SAIC		06/06	call cvg_matchfilter 			*
 * M. Li/SAIC           03/07   Updated cvg_matchfilter                 *
 * m.gamazaychikov/SAIC	06/07	Add code to free TCB and TCT memory	*
 ***********************************************************************/
{
    int		    curpos, ier, flag, el_level;
    long	    maxbytes;
    int		    ier1, loglev, ic, icx, ii, jj, kk, one=1;
    int		    elms[3][MAX_EDITABLE_ELEMS], lvl_cnt[LEVELS], total_elms;
    char	    newfil[LLPATH], reqfil[LLPATH], grp[4], dbgfile[LLPATH];
    Boolean         autopl_enabled;
    VG_DBStruct	    el;
    filter_t	    el_filter, timeMatched;
    Boolean	    filter_match, matchAny = False;
    FILE	    *fptr;
    CMDObjectSet    nmap_metadata = NULL;
    PlacementSet    nmap_placements = NULL;
    cvg_group_info  *nmap_group_check = NULL;
/*---------------------------------------------------------------------*/

    ic = icol;
    icx = 256;
    if ( ic > icx || ic < 0 )  ic = 0;
    cds_scol ( ic, iret );

    strcpy(grp, "CVG");
    loglev = 0;
    *iret = 0;
    curpos  = 0;
    maxbytes = 0;    

    if (!fname) {
	strcpy(reqfil, work_file);
    }
    else {
	strcpy(reqfil, fname);
    }


    cvg_open(reqfil, (int)wrtflg, &fptr, &ier);

    if (( ier != 0 ) || ( fptr == NULL )) {
	*iret = -1;
	er_lmsg( &loglev, grp, &ier, reqfil, &ier1, strlen(grp),strlen(reqfil));
	return;
    }

    cfl_inqr(reqfil, NULL, &maxbytes, newfil, &ier);
    if (ier < 0) {
	*iret = -1;
	er_lmsg( &loglev, grp, &ier, reqfil, &ier1, strlen(grp),strlen(reqfil));
	return;
    }

    /*
     * Get each el.hdr and assign each elem offset to one of the levels.
     */
    for (ii = 0; ii < 3; ii++) {
        lvl_cnt[ii] = 0;
    }

    /*
     *  Scan the vg file and load the offsets of all non-deleted elements.
     *  Stop loading at end of file or MAX_EDITABLE_ELEMS.
     */
    total_elms = 0;
    while (((long)curpos < maxbytes) && (total_elms < MAX_EDITABLE_ELEMS))  {

        cvg_rdhdr(newfil, fptr, curpos, (int)maxbytes, &el, &flag, &ier);
	if (ier < 0 || el.hdr.recsz < 0 || el.hdr.recsz > 65536) {
	    *iret = -4;
	    return;
	}

        cvg_level( &el.hdr, &el_level, &ier );
	if ( ier == 0 ) {	
	    elms[ el_level ] [ lvl_cnt[el_level]++ ] = curpos;
	    total_elms++;
	}
		
 	curpos += el.hdr.recsz;	
    }

    if (total_elms >= MAX_EDITABLE_ELEMS) {
	*iret = 1;
	er_lmsg( &loglev, grp, &ier, newfil, &ier1, 
						strlen(grp),strlen(reqfil));
    }

    /*
     *  Create the structures to manage the metadata and object placement
     *  information.  If there were structures already in place, hold them
     *  aside as they were put there by product generation.
     */
    ctb_pfbool( "ENABLE_AUTOPLACE", &autopl_enabled, &ier );
    if (autopl_enabled) {
        if (cvg_metadata) {
            nmap_metadata = cvg_metadata;
            nmap_placements = cvg_placements;
            nmap_group_check = cvg_group_check;
        }
        cmd_osnew(&cvg_metadata, &ier);
        cap_psnew(&cvg_placements, &ier);
        G_CALLOC(cvg_group_check, cvg_group_info, one, "cvg_load: cvg_group_check");

        /*
         * Fill in the structures with the information needed
         */
        cvg_ld4place(fname, iret);

        /*
         * Ok, its all loaded, so place all the objects where they belong
         */
        cap_psplace(cvg_placements, cvg_metadata, iret);

        ctb_pfstr("AUTOPLACE_DBG", dbgfile, &ier );
        if (dbgfile[0] != '\0') {
            dump_objects(dbgfile, cvg_metadata, cvg_placements);
        }
    }

    /*
     *  Now loop thru the levels and display the elements
     */
    kk = 0;

    for (ii = 0; ii < LEVELS; ii++) {

	for (jj=0; jj<lvl_cnt[kk]; jj++) {
	    curpos = elms[ii][jj];
            cvg_rdhdr(newfil, fptr, curpos, (int)maxbytes, &el, &flag, &ier);
	    cvg_rdele(&el, curpos, el.hdr.recsz, fptr, &ier);

	    cvg_getElFilter ( &el, el_filter, &ier ); 

            cvg_matchfilter ( el_filter, matchAny, &filter_match, timeMatched, &ier );

	    if (selflag) {
	        crg_set(&el, curpos, layer, &ier);
	    }

	    if ( filter_match ) {
	        cds_dspelm( &el, &ier); 
	    }

            /*
             * Free TCA/GFA/TCT/TCB memory
             */
            if ( el.hdr.vg_type == TCA_ELM ) {
                cvg_freeBkpts ( &el );
            }
            else if ( el.hdr.vg_type == GFA_ELM ) {
                cvg_freeElPtr ( &el );
            }
            else if ( el.hdr.vg_type == TCTRK_ELM ) {
                cvg_freeTct ( &el );
            }
            else if ( el.hdr.vg_type == TCBKL_ELM ) {
                cvg_freeTcb ( &el );
	    }
	}

	kk++;
    }

    cvg_clos(fptr, &ier);
    if ( ier != 0 )
	*iret = -2;

    if ( plotflg ) geplot(&ier);
    ic = 0;
    cds_scol ( ic, iret );

    /*
     * Free up the metadata and placement information now that we 
     * are done plotting everything
     */
    if (autopl_enabled) {
        cmd_osdel(cvg_metadata, iret);
        cap_psdel(cvg_placements, iret);
        G_FREE(cvg_group_check, cvg_group_info);

        /*
         * Put back the product generation metadata
         */
        cvg_metadata = nmap_metadata;
        cvg_placements = nmap_placements;
        cvg_group_check = nmap_group_check;
    }

    return;

}
Пример #13
0
int xml_count( 	const char	*xmlBuf,
       		const char	*elementName, 
		int		elementNumber,
		const char	*childName,
       		const char	*childValue, 
       		int		*iret )
/************************************************************************
 * xml_count                                                            *
 *                                                                      *
 * This function returns the number of specified elements that are      *
 * contained in an xml file.  						*
 * 									*
 * The input element is actually part of an XPath expression.  This     *
 * expression by default assumes the searched for element is a child    *
 * of the root node of the xml document (/root/elementName).  The root  *
 * node should not be specified in elementName, however.  This routine  *
 * will prepend "[slash]*[slash]" to the beginning of the element name, *
 * thus always matching the root.					* 
 *                                                                      *
 * See additional documentation and usage examples of this and other    *
 * cgemlib/xml library routines at:					*
 *									*
 *	$NAWIPS/doc/Prog_guid/xml/cgemlibxml.sxw.			*
 *									*
 * Valid Inputs:							*
 *                                                                      *
 * int xml_count( xmlBuf, elementName, elementNumber, childName,        *
 *                childValue, iret ) 					*
 *                                                                      *
 * Input parameters:                                                    *
 *      *xmlBuf		const char	buffer containing xml document  *
 *	*elementName	const char	element name to be counted	* 
 *	elementNumber	int		number of element or 0 for none *
 *	*childName	const char	optional child element name     *
 *	*childValue 	const char	optional element value or NULL  *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *                                        0 = normal                    *
 *					  1 = non-fatal xpath error     *
 *					       see Valid Inputs above   *
 *                                       -1 = bad xmlBuf pointer (NULL) *
 *                                       -2 = bufSize <= 0              *
 *					 -3 = fatal error creating      *
 *					       XPath expression		*
 *                                       -4 = unable to allocate memory *
 *					 -5 = xpath context error	*
 *					 -6 = error parsing xmlBuf	*
 *                                       -7 = xpath context error       *
 *                                       -8 = xpath expression error    *
 *                                       -9 = node list is empty        *
 * Return:								*
 *			int		number of instances of the 	*
 *					  specified element in xmlBuf  	*
 **                                                                     *
 * Log:                                                                 *
 * E. Safford/SAIC	11/05	initial coding (adapted from tutorial   *
 *				 by Aleksey Sanin, Copyright 2004, used *
 *                               under GNU Free Documentation License)  *
 ***********************************************************************/
{
    int 		count      = 0, ier = 0, bufSize = 0;

    xmlChar		*xpathExpr = NULL;
    xmlDocPtr 		doc        = NULL; 
    xmlXPathObjectPtr 	xpathObj   = NULL; 
    xmlNodeSetPtr	nodes      = NULL;
 /*--------------------------------------------------------------------*/

    *iret   = 0;

    /*
     *  Sanity check on input buffer
     */ 
    if( xmlBuf == NULL ) {
	*iret = -1;
	return( count );
    }

    bufSize = strlen( xmlBuf );
    if( bufSize <= 0 ) {
	*iret = -2;
	return( count );
    }


    /* 
     * Init libxml 
     */
    xmlInitParser();

    /*
     * Construct the XPath expression
     */
    xml_makeXpathExpr( elementName, elementNumber, childName, 0, childValue,
    			&xpathExpr, &ier );
    if( ier < 0 ) {
	*iret = -3;
	G_FREE( xpathExpr, xmlChar );
	return( count );
    }
    else if( ier > 0 ) {
	*iret = 1;
    }


    xml_executeXpathExpr( xmlBuf, bufSize, xpathExpr, &doc, &xpathObj, &ier );

    if( ier < 0 ) {
        *iret = -8;
    } 
    else {
        /* 
         * Process results 
         */
        nodes = xpathObj->nodesetval;
        count = nodes->nodeNr;
    }


    /* 
     * Shutdown libxml and cleanup
     */
    G_FREE( xpathExpr, xmlChar ); 
    xmlXPathFreeObject(xpathObj); 
    xmlFreeDoc(doc);   

    xmlCleanupParser();


    return( count );
}