int main(int argc, char** argv) { int c, i, optindex; static struct option long_options[] = { {"host", required_argument, NULL, 'h'}, {"port", required_argument, NULL, 'p'}, {"username", required_argument, NULL, 'U'}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; if (argc == 1 || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-?")) help(); while ((c = getopt_long(argc, argv, "h:p:U:", long_options, &optindex)) != -1) { switch (c) { case 'h': /* host for tranlsting oids */ pghost = optarg; break; case 'p': /* port for translating oids */ pgport = optarg; break; case 'U': /* username for translating oids */ username = optarg; break; default: fprintf(stderr, "Try \"changetrackingdump --help\" for more information.\n"); exit(1); } } if(pghost) { conn = DBConnect(pghost, pgport, "template1", username); } dbQry = createPQExpBuffer(); for (i = optind; i < argc; i++) { char *fname = argv[i]; logFd = open(fname, O_RDONLY | PG_BINARY, 0); if (logFd < 0) { perror(fname); continue; } dumpChangeTracking(fname); } exit_gracefuly(0); /* just to avoid a warning */ return 0; }
/* * Atempt to get the name of database (if there's a database connection) */ static void getDbName(uint32 db) { resetPQExpBuffer(dbQry); if((conn) && (lastDbOid != db)) { PQclear(res); appendPQExpBuffer(dbQry, "SELECT datname FROM pg_database WHERE oid = %i", db); res = PQexec(conn, dbQry->data); if (PQresultStatus(res) != PGRES_TUPLES_OK) { fprintf(stderr, "SELECT FAILED: %s", PQerrorMessage(conn)); PQclear(res); exit_gracefuly(1); } resetPQExpBuffer(dbQry); lastDbOid = db; if(PQntuples(res) > 0) { strcpy(dbName, PQgetvalue(res, 0, 0)); // Database changed makes new connection PQfinish(lastDbConn); lastDbConn = DBConnect(pghost, pgport, dbName, username); return; } } else if(lastDbOid == db) return; /* Didn't find the name, return string with oid */ sprintf(dbName, "%u", db); return; }
/* * * Function: onTxStart * Description: 接收到CMP平台请求时处理 * Return: * Other: */ int onTxStart( char *pczExecFile ) { if( TestDBConnect() != 0 ) { DBDisconnect(); usleep(500000); DBConnect(); } /**交易开始时候重新连接*************** *****************/ return 0; }
int main(int argc, char** argv) { int c, i, optindex; bool oid2name = false; bool oid2name_gen = false; char *pghost = NULL; /* connection host */ char *pgport = NULL; /* connection port */ char *pguser = NULL; /* connection username */ char *dbname = NULL; /* connection database name */ char *oid2name_file = NULL; static struct option long_options[] = { {"transactions", no_argument, NULL, 't'}, {"statements", no_argument, NULL, 's'}, {"stats", no_argument, NULL, 'S'}, {"hide-timestamps", no_argument, NULL, 'T'}, {"rmid", required_argument, NULL, 'r'}, {"oid2name", no_argument, NULL, 'n'}, {"gen_oid2name", no_argument, NULL, 'g'}, {"xid", required_argument, NULL, 'x'}, {"host", required_argument, NULL, 'h'}, {"port", required_argument, NULL, 'p'}, {"user", required_argument, NULL, 'U'}, {"dbname", required_argument, NULL, 'd'}, {"file", required_argument, NULL, 'f'}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; if (argc == 1 || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-?")) help(); pghost = strdup("localhost"); pgport = strdup("5432"); pguser = getenv("USER"); dbname = strdup("postgres"); oid2name_file = strdup(DATADIR "/contrib/" OID2NAME_FILE); while ((c = getopt_long(argc, argv, "sStTngr:x:h:p:U:d:f:", long_options, &optindex)) != -1) { switch (c) { case 's': /* show statements */ statements = true; break; case 'S': /* show statistics */ enable_stats = true; enable_rmgr_dump(false); break; case 't': transactions = true; /* show only transactions */ break; case 'T': /* hide timestamps (used for testing) */ hideTimestamps = true; break; case 'n': oid2name = true; break; case 'g': oid2name_gen = true; break; case 'r': /* output only rmid passed */ rmid = atoi(optarg); break; case 'x': /* output only xid passed */ xid = atoi(optarg); break; case 'h': /* host for tranlsting oids */ pghost = optarg; break; case 'p': /* port for translating oids */ pgport = optarg; break; case 'U': /* username for translating oids */ pguser = optarg; break; case 'd': /* database name for translating oids */ dbname = optarg; break; case 'f': oid2name_file = optarg; break; default: fprintf(stderr, "Try \"xlogdump --help\" for more information.\n"); exit(1); } } if (statements && transactions) { fprintf(stderr, "options \"statements\" (-s) and \"transactions\" (-t) cannot be used together\n"); exit(1); } if (rmid>=0 && transactions) { fprintf(stderr, "options \"rmid\" (-r) and \"transactions\" (-t) cannot be used together\n"); exit(1); } if (oid2name) { if ( !oid2name_from_file(oid2name_file) ) { /* if not found in share/contrib, read from the cwd. */ oid2name_from_file(OID2NAME_FILE); } if ( !DBConnect(pghost, pgport, dbname, pguser) ) fprintf(stderr, "WARNING: Database connection to lookup the system catalog is not available.\n"); } /* * Generate an oid2name cache file. */ if (oid2name_gen) { if ( !DBConnect(pghost, pgport, dbname, pguser) ) exit_gracefuly(1); if (oid2name_to_file("oid2name.out")) { printf("oid2name.out successfully created.\n"); } exit_gracefuly(0); } for (i = optind; i < argc; i++) { char *fname = argv[i]; logFd = open(fname, O_RDONLY | PG_BINARY, 0); if (logFd < 0) { perror(fname); continue; } dumpXLog(fname); } if (enable_stats) print_xlog_stats(); exit_gracefuly(0); /* just to avoid a warning */ return 0; }
void main(int argc, char *argv[]) { ifstream bcpInfile; // local import file holding records to bcp to x_import table int hndl; // file handle char szXfrFile[128]; // holds name of delimited import file char szTmpFile[128]; // holds name of renamed delimited import file char szXfrLocalFile[128]; // holds name of delimited import file with local dir prepended int intBcpCount; // number of rows bcp'd // Open import log and import error log files if ( !OpenLogFiles() ) return; if ( argc >= 7 ) szSystem = argv[7]; else szSystem = ""; // Check if user wants help or if incorrect args entered if ( !CheckArgs(argc, argv) ) return; // Create transfer filenames wsprintf(szXfrFile, "%s_cags.xfr", argv[7] ); wsprintf(szTmpFile, "%s_cags.yyy", argv[7] ); // Connect to database and init db structures if ( !DBConnect(argv[1], argv[2], argv[3]) ) return; // // Check if local wms_cags.xfr exists to BCP records into import table // wsprintf(szXfrLocalFile, "%s%s", "./transfer/", szXfrFile ); if ( FileSize(szXfrLocalFile) > -1 ) // file exists { // Open local wms_cags.xfr bcpInfile.open(szXfrLocalFile, ios::nocreate, filebuf::sh_none); if ( !bcpInfile.is_open() ) { // Failed open so get out and retry on next run errfile << ERROR_PREFIX << "failed to open bcp input file" << endl; return; } else { // Call bcp routines to move data from import file into x_import table // Note: If migrated to another RDBMS most changes will be to this function if ( (intBcpCount = BCPInRecords(bcpInfile, argv[7])) != -1 ) { // Delete local import file now that its records are in import table bcpInfile.close(); f_deletefile(szXfrLocalFile); logfile << INFO_PREFIX << "successfull BCP of " << intBcpCount << " records into import table" << endl; } else { // Failed bcp so don't delete and get out to retry on next run bcpInfile.close(); errfile << ERROR_PREFIX << "failed BCP of import file to import table" << endl; return; } } } else { if ( FileSize(szXfrLocalFile) == -1 ) logfile << WARNING_PREFIX << "no records to import from " << szXfrLocalFile << " this run" << endl; else errfile << ERROR_PREFIX << "error opening local import file " << szXfrLocalFile << endl; } // // Logon to ftp server to get remote wms_cags.xfr to be bcp'd next import run // hndl = ftp_login(argv[4], argv[5], argv[6], ""); if ( hndl == -1 ) { errfile << ERROR_PREFIX << "failed ftp_login" << endl; return; } // Set current remote transfer directory if ( ftp_cd(hndl, argv[8]) == -1 ) { errfile << ERROR_PREFIX << "failed ftp_cd to " << argv[8] << endl; return; } // Check for no left over records from prior import and new records to import if ( !ftp_exist(hndl, szTmpFile) && ftp_exist(hndl, szXfrFile) ) { // If so, then rename prior to ftp_get to prevent contention with remote site if ( ftp_rename(hndl, szXfrFile, szTmpFile) == -1 ) { // ftp_rename failed so just log message and try again next invocation errfile << ERROR_PREFIX << "failed ftp_remame of " << szXfrFile << " to " << szTmpFile << " will retry next run" << endl; return; } } // Check for either left over records or new records in tmp file to import if ( ftp_exist(hndl, szTmpFile) ) { // If so, then ftp them to local directory if ( ftp_get(hndl, szTmpFile, szXfrLocalFile) == -1 ) { // ftp_get failed so do nothing here and retry next invovation errfile << ERROR_PREFIX << "failed ftp_get of " << szTmpFile << " will retry next run" << endl; } else { if ( ftp_delete(hndl, szTmpFile) == -1 ) { // ftp_delete failed so delete local to prevent re-importing next invocation f_deletefile(szXfrLocalFile); errfile << ERROR_PREFIX << "failed ftp_delete of " << szTmpFile << endl; } else { // successfull FTP logfile << INFO_PREFIX << "successfull FTP from remote site to " << szXfrLocalFile << endl; } } } else logfile << WARNING_PREFIX << "no records to ftp from remote site this run" << endl; // Close opened objects if ( !logfile.is_open() ) logfile.close(); if ( !errfile.is_open() ) errfile.close(); dbexit(); // close database connection ftp_quit(hndl); // close ftp connection }
/* * * Function: onSysStart * Description: 系统启动处理 * Return: * Other: */ int onSysStart( char *pczExecFile ) { return DBConnect(); return 0; }
void Init(){ for (int i = 0; i < 50; i++){ Gesture_ g; g_gestureManager.gestures.push_back(g); } DBConnect(); DBLoadAllGestures(); loadFTable(); // Initialise GLFW if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(1); } glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Open a window and create its OpenGL context if (!glfwOpenWindow(1050, 690, 0, 0, 0, 0, 32, 0, GLFW_WINDOW)) { fprintf(stderr, "Failed to open GLFW window.\n"); glfwTerminate(); exit(1); } // Initialize GLEW glewExperimental = true; // Needed for core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); exit(1); } glfwSetWindowTitle("Gesture Recognition"); glfwDisable(GLFW_STICKY_KEYS); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); // Init AntTweakBar if (!TwInit(TW_OPENGL_CORE, NULL)){ fprintf(stderr, "Failed to initialize AntTweakBar\n"); exit(1); } TwWindowSize(1050, 690); CreateBar(); //leap init if (g_leapController.isConnected()) { if (!g_leapController.addListener(g_leapListener)) std::cout << "Leap controller isnt accepting the listener" << std::endl; } else std::cout << "Leap controller isnt connected" << std::endl; }
nsresult sbIPDDevice::ConnectInternal() { nsresult rv; // Do nothing if device is already connected. If the device is not connected, // nothing should be accessing the "connect lock" fields. { sbAutoReadLock autoConnectLock(mConnectLock); if (mConnected) return NS_OK; } // Invoke the super-class. rv = sbBaseDevice::Connect(); NS_ENSURE_SUCCESS(rv, rv); // Get the device properties. nsCOMPtr<nsIPropertyBag2> properties = do_QueryInterface(mCreationProperties, &rv); NS_ENSURE_SUCCESS(rv, rv); // Get the device mount path. rv = properties->GetPropertyAsAString(NS_LITERAL_STRING("MountPath"), mMountPath); NS_ENSURE_SUCCESS(rv, rv); // Get the Firewire GUID. rv = properties->GetPropertyAsAString(NS_LITERAL_STRING("FirewireGUID"), mFirewireGUID); if (NS_SUCCEEDED(rv)) { FIELD_LOG (("Connect %s\n", NS_LossyConvertUTF16toASCII(mFirewireGUID).get())); } else { FIELD_LOG(("Connect could not get iPod Firewire GUID.\n")); } // Connect the device capabilities. rv = CapabilitiesConnect(); NS_ENSURE_SUCCESS(rv, rv); // Connect the iPod database. rv = DBConnect(); NS_ENSURE_SUCCESS(rv, rv); // Connect the iPod preference services. rv = PrefConnect(); NS_ENSURE_SUCCESS(rv, rv); // Connect the Songbird device library. rv = LibraryConnect(); NS_ENSURE_SUCCESS(rv, rv); // Connect the FairPlay services. rv = FPConnect(); NS_ENSURE_SUCCESS(rv, rv); // Mark the device as connected. After this, "connect lock" fields may be // used. { sbAutoWriteLock autoConnectLock(mConnectLock); mConnected = PR_TRUE; } // Start the iPod request processing. rv = ReqProcessingStart(); NS_ENSURE_SUCCESS(rv, rv); // Mount the device. //XXXeps Do in DBConnect rv = PushRequest(TransferRequest::REQUEST_MOUNT, nsnull, mDeviceLibrary); NS_ENSURE_SUCCESS(rv, rv); // Set up the iPod for the first time if needed rv = SetUpIfNeeded(); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
FrontEnd::FrontEnd(wxWindow* parent, int id, const wxString& title): wxFrame(parent, id, title)//, pos, size, wxDEFAULT_FRAME_STYLE) { //_CrtSetBreakAlloc(3446); //_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF); //////////////////////////////////////////////////// // books creation m_panel = NULL; m_bookCtrl = NULL; //// create a dummy image list with a few icons //const wxSize imageSize(32, 32); //m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); //m_imageList-> // Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); //m_imageList-> // Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); //m_imageList-> // Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); //m_imageList-> // Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); // Panel m_panel = new wxPanel(this); // Set sizers m_sizerFrame = new wxBoxSizer(wxVERTICAL); // Create list book int flags; flags = wxBK_LEFT; m_bookCtrl = new wxListbook(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, flags); wxListView* list = ((wxListbook*)m_bookCtrl)->GetListView(); list->SetColumnWidth(0, 140); if ( !m_bookCtrl ) assert(0); m_bookCtrl->Hide(); //m_bookCtrl->SetImageList(m_imageList); init_pages(m_bookCtrl); m_sizerFrame->Add(m_bookCtrl, wxSizerFlags(5).Expand().Border()); //m_sizerFrame->Insert(0, m_bookCtrl, wxSizerFlags(15).Expand().Border()); m_sizerFrame->Show(m_bookCtrl); m_sizerFrame->Layout(); //////////////////////////////////////////////////// m_btnNextSong = new wxButton(m_panel, ID_NEXT_SONG, "Next Song"); m_sizerFrame->Add(m_btnNextSong, wxSizerFlags(1).Expand()); m_panel->SetSizer(m_sizerFrame); m_sizerFrame->SetSizeHints(this); InitMenus(); InitProperties(); if(!DBConnect("KTVAdmin", "admin", "localhost", "ktv")) wxMessageBox("Cannot connect to the database£¡", "Error"); }
/* ******************************* * MAIN * *********************************/ int main(int argc, char *argv[]) { int i, j; /* Iteradores para for. */ int r; /* Retorno das funcoes (representa codigo de erro ou sucesso). */ float totalRainfall; /* Recebe do arquivo out do SWMM a precipitacao total. */ float depth; /* Recebe do arquivo out do SWMM o nivel da agua na juncao. */ float flow; /* Recebe do arquivo out do SWMM a vazao no conduit. */ char inpFile[] = "data/2010.inp"; /* Arquivo de entrada do SWMM. */ char rptFile[] = "data/2010.rpt"; /* Arquivo de relatorio de execucao do SWMM. */ char outFile[] = "data/2010.out"; /* Arquivo de saida do SWMM. */ FILE *DBConn; /* Arquivo .dat de entrada com dados da estacao. */ int iteracao = 1; /* = "linha" do original. Iteracao = 1 -> realiza os calculos em cima de uma linha de dados. Iteracao = 2 -> realiza calculos 2a vez... */ double pobs; /* Precipitacao observada. */ stationData stat; /* Struct stationData com os dados da estacao. */ //return UpdateInitFlow(inpFile, "L-50", 15); /* ESTABELECE CONEXAO COM O "DB" (arquivo). */ DBConn = DBConnect(); if (DBConn == NULL) /* Erro. */ { printf("\nErro no retorno da conexao com <banco>\n"); return 1; } /* CARREGA DADOS DO BANCO (arquivo) NAS VARIAVEIS E CHAMA PREVISAO DE PRECIPITACAO. */ while((LoadDBData(DBConn, &stat, &pobs)) == 0) { PrecForecast(&stat, &pobs, &iteracao); } /* CHECAGEM E UTILIZACAO DE DADOS VGI. */ // VGICheck(); /* Execucao do SWMM. */ r = RunSwmmDll(inpFile, rptFile, outFile); if (r > 0) { printf("\nA execucao do SWMM nao obteve sucesso; codigo do erro = %d\n", r); } else { /* Abre outfile como um arquivo de saida do SWMM. */ r = OpenSwmmOutFile(outFile); if (r == 1) { printf("\nResultados invalidos no arquivo de saida do SWMM.\n"); } else if (r == 2) { printf("\nO arquivo nao eh um arquivo de saida do SWMM.\n"); } else { printf("\nPeriodo No ou Precipitacao Altura Vazao"); printf("\nde Tempo Link Total Total Total"); printf("\n==================================================="); for(i = 1; i <= SWMM_Nperiods; i++) { for(j = 0; j < 182; j++) { GetSwmmResult(3, 0, 1, i, &totalRainfall); GetSwmmResult(2, j, 1, i, &depth); GetSwmmResult(2, j, 0, i, &flow); printf("\n%6d %6d %8.2f %8.2f %8.2f", i, j + 1, totalRainfall, depth, flow); } } CloseSwmmOutFile(); } } remove(rptFile); remove(outFile); remove("data/precOutSample.dat"); return 0; }