int main(int argc, const char * argv[]) { av_register_all(); av_log_set_callback(ffmpegLog); for (int sig : { SIGSEGV, SIGTERM, SIGINT, SIGHUP, SIGABRT}) { signal(sig, handleSignal); } if (argc != 4) { Err<<"invalid arguments, use: "<<argv[0]<<" tcp://srv:port uuid logFile.log"<<endl; return -1; } string addr = argv[1]; string logf = argv[3]; int64_t uuid = stol(argv[2]); openLogFile(logf); const char * stars = " *\n *\n *\n"; Log<<stars<<" * Starting id: "<<uuid<<", pushing to: "<<addr<<endl<<stars<<endl; try { MainLoop loop; loop.init(ZAddr(addr), uuid); loop.run(); return 0; } catch (const exception & ex) { Err<<"exception in main: "<<toStr(ex)<<endl; } catch (...) { Err<<"unknown exception in main"<<endl; } return -1; }
void Init() { System::Init(); MainLoop oMainLoop; // Creates an object of the 'MainLoop' class oMainLoop.Run(); }
bool TextureDemo::Render() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); MainLoop *ml = MainLoop::Get(); if (ml) { RenderSystem *rs = ml->RenderSys(); if (rs) { unsigned int w = rs->screenWidth(); unsigned int h = rs->screenHeight(); if (w <= h) glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, 2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0); else glOrtho(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0); } } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushAttrib(GL_ALL_ATTRIB_BITS); theModel->Draw(); glPopAttrib(); return true; }
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { MainLoop main; CreateConsole(); main.Run(); CloseWindow(); return 0; }
void run(const std::string & inFileName) { // Create a main loop object. MainLoop loop; // Create gstreamer elements ScopedObject<GstElement> pipeline(Pipeline::Create("audio-player")); ScopedObject<GstElement> source(Element::Create(pipeline, "filesrc", "file-source")); ScopedObject<GstElement> demuxer(Element::Create(pipeline, "oggdemux", "ogg-demuxer")); ScopedObject<GstElement> decoder(Element::Create(pipeline, "vorbisdec", "vorbis-decoder")); ScopedObject<GstElement> conv(Element::Create(pipeline, "audioconvert", "converter")); ScopedObject<GstElement> sink(Element::Create(pipeline, "autoaudiosink", "audio-output")); // We set the input filename to the source element g_object_set(G_OBJECT(source.get()), "location", inFileName.c_str(), NULL); // Link the first half Element::Link(source, demuxer); // Link the second half Element::Link(decoder, conv, sink); // Note that the demuxer will be linked to the decoder dynamically. // The reason is that Ogg may contain various streams (for example // audio and video). The source pad(s) will be created at run time, // by the demuxer when it detects the amount and nature of streams. // Therefore we connect a callback function which will be executed // when the "pad-added" is emitted. g_signal_connect(demuxer, "pad-added", G_CALLBACK(on_pad_added), decoder); // We add a message handler. Also pass the loop as an extra argument. ScopedBusListener busListener(pipeline.get(), boost::bind(&on_bus_message, _1, _2, &loop)); // Set the pipeline to "playing" state std::cout << "Now playing: " << inFileName << std::endl; Pipeline::SetState(pipeline, GST_STATE_PLAYING); // Start the event loop std::cout << "Running..." << std::endl; loop.run(); // Out of the main loop, clean up nicely std::cout << "Returned, stopping playback" << std::endl; // Stop the pipeline Element::SetState(pipeline, GST_STATE_NULL); std::cout << "Deleting pipeline" << std::endl; // ScopedObject performs cleanup in its destructor. }
void do_benchmark(Canvas &canvas) { BenchmarkCollection benchmark_collection; MainLoop *loop; benchmark_collection.populate_from_options(); if (benchmark_collection.needs_decoration()) loop = new MainLoopDecoration(canvas, benchmark_collection.benchmarks()); else loop = new MainLoop(canvas, benchmark_collection.benchmarks()); while (loop->step()); Log::info("=======================================================\n"); Log::info(" glmark2 Score: %u \n", loop->score()); Log::info("=======================================================\n"); delete loop; }
//---------------------------------------------------------------------- // main //---------------------------------------------------------------------- int main_gdbserver (int argc, char *argv[]) { Error error; MainLoop mainloop; #ifndef _WIN32 // Setup signal handlers first thing. signal (SIGPIPE, signal_handler); MainLoop::SignalHandleUP sighup_handle = mainloop.RegisterSignal(SIGHUP, sighup_handler, error); #endif const char *progname = argv[0]; const char *subcommand = argv[1]; argc--; argv++; int long_option_index = 0; int ch; std::string platform_name; std::string attach_target; std::string named_pipe_path; std::string log_file; StringRef log_channels; // e.g. "lldb process threads:gdb-remote default:linux all" int unnamed_pipe_fd = -1; bool reverse_connect = false; // ProcessLaunchInfo launch_info; ProcessAttachInfo attach_info; bool show_usage = false; int option_error = 0; #if __GLIBC__ optind = 0; #else optreset = 1; optind = 1; #endif std::string short_options(OptionParser::GetShortOptionString(g_long_options)); while ((ch = getopt_long_only(argc, argv, short_options.c_str(), g_long_options, &long_option_index)) != -1) { switch (ch) { case 0: // Any optional that auto set themselves will return 0 break; case 'l': // Set Log File if (optarg && optarg[0]) log_file.assign(optarg); break; case 'c': // Log Channels if (optarg && optarg[0]) log_channels = StringRef(optarg); break; case 'p': // platform name if (optarg && optarg[0]) platform_name = optarg; break; case 'N': // named pipe if (optarg && optarg[0]) named_pipe_path = optarg; break; case 'U': // unnamed pipe if (optarg && optarg[0]) unnamed_pipe_fd = StringConvert::ToUInt32(optarg, -1); break; case 'r': // Do nothing, native regs is the default these days break; case 'R': reverse_connect = true; break; #ifndef _WIN32 case 'S': // Put llgs into a new session. Terminals group processes // into sessions and when a special terminal key sequences // (like control+c) are typed they can cause signals to go out to // all processes in a session. Using this --setsid (-S) option // will cause debugserver to run in its own sessions and be free // from such issues. // // This is useful when llgs is spawned from a command // line application that uses llgs to do the debugging, // yet that application doesn't want llgs receiving the // signals sent to the session (i.e. dying when anyone hits ^C). { const ::pid_t new_sid = setsid(); if (new_sid == -1) { const char *errno_str = strerror(errno); fprintf (stderr, "failed to set new session id for %s (%s)\n", LLGS_PROGRAM_NAME, errno_str ? errno_str : "<no error string>"); } } break; #endif case 'a': // attach {pid|process_name} if (optarg && optarg[0]) attach_target = optarg; break; case 'h': /* fall-through is intentional */ case '?': show_usage = true; break; } } if (show_usage || option_error) { display_usage(progname, subcommand); exit(option_error); } if (!LLDBServerUtilities::SetupLogging(log_file, log_channels, LLDB_LOG_OPTION_PREPEND_TIMESTAMP)) return -1; Log *log(lldb_private::GetLogIfAnyCategoriesSet (GDBR_LOG_VERBOSE)); if (log) { log->Printf ("lldb-server launch"); for (int i = 0; i < argc; i++) { log->Printf ("argv[%i] = '%s'", i, argv[i]); } } // Skip any options we consumed with getopt_long_only. argc -= optind; argv += optind; if (argc == 0) { display_usage(progname, subcommand); exit(255); } // Setup the platform that GDBRemoteCommunicationServerLLGS will use. lldb::PlatformSP platform_sp = setup_platform (platform_name); GDBRemoteCommunicationServerLLGS gdb_server (platform_sp, mainloop); const char *const host_and_port = argv[0]; argc -= 1; argv += 1; // Any arguments left over are for the program that we need to launch. If there // are no arguments, then the GDB server will start up and wait for an 'A' packet // to launch a program, or a vAttach packet to attach to an existing process, unless // explicitly asked to attach with the --attach={pid|program_name} form. if (!attach_target.empty ()) handle_attach (gdb_server, attach_target); else if (argc > 0) handle_launch (gdb_server, argc, argv); // Print version info. printf("%s-%s", LLGS_PROGRAM_NAME, LLGS_VERSION_STR); ConnectToRemote(mainloop, gdb_server, reverse_connect, host_and_port, progname, subcommand, named_pipe_path.c_str(), unnamed_pipe_fd); if (! gdb_server.IsConnected()) { fprintf (stderr, "no connection information provided, unable to run\n"); display_usage (progname, subcommand); return 1; } mainloop.Run(); fprintf(stderr, "lldb-server exiting...\n"); return 0; }
void start_ml(void *data, const char *el, const char **attr) { MainLoop *ml = (MainLoop *)data; ml->process_element(el, attr); }
int main(int argc, char *argv[]) { UsersPermissions users,user2; // users.setUsername("root"); // users.setPassword("root"); // users.store(); // // user2.setUsername("monitor"); // user2.setPassword("monitor"); // user2.setPermissionMode("ServerSettings", user2.none); // user2.setPermissionMode("AgentSettings", user2.write); // user2.setPermissionMode("UserSettings", user2.read); // user2.store(); // bool res = user2.load("root"); // if (user2.isWriteOk("agent settings")) std::cout << "yes" << std::endl; // // QString msg = user2.toQString(); // std::cout << msg.toStdString() << std::endl; // users.fromString(msg); // QString msg2 = users.toQString(); // std::cout << msg2.toStdString() << std::endl; // // return 0; //printf("wwwww\n"); writeLog.setPathToLogFile("/home/yurec/log.txt"); writeLog.initLogger(); writeLog.setLogLevel(DebusLogger::allLevels); writeLog.showLogLevel(true); writeLog.enableLogging(true); if ( !globalServerConfig.loadConfig() ) writeLog.fatal() << "Error read configuration file" << writeLog.endl; //agents.setDir(globalServerConfig.getInclude()); QCoreApplication app(argc, argv); QTimer::singleShot(100, &mainLoop, SLOT(startMainloop())); app.exec(); //mainLoop.startMainloop(); exit(0); pid_t pid = fork(); switch (pid){ case -1:{ writeLog.fatal() << "Server not started, errno=" << errno << " (" << strerror(errno) <<" )" << writeLog.endl; exit(EXIT_FAILURE); } case 0:{ umask(0); pid_t sid = setsid(); if(sid < 0) { writeLog.fatal() << "Server not started, errno=" << errno << " (" << strerror(errno) <<" )" << writeLog.endl; exit(EXIT_FAILURE); } if((chdir("/")) < 0) { writeLog.fatal() << "Server not started, can not chdir</> errno=" << errno << " (" << strerror(errno) <<" )" << writeLog.endl; exit(EXIT_FAILURE); } signal(SIGTERM, sigTerminate); signal(SIGHUP, sigHup); pidOfMainLoop = getpid(); //writeLog.debug() << "created new process with pid " << pidOfMainLoop << writeLog.endl; mainLoop.startMainloop(); exit(EXIT_SUCCESS); } default: { make_dirs(D_PIDFILE); FILE *pPidFile= fopen(D_PIDFILE, "w"); if (pPidFile == NULL){ writeLog.fatal() << "Can't open pid file, errno:" << errno << " (" << strerror(errno) << ")" << writeLog.endl; kill(pid,SIGTERM); exit(EXIT_FAILURE); } fprintf(pPidFile, "%d\n", pid); fclose(pPidFile); exit(EXIT_SUCCESS); } } }