/* Clear connector data */ void conClear(Connector *connect, u_char dir) { Link* lnkPtr = NULL; /* element connector */ if(connect->ticket) { if(dir == C_IN) { if(connect->elt.pointer) { IFFREE(connect->elt.data); } else { dataClear(connect->elt.data); free(connect->elt.data); //dataDelete(connect->elt.data); } } else { /* if get data, delete it */ if(connect->elt.data) { dataClear(connect->elt.data); free(connect->elt.data); //dataDelete(connect->elt.data); } } /* delete link structures */ while(connect->elt.pin) { lnkPtr = connect->elt.pin; connect->elt.pin = connect->elt.pin->next; free(lnkPtr); } } /* block connector */ else { IFFREE(connect->blk.name); } }
vibration::~vibration() { IFFREE(m_configfile); IFFREE(m_filter); if(length()) { while((m_item = (VIBRATION_DATA *)remove()) != NULL) { IFDESTROYA(m_item->data); IFDESTROYA(m_item->key); IFDESTROY(m_item); } } }
bool httpserver::onget(string istr, string &ostr) { string filename = istr.c_str() + strlen("GET "); int n1 = min(filename.find(' '), filename.find('\r')); int n2 = min(filename.find('\n'), filename.find('\t')); string fname = filename.substr(0, min(n1, n2)); char *pstr = NULL; char *pfilename = strndup(fname.c_str(), filename.length()); VERBOSE("pfilename (" << pfilename << ")"); if((pstr = (char *)m_filer.loadfile(pfilename)) != NULL) { ostr = "Content-Type: text/plain\n"; ostr += pstr; IFFREE(pstr); } else { ostr = ""; //ostr += "Content-Type: text/html\n"; ostr += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"; ostr += "<html><head><title>404 Not Found</title></head>"; ostr += "<body><h1>Not Found</h1>\n"; ostr += "<p>The requested URL "; ostr += pfilename; ostr += " was not found on this server.</p>\n"; ostr += "<hr><address>Apache/2.2.17 (Ubuntu) Server at localhost Port 80</address></body></html>"; // FIXME: } IFDESTROYA(pfilename); return true; }
char *cypress::sys_tee(const char *command, int buflen) { int len = 0; char *buf = (char *)malloc(buflen); char *cur = buf; memset(buf, 0, buflen); FILE *fp = popen(command, "r"); size_t ret = 0; if(fp == NULL) { IFFREE(buf); return NULL; } while (!feof(fp)) { if (len >= buflen) { buf[buflen] = 0; fclose(fp); return buf; } ret = fread(cur++, sizeof(char), 1, fp); len++; } fclose(fp); return buf; }
bool topologymacaddresses::update(deviceinfo *pinfo) { if(pinfo == NULL) return false; int index = 1; char *value = NULL; char *address = NULL; MACAddress.ss << ".1.3.6.1.2.1.17.4.3.1.1.0."; if((m_subs = pinfo->m_devmac.cloneof(MACAddress.ss.str())) == NULL) return false; while((value = m_subs->remove_key()) != NULL) { clear(); address = value + strlen(".1.3.6.1.2.1.17.4.3.1.1.0."); //IfIndex.ss ifindex is set via MAC_PORT GET_MAC_IFINDEX "1.3.6.1.2.1.17.1.4.1.2.%d" MACAddress.ss << ".1.3.6.1.2.1.17.4.3.1.1.0." << address; //#define GET_MAC_ADDRESS "1.3.6.1.2.1.17.4.3.1.1.0" SwitchPort.ss << ".1.3.6.1.2.1.17.4.3.1.2.0." << address; //#define GET_MAC_PORT "1.3.6.1.2.1.17.4.3.1.2.%s" VLANNumber.ss << ".1.3.6.1.2.1.17.4.3.1.3.0." << address; //#define GET_MAC_TYPE "1.3.6.1.2.1.17.4.3.1.3.%s" if(runquery(pinfo) == true) index++; IFFREE(value); } IFDESTROY(m_subs); return true; };
bool xml::file(const char *filename) { bool ret = false; if(filename == NULL) return false; m_buffer = (char *)m_filer.loadfile(filename); ret = document(m_buffer); IFFREE(m_buffer); return ret; }
bool vibration::getconfig(char *filename) { char *pline = NULL; if((m_buffer = (char *)m_filer.loadfile(filename)) == NULL) return false; if(m_lines.split(m_buffer, "\n") > 0) { // split buffer into array while((pline = (char *)m_lines.remove()) != NULL) { // remove elements from array if(strncmp(pline, m_filter, strlen(m_filter)) == 0) // we only case about some lines getfields(pline); // split up key/value IFDESTROYA(pline); // only use lines that begin with filter, delete all others } } IFFREE(m_buffer); return true; }
void setfile(const char *file) { IFFREE(m_configfile); if(file != NULL) m_configfile = strdup(file); };
/* * ==================================================================== * Solve the full system of equations including direct and grid parts. * * Note: This routine does not "need to know" about definitions of * grid, sparse matrices, elements etc. * * This is still in TEST PHASE. I need to implement routines for dealing * with boundary conditions (in "elements.c"?) and setting up a * right-hand-side. These data should be passed on by the calling routine! * * Maybe later implement restarted GMRES to decrease memory consumption? * ==================================================================== */ void solveFull(void *directMat, void *interpMat, void *projectMat, void *precondMat, char *precondType, void *grid, double *sourceVector, double *destVector, int matNum, int numColsDirect, int numRowsDirect) { char fctName[] = "solveFull"; int testSolution = 0; /* Perform a final matrix-vector product to * confirm the soltion accuracy. */ int i, iter; double norm1, norm2, tol2; struct fullSolveBundle bundleData[1]; double err, *testVector=NULL, *solutionVectorTmp, *rightHandSideTmp; /* These should really be passed from the calling routine */ double tol = 1.0E-4, *solutionVector, *rightHandSide; int modifyTol=1; /* 1 if tol may be modified based on the RHS norm */ int maxiter = 100; /* Maximum number of iteration in the gmres */ /* Never do more iterations than the number of unknowns */ maxiter = MIN(maxiter, numColsDirect); /* solutionVector = (double*) calloc(numColsDirect,sizeof(double)); rightHandSide = (double*) calloc(numColsDirect,sizeof(double)); */ solutionVector = destVector; rightHandSide = sourceVector; /* JKW DUMMY = unit vector right-hand-side: */ /* fprintf(stderr,"%s: WARNING: Using dummy right-hand-side!\n",fctName); for (i=0; i<numColsDirect; i++) rightHandSide[i] = ((double) rand())/((double) RAND_MAX); for (i=0; i<numColsDirect; i++) rightHandSide[i] = 0.0; rightHandSide[0] = 1.0; */ printf("%s: Solving system with preconditioner: %s\n", fctName,precondType); /* Bundle data for the "matrix multiply routine". Use a structure * for the bundle, so that it cannot be messed up easily. */ bundleData->directMat = directMat; bundleData->interpMat = interpMat; bundleData->projectMat = projectMat; bundleData->precondMat = precondMat; bundleData->precondType = precondType; bundleData->numColsDirect = numColsDirect; bundleData->numRowsDirect = numRowsDirect; bundleData->grid = grid; /* Presently, only work on the first matrix. * This *could* be changed at a later point. */ bundleData->matNum = matNum; /* Allocate working vector for the "matrix multiply routine" */ /* Work vectors for eval values for direct and grid parts */ if (strcmp(precondType,"right")==0){ /* Make an extra work vector to store source values */ bundleData->workSrc = (double *) calloc(numColsDirect,sizeof(double)); } else if (strcmp(precondType,"left")==0){ /* Make an extra work vector to store eval values */ bundleData->workEval = (double *) calloc(numRowsDirect,sizeof(double)); } else if (strcmp(precondType,"none")!=0){ /* This is everything else, which is unknown = bad! * Print error and exit */ fprintf(stderr,"%s: ERROR. Unknown preconditioner type\n" " Please use \"none\", \"left\" or \"right\"\n" " Exiting\n", fctName); exit(1); } /* === Call iterative solver === */ /* Possibly repeat the call to the iterative solver. * Note that the memory consumption is O(maxiter^2*N) and the * CPU consumption is O(maxgmres*maxiter^2*N), so it may pay out * to use restarted gmres. */ if (strcmp(precondType,"none")==0){ /* NO precond, solve: Ax = b */ iter = gmres(solutionVector, rightHandSide, numColsDirect, tol, maxiter, fullMatrixMultiply, (void*) bundleData); } else if (strcmp(precondType,"right")==0){ /* RIGHT precond, solve: APy = b */ /* Modify stop criterion based on the 2-norm of the * right-hand-side vector */ for (i=0,norm1=0.0;i<numColsDirect;i++) norm1 += rightHandSide[i]*rightHandSide[i]; norm1 = sqrt(norm1); tol2 = tol; if (norm1>0.0 && modifyTol){ fprintf(stdout,"%s: Scaling tolerance with ||b|| = %g\n", fctName,norm1); tol2 *= norm1; fprintf(stdout, "%s: Aiming for tolerance %g, rather than the specified %g\n", fctName,tol2,tol); } solutionVectorTmp = (double*) calloc(numColsDirect,sizeof(double)); iter = gmres(solutionVectorTmp, rightHandSide, numColsDirect, tol2, maxiter, fullMatrixMultiply, (void*) bundleData); /* Then calculate x = Py. */ spMatMultiply(precondMat, solutionVectorTmp, solutionVector, matNum); FREE(solutionVectorTmp); } else if (strcmp(precondType,"left")==0){ /* LEFT preconditioner - calculate y := Pb. */ rightHandSideTmp = (double*) calloc(numColsDirect,sizeof(double)); spMatMultiply(precondMat,rightHandSide,rightHandSideTmp,matNum); /* Note that rightHandSideTmp and rightHandSide do not have the * same norm. In fact they may differ considerably, so make sure * this is taken into account when selecting the accuracy of the * solution. At the moment I'm slightly at a loss on how to do * this accurately. For now, the tolerance will be scaled by * ||Pb||/||b||, where P is the preconditioner and b is the right * hand side (Pb is the new right hand side). * Issue a warning statement about this */ fprintf(stderr,"%s: WARNING: Scaling tolerance with ||Pb||/||b||!\n", fctName); for (i=0,norm1=0.0,norm2=0.0;i<numColsDirect;i++){ norm1 += rightHandSide[i]*rightHandSide[i]; norm2 += rightHandSideTmp[i]*rightHandSideTmp[i]; } norm1 = sqrt(norm1); norm2 = sqrt(norm2); if(norm1>0.0 && modifyTol){ tol2 = tol*norm2/norm1; fprintf(stderr, "%s: Aiming for tolerance %g, rather than the specified %g!\n", fctName,tol2,tol); } else tol2 = tol; /* Now solve PAx = y */ iter = gmres(solutionVector, rightHandSideTmp, numColsDirect, tol2, maxiter, fullMatrixMultiply, (void*) bundleData); FREE(rightHandSideTmp); } printf("%s: GMRES used %d iterations\n",fctName,iter); /* Test the solution making a matrix-vector product * (no preconditioning) A*x and comparing with the right-hand-side */ if (testSolution) { bundleData->precondType = "none"; testVector = (double*) calloc(numColsDirect,sizeof(double)); fullMatrixMultiply(solutionVector,testVector,numColsDirect, (void*)bundleData); for (i=0, err=0.0; i<numColsDirect; i++) err += (testVector[i]-rightHandSide[i]) *(testVector[i]-rightHandSide[i]); err=sqrt(err); printf(" Estimated ||err||: %g\n",err); } /* TEST SECTION */ if (0){ if (0){ for (i=0; i<numColsDirect; i++){ printf("%g %g\n",solutionVector[i],rightHandSide[i]); } } /*dumpSparseMatrixTranspose(precondMat,0);*/ if (0){ int j; for (j=0;j<numColsDirect;j++){ for (i=0; i<numColsDirect; i++) testVector[i]=solutionVector[i]=0.0; testVector[j]=1; fullMatrixMultiply(testVector,solutionVector,numColsDirect, (void*)bundleData); printf("Column %d: \n",j); for (i=0; i<numColsDirect; i++) printf(" %12.6e",solutionVector[i]); printf("\n"); } } if (0){/* Dump transpose matrix to file: */ int j; FILE *dumpFile; dumpFile = fopen("mat.out","w"); printf("Writing to mat.out\n"); for (j=0;j<numColsDirect;j++){ for (i=0; i<numColsDirect; i++) testVector[i]=solutionVector[i]=0.0; testVector[j]=1; fullMatrixMultiply(testVector,solutionVector,numColsDirect, (void*)bundleData); for (i=0; i<numColsDirect; i++) fprintf(dumpFile," %15.8e",solutionVector[i]); fprintf(dumpFile,"\n"); } fclose(dumpFile); } if (0){ /* Calculate and write A*e_1: */ int j; FILE *dumpFile; dumpFile = fopen("a_times_e1.out","w"); j=0; for (i=0; i<numColsDirect; i++) testVector[i]=solutionVector[i]=0.0; testVector[j]=1; fullMatrixMultiply(testVector,solutionVector,numColsDirect, (void*)bundleData); printf("Writing to %s\n","a_times_e1.out"); for (i=0; i<numColsDirect; i++) fprintf(dumpFile," %12.6e\n",solutionVector[i]); } } /* Test a preconditioner. For a small system P*A=I, so PA*b=b for (i=0; i<numColsDirect; i++) testVector[i]=solutionVector[i]=0.0; bundleData->precondType = "none"; testVector = (double*) calloc(numColsDirect,sizeof(double)); fullMatrixMultiply(rightHandSide,testVector,numColsDirect, (void*)bundleData); spMatMultiply(precondMat,testVector,solutionVector,matNum); for (i=0; i<numColsDirect; i++) printf(" %16.8e %16.8e %16.8e \n",rightHandSide[i],solutionVector[i],testVector[i]); */ /* Free working vector and other stuff used. */ IFFREE(testVector); /*FREE(solutionVector); FREE(rightHandSide);*/ if (strcmp(precondType,"right")==0){ FREE(bundleData->workSrc); } else if (strcmp(precondType,"left")==0){ FREE(bundleData->workEval); } return; /* Should probably return (a pointer to) the solution vector? */ } /* End of routine solveFull */
bool topologychassishw::update(deviceinfo *pinfo) { if(pinfo == NULL) return false; int index = 1; char *value = NULL; string str; TABLECOL_ITEMS IfIndex; if(pinfo->m_isjuniper == true) { IfIndex.ss << ".1.3.6.1.4.1.2636.3.1.8.1.6."; if((m_subs = pinfo->m_devchassis.cloneof(IfIndex.ss.str())) == NULL) return false; } else { IfIndex.ss << ".1.3.6.1.2.1.47.1.1.1.1.2."; if((m_subs = pinfo->m_devchassis.cloneof(IfIndex.ss.str())) == NULL) return false; } while((value = m_subs->remove_key()) != NULL) { clear(); if(pinfo->m_isjuniper == true) { IfIndex.p = value + strlen(".1.3.6.1.4.1.2636.3.1.8.1.6."); // IfIndex CardAlias.ss << ".1.3.6.1.4.1.2636.3.1.8.1.4." << IfIndex.p; CardDescr.ss << ".1.3.6.1.4.1.2636.3.1.8.1.6." << IfIndex.p; CardHW.ss << ".1.3.6.1.4.1.2636.3.1.8.1.10." << IfIndex.p; CardManuf.ss << ".1.3.6.1.4.1.2636.3.1.8.1.2." << IfIndex.p; CardModel.ss << ".1.3.6.1.4.1.2636.3.1.8.1.3." << IfIndex.p; CardOrder.ss << ".1.3.6.1.4.1.2636.3.1.8.1.11." << IfIndex.p; CardParent.ss << ".1.3.6.1.4.1.2636.3.1.8.1.1." << IfIndex.p; CardPhyName.ss << ".1.3.6.1.4.1.2636.3.1.8.1.12." << IfIndex.p; CardSerial.ss << ".1.3.6.1.4.1.2636.3.1.8.1.7." << IfIndex.p; CardSW.ss << ".1.3.6.1.4.1.2636.3.1.8.1.8." << IfIndex.p; CardType.ss << ".1.3.6.1.4.1.2636.3.1.8.1.5." << IfIndex.p; // tmpInfo.chassis_type = 0; //tmpInfo.chassis_class = 0; // ref: http://www.oidview.com/mibs/2636/JUNIPER-MIB.html } else { IfIndex.p = value + strlen(".1.3.6.1.2.1.47.1.1.1.1.2."); // IfIndex CardAlias.ss << ".1.3.6.1.2.1.47.1.1.1.1.14." << IfIndex.p; CardDescr.ss << ".1.3.6.1.2.1.47.1.1.1.1.2." << IfIndex.p; CardHW.ss << ".1.3.6.1.2.1.47.1.1.1.1.9." << IfIndex.p; CardManuf.ss << ".1.3.6.1.2.1.47.1.1.1.1.12." << IfIndex.p; CardModel.ss << ".1.3.6.1.2.1.47.1.1.1.1.13." << IfIndex.p; CardOrder.ss << ".1.3.6.1.2.1.47.1.1.1.1.6." << IfIndex.p; CardParent.ss << ".1.3.6.1.2.1.47.1.1.1.1.4." << IfIndex.p; // Container CardPhyName.ss << ".1.3.6.1.2.1.47.1.1.1.1.7." << IfIndex.p; CardSerial.ss << ".1.3.6.1.2.1.47.1.1.1.1.11." << IfIndex.p; CardSW.ss << ".1.3.6.1.2.1.47.1.1.1.1.10." << IfIndex.p; CardType.ss << ".1.3.6.1.2.1.47.1.1.1.1.5." << IfIndex.p; } if(runquery(pinfo) == true) index++; IFFREE(value); } IFDESTROY(m_subs); return true; };
latency::~latency() { IFFREE(m_xtablename); }