コード例 #1
0
ファイル: ss_app.cpp プロジェクト: DanAurea/boinc
int update_data() {
    int retval = rpc.get_state(cc_state);
    if (!retval) {
        retval = rpc.get_cc_status(cc_status);
    }
    return retval;
}
コード例 #2
0
bool CBOINCClientManager::IsBOINCCoreRunning() {
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function Begin"));

    int retval=0;
    bool running = false;
    HOST_INFO hostinfo;
    RPC_CLIENT rpc;

#ifdef __WXMSW__
    if (IsBOINCServiceInstalled()) {
        running = (FALSE != IsBOINCServiceStarting()) || (FALSE != IsBOINCServiceRunning());
    } else {
#endif
    // If set up to run as a daemon, allow time for daemon to start up
    for (int i=0; i<10; i++) {
        retval = rpc.init("localhost");  // synchronous is OK since local
        wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Connecting to core client returned '%d'"), retval);
        retval = rpc.get_host_info(hostinfo);
        wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Requesting host info... retval '%d'"), retval);
        running = (retval == 0);
        rpc.close();
        if (running) break;
        if (!IsBOINCConfiguredAsDaemon()) break;
        wxSleep(1);
    }
#ifdef __WXMSW__
    }
#endif

    wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Returning '%d'"), retval);
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function End"));
    return running;
}
コード例 #3
0
void CBOINCClientManager::ShutdownBOINCCore() {
    CMainDocument*     pDoc = wxGetApp().GetDocument();
    wxInt32            iCount = 0;
    bool               bClientQuit = false;
    std::string        strPassword;

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

    if (m_bBOINCStartedByManager) {
        if (!pDoc->IsLocalClient()) {
            RPC_CLIENT rpc;
            if (!rpc.init("localhost")) {
                try {
                    strPassword = read_gui_rpc_password();
                } catch (...) {
                    // Ignore any errors here and set an empty password.
                    // This will happen if the manager does not find the
                    // GUI-RPC-password file in its working directory.
                }
                rpc.authorize(strPassword.c_str());
                if (wxProcess::Exists(m_lBOINCCoreProcessId)) {
                    rpc.quit();
                    for (iCount = 0; iCount <= 10; iCount++) {
                        if (!bClientQuit && !wxProcess::Exists(m_lBOINCCoreProcessId)) {
                            bClientQuit = true;
                            break;
                        }
                        ::wxSleep(1);
                    }
                }
            }
            rpc.close();
        } else {
            if (wxProcess::Exists(m_lBOINCCoreProcessId)) {
                pDoc->CoreClientQuit();
                for (iCount = 0; iCount <= 10; iCount++) {
                    if (!bClientQuit && !wxProcess::Exists(m_lBOINCCoreProcessId)) {
                        bClientQuit = true;
                        break;
                    }
                    ::wxSleep(1);
                }
            }
        }

        if (!bClientQuit) {
            ::wxKill(m_lBOINCCoreProcessId);
        }
    }
}
コード例 #4
0
// wxProcess::Exists and wxKill are unimplemented in WxMac-2.6.0
void CBOINCClientManager::ShutdownBOINCCore() {
    CMainDocument*     pDoc = wxGetApp().GetDocument();
    wxInt32            iCount = 0;
    std::string        strPassword;

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

    if (m_bBOINCStartedByManager) {
        if (!pDoc->IsLocalClient()) {
            RPC_CLIENT rpc;
            if (!rpc.init("localhost")) {
                try {
                    strPassword = read_gui_rpc_password();
                } catch (...) {
                    // Ignore any errors here and set an empty password.
                    // This will happen if the manager does not find the
                    // GUI-RPC-password file in its working directory.
                }
                rpc.authorize(strPassword.c_str());
                if (ProcessExists(m_lBOINCCoreProcessId)) {
                    rpc.quit();
                    for (iCount = 0; iCount <= 10; iCount++) {
                        if (!ProcessExists(m_lBOINCCoreProcessId))
                            return;
                        ::wxSleep(1);
                    }
                }
            }
            rpc.close();
        } else {
            if (ProcessExists(m_lBOINCCoreProcessId)) {
                pDoc->CoreClientQuit();
                for (iCount = 0; iCount <= 10; iCount++) {
                    if (!ProcessExists(m_lBOINCCoreProcessId))
                        return;

                    ::wxSleep(1);
                }
            }
        }
        
        // Client did not quit after 10 seconds so kill it
        kill(m_lBOINCCoreProcessId, SIGKILL);
    }
    m_lBOINCCoreProcessId = 0;
}
コード例 #5
0
ファイル: ss_app.cpp プロジェクト: freehal/boinc-freehal
int main(int argc, char** argv) {
    int retval;
    bool test = false;

    for (int i=1; i<argc; i++) {
        if (!strcmp(argv[i], "--test")) {
            test = true;
        }
        if (!strcmp(argv[i], "--retry_connect")) {
            retry_connect = true;
        }
    }
#ifdef _WIN32
    WinsockInitialize();
#endif

    if (test) {
        retval = rpc.init("localhost");
        if (!retval) {
            retval = update_data();
        }
        exit(ERR_CONNECT);
    }
    
#ifdef __APPLE__
    // For GridRepublic, the installer put a branding file in our data directory
    FILE *f = fopen("/Library/Application Support/BOINC Data/Branding", "r");
    if (f) {
        fscanf(f, "BrandId=%ld\n", &iBrandId);
        fclose(f);
    }
#else
#endif

    boinc_graphics_loop(argc, argv, "BOINC screensaver");
    boinc_finish_diag();
#ifdef _WIN32
    WinsockCleanup();
#endif
}
コード例 #6
0
void CBOINCClientManager::ShutdownBOINCCore() {
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function Begin"));

    CMainDocument*     pDoc = wxGetApp().GetDocument();
    wxInt32            iCount = 0;
    DWORD              dwExitCode = 0;
    bool               bClientQuit = false;
    std::string        strPassword;

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

    if (m_bBOINCStartedByManager) {
        if (!pDoc->IsLocalClient()) {
            RPC_CLIENT rpc;
            if (!rpc.init("localhost")) {
                try {
                    strPassword = read_gui_rpc_password();
                } catch (...) {
                    // Ignore any errors here and set an empty password.
                    // This will happen if the manager does not find the
                    // GUI-RPC-password file in its working directory.
                }
                rpc.authorize(strPassword.c_str());
                if (GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) {
                    if (STILL_ACTIVE == dwExitCode) {
                        rpc.quit();
                        for (iCount = 0; iCount <= 10; iCount++) {
                            if (!bClientQuit && GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) {
                                if (STILL_ACTIVE != dwExitCode) {
                                    wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit Detected"));
                                    bClientQuit = true;
                                    break;
                                }
                            }
                            wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit NOT Detected, Sleeping..."));
                            ::wxSleep(1);
                        }
                    }
                }
            }
            rpc.close();
        } else {
            if (GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) {
                if (STILL_ACTIVE == dwExitCode) {
                    pDoc->CoreClientQuit();
                    for (iCount = 0; iCount <= 10; iCount++) {
                        if (!bClientQuit && GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) {
                            if (STILL_ACTIVE != dwExitCode) {
                                wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit Detected"));
                                bClientQuit = true;
                                break;
                            }
                        }
                        wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit NOT Detected, Sleeping..."));
                        ::wxSleep(1);
                    }
                }
            }
        }

        if (!bClientQuit) {
            ::wxKill(m_lBOINCCoreProcessId);
        }
        m_lBOINCCoreProcessId = 0;
    }

    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function End"));
}
コード例 #7
0
ファイル: BOINCClientManager.cpp プロジェクト: Ashod/Boinc
void CBOINCClientManager::ShutdownBOINCCore(bool ShuttingDownManager) {
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function Begin"));

    CMainDocument*      pDoc = wxGetApp().GetDocument();
    wxInt32             iCount = 0;
    bool                bClientQuit = false;
    wxString            strConnectedCompter = wxEmptyString;
    wxString            strPassword = wxEmptyString;
    double              startTime = 0;
    wxDateTime          zeroTime = wxDateTime((time_t)0);
    wxDateTime          rpcCompletionTime = zeroTime;
    ASYNC_RPC_REQUEST   request;
    int                 quit_result;

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

#ifdef __WXMAC__
    // Mac Manager shuts down client only if Manager started client
    if (!m_bBOINCStartedByManager) return;
#endif

#ifdef __WXMSW__
    if (IsBOINCConfiguredAsDaemon()) {
        stop_daemon_via_daemonctrl();
        bClientQuit = true;
    } else
#endif
    {
        pDoc->GetConnectedComputerName(strConnectedCompter);
        if (!pDoc->IsComputerNameLocal(strConnectedCompter)) {
            RPC_CLIENT rpc;
            if (!rpc.init("localhost")) {
                pDoc->m_pNetworkConnection->GetLocalPassword(strPassword);
                rpc.authorize((const char*)strPassword.mb_str());
                if (IsBOINCCoreRunning()) {
                    rpc.quit();
                    for (iCount = 0; iCount <= 10; iCount++) {
                        if (!bClientQuit && !IsBOINCCoreRunning()) {
                            wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit Detected"));
                            bClientQuit = true;
                            break;
                        }
                        wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit NOT Detected, Sleeping..."));
                        ::wxSleep(1);
                    }
                } else {
                    bClientQuit = true;
                }
            }
            rpc.close();
        } else {
            if (IsBOINCCoreRunning()) {
                if (ShuttingDownManager) {
                    // Set event filtering to allow RPC completion 
                    // events but not events which start new RPCs
                    wxGetApp().SetEventFiltering(true);
                }
                quit_result = -1;
                request.clear();
                request.which_rpc = RPC_QUIT;
                request.rpcType = RPC_TYPE_ASYNC_NO_REFRESH;
                request.completionTime = &rpcCompletionTime;
                request.resultPtr = &quit_result;
                pDoc->RequestRPC(request);  // Issue an asynchronous Quit RPC

                // Client needs time to shut down project applications, so don't wait
                // for it to shut down; assume it will exit OK if Quit RPC succeeds.
                startTime = dtime();
                while ((dtime() - startTime) < 10.0) {  // Allow 10 seconds
                    boinc_sleep(0.25);          // Check 4 times per second
                    wxSafeYield(NULL, true);    // To allow handling RPC completion events
                    if (!bClientQuit && (rpcCompletionTime != zeroTime)) {
                        // If Quit RPC finished, check its returned value
                        if (quit_result) {
                            break;  // Quit RPC returned an error
                        }
                        wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit Detected"));
                        bClientQuit = true;
                        break;
                    }
                    wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit NOT Detected, Sleeping..."));
                }
            } else {
                bClientQuit = true;
            }
        }
    }

    if (!bClientQuit) {
        KillClient();
    }
    m_lBOINCCoreProcessId = 0;

    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function End"));
}
コード例 #8
0
ファイル: screensaver_x11.cpp プロジェクト: khandesh/boinc
/// Program entry point.
int main(int argc, char *argv[]) {
  unsigned long int window_id = 0;
  bool windowed = true;
  std::string boinc_wd = "/var/lib/boinc-client";

  // parse command line
  for(int c = 0; c < argc; c++) {
      std::string option = argv[c];
      if(option == "-window-id" && argv[c+1])
        sscanf(argv[++c], "%lx", &window_id);
      else if(option == "-root")
        windowed = false;
      else if (option == "-window")
        windowed = true;
      else if (option == "-boinc_dir")
        if(argv[++c])
          boinc_wd = argv[c];
    }

  // if no -window-id command line argument is given,
  // look for the XSCREENSAVER_WINDOW environment variable
  if(!window_id) {
      char *xssw = getenv("XSCREENSAVER_WINDOW");
      if(xssw && *xssw) {
          unsigned long int id = 0;
          char c;
          if (sscanf(xssw, "0x%lx %c", &id, &c) == 1 ||
              sscanf(xssw, "%lu %c", &id, &c) == 1)
            window_id = id;
      }
  }

  // connect to the X server using $DISPLAY
  int screen_num = 0;
  con = xcb_connect(NULL, &screen_num);

  if(!con) {
      std::cerr << "Cannot connect to your X server." << std::endl
                << "Please check if it's running and whether your DISPLAY "
                << "environment variable is set correctly." << std::endl;
      return 1;
   }

  // get default screen
  xcb_screen_t *screen;
  for(xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(con));
      it.rem; screen_num--, xcb_screen_next(&it))
    if(!screen_num) screen = it.data;

  // create screensaver window
  window = new scr_window(con, screen, window_id, windowed);
  window->set_text("screensaver loading");

  // start the X event loop
  pthread_t thread;
  if(pthread_create(&thread, NULL, event_loop, NULL)) {
      std::cerr << "Could not create a thread." << std::endl;
      exit(1);
  }

  // try to connect
  RPC_CLIENT *rpc = new RPC_CLIENT;
  if(rpc->init(NULL)) {
      window->set_text("boinc not running");
      pthread_join(thread, NULL);
      return 0;
  }

  // get results that support graphics
  RESULTS results;
  while(true) {
      int suspend_reason = 0;
      rpc->get_screensaver_tasks(suspend_reason, results);
      if(results.results.empty()) sleep(10);
      else break;
  }

  srandom(time(NULL));
  std::string graphics_cmd = "graphics_app";
  // the loop skips projects that do not yet
  // support the graphics_app soft link.
  while(graphics_cmd == "graphics_app") {
      // select a random result
      int n = random() % results.results.size();
      RESULT *result = results.results[n];
      
      // change to slot dir
      std::stringstream stream;
      stream << boinc_wd << "/slots/" << result->slot << "/";
      std::string slot_dir = stream.str();
      if(chdir(slot_dir.c_str())) {
          perror("chdir");
          exit(1);
      }

      // resolve graphics_app soft link
      boinc_resolve_filename_s(graphics_cmd.c_str(), graphics_cmd);
  }

  // fork and...
  pid_t pid = fork();
  if(pid == -1) {
      perror("fork");
      exit(1);
  }

  // ...spawn graphics app
  if(!pid) // child
    if(execl(graphics_cmd.c_str(), graphics_cmd.c_str(), NULL)) {
        perror("exec");
        exit(1);
    }

  // look for our graphics app
  // do this 10 times, every 1/2 seconds, then give up.
  //
  xcb_window_t client = 0;
  for(int n = 0; n < 10; n++) {
      // get list of x clients
      xcb_intern_atom_cookie_t cookie0=xcb_intern_atom(
            con, 0, strlen("_NET_CLIENT_LIST"), "_NET_CLIENT_LIST"
      );
      xcb_intern_atom_reply_t *reply0=xcb_intern_atom_reply(con, cookie0, NULL);

      xcb_get_property_cookie_t cookie =
        xcb_get_property(con, 0, screen->root, reply0->atom, XCB_ATOM_WINDOW, 0,
                         std::numeric_limits<uint32_t>::max());

      xcb_generic_error_t  *error;
      xcb_get_property_reply_t *reply =
        xcb_get_property_reply(con, cookie, &error);
      if(error) {
          std::cerr << "Could not get client list." << std::endl;
          exit(1);
      }

      xcb_window_t *clients =
        static_cast<xcb_window_t*>(xcb_get_property_value(reply));

      // check if one of them is our graphics app
      for(int c = 0; c < reply->length; c++) {
          xcb_get_property_reply_t *reply2;

          // check WM_COMMAND
          cookie = xcb_get_property(con, 0, clients[c], XCB_ATOM_WM_COMMAND, XCB_ATOM_STRING,
                                    0, std::numeric_limits<uint32_t>::max());
          reply2 = xcb_get_property_reply(con, cookie, &error);
          if(!error) {  // ignore errors 
              char *command = static_cast<char*>(xcb_get_property_value(reply2));
      
              if(command && graphics_cmd == command) {
                  client = clients[c];
                  break;
              }

              free(reply2);
          }

          // check WM_CLASS
          cookie = xcb_get_property(con, 0, clients[c], XCB_ATOM_WM_CLASS, XCB_ATOM_STRING,
                                    0, std::numeric_limits<uint32_t>::max());
          reply2 = xcb_get_property_reply(con, cookie, &error);
          if(!error) {  // ignore errors 
              char *clas = static_cast<char*>(xcb_get_property_value(reply2));

              size_t pos = graphics_cmd.find_last_of('/');
              std::string executable;
              if(pos == std::string::npos) executable = graphics_cmd;
              else executable = graphics_cmd.substr(pos + 1);

              if(clas && executable == clas) {
                  client = clients[c];
                  break;
                }
              
              free(reply2);
          }

          // More checks are possible, but a single method for all graphics
          // applications would be preferred, such as WM_CLASS = "BOINC".
      }

      free(reply);

      if(client) break;

      usleep(500000);
  }

  // if the client window was found, xembed it
  if(client)
    window->xembed(client);

  pthread_join(thread, NULL);

  delete window;
  xcb_disconnect(con);
  return 0;
}
コード例 #9
0
ファイル: ss_app.cpp プロジェクト: DanAurea/boinc
int main(int argc, char** argv) {
    int retval;
    bool test = false;

    for (int i=1; i<argc; i++) {
        if (!strcmp(argv[i], "--test")) {
            test = true;
        }
        if (!strcmp(argv[i], "--retry_connect")) {
            retry_connect = true;
        }
    }

    // Initialize the BOINC Diagnostics Framework
    int dwDiagnosticsFlags =
#ifdef _DEBUG
        BOINC_DIAG_HEAPCHECKENABLED |
        BOINC_DIAG_MEMORYLEAKCHECKENABLED |
#endif
        BOINC_DIAG_DUMPCALLSTACKENABLED | 
        BOINC_DIAG_PERUSERLOGFILES |
        BOINC_DIAG_REDIRECTSTDERR |
        BOINC_DIAG_REDIRECTSTDOUT |
        BOINC_DIAG_TRACETOSTDOUT;

    diagnostics_init(dwDiagnosticsFlags, "stdoutscrgfx", "stderrscrgfx");

#ifdef _WIN32
    WinsockInitialize();
#endif

    if (test) {
        retval = rpc.init(NULL);
        if (!retval) {
            retval = update_data();
        }
        exit(ERR_CONNECT);
    }
    
#ifdef __APPLE__
    long brandId = BOINC_BRAND_ID;
    // For GridRepublic or CharityEngine, the installer put a branding file in our data directory
    FILE *f = fopen("/Library/Application Support/BOINC Data/Branding", "r");
    if (f) {
        fscanf(f, "BrandId=%ld\n", &brandId);
        fclose(f);
        if (brandId == GRIDREPUBLIC_BRAND_ID) {
            brand_name = "GridRepublic";
            logo_file = "gridrepublic_ss_logo.jpg";
        } else if (brandId == CHARITYENGINE_BRAND_ID) {
            brand_name = "Charity Engine";
            logo_file = "CE_ss_logo.jpg";
        }
    }
#endif

    boinc_graphics_loop(argc, argv, "BOINC screensaver");

    boinc_finish_diag();

#ifdef _WIN32
    WinsockCleanup();
#endif

    return 0;
}
コード例 #10
0
ファイル: ss_app.cpp プロジェクト: DanAurea/boinc
void app_graphics_render(int xs, int ys, double t) {
    double alpha;
    static bool showing_project = false;
    static unsigned int project_index = 0, job_index=0;
    static float logo_pos[3] = {.2, .2, 0};
    int retval;

    if (!connected) {
        if (t > next_connect_time) {
            retval = rpc.init(NULL);
            if (!retval) {
                retval = update_data();
            }
            if (retval) {
                if (!retry_connect) {
                    exit(ERR_CONNECT);
                }
                next_connect_time = t + 10;
            } else {
                connected = true;
            }
        }
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // draw logo first - it's in background
    //
    mode_unshaded();
    mode_ortho();
    if (logo_fader.value(t, alpha)) {
        logo_pos[0] = drand()*.4;
        logo_pos[1] = drand()*.4;
    }
    draw_logo(logo_pos, (float)alpha);

    if (info_fader.value(t, alpha)) {
        retval = update_data();
        if (retval) {
            if (!retry_connect) {
                exit(ERR_CONNECT);
            }
            connected = false;
            next_connect_time = t + 10;
        } else {
            if (showing_project) {
                showing_project = false;
                project_index++;
            } else {
                int n = (int)cc_state.results.size();
                if (n) {
                    job_index += MAX_JOBS_DISPLAY;
                    job_index %= n;
                } else {
                    job_index = 0;
                }
                showing_project = true;
            }
        }
    }
    white[3] = alpha;
    if (connected) {
        if (cc_state.projects.size() == 0) {
            show_no_projects();
        } else if (showing_project) {
            if (project_index >= cc_state.projects.size()) {
                project_index = 0;
            }
            show_project(project_index, alpha);
        } else {
            show_jobs(job_index, alpha);
        }
    } else {
        show_disconnected();
    }
    ortho_done();
}
コード例 #11
0
ファイル: boinc_cmd.cpp プロジェクト: MestreLion/boinc-debian
int main(int argc, char** argv) {
    RPC_CLIENT rpc;
    int i, retval, port=0;
    MESSAGES messages;
    NOTICES notices;
    char passwd_buf[256], hostname_buf[256], *hostname=0;
    char* passwd = passwd_buf, *p;

#ifdef _WIN32
    chdir_to_data_dir();
#endif
    strcpy(passwd_buf, "");
    read_gui_rpc_password(passwd_buf);

#if defined(_WIN32) && defined(USE_WINSOCK)
    WSADATA wsdata;
    retval = WSAStartup( MAKEWORD( 1, 1 ), &wsdata);
    if (retval) {
        fprintf(stderr, "WinsockInitialize: %d\n", retval);
        exit(1);
    }
#endif
    if (argc < 2) usage();
    i = 1;
    if (!strcmp(argv[i], "--help")) usage();
    if (!strcmp(argv[i], "-h"))     usage();
    if (!strcmp(argv[i], "--version")) version();
    if (!strcmp(argv[i], "-V"))     version();

    if (!strcmp(argv[i], "--host")) {
        if (++i == argc) usage();
        strlcpy(hostname_buf, argv[i], sizeof(hostname_buf));
        hostname = hostname_buf;
        p = strchr(hostname, ':');
        if (p) {
            port = atoi(p+1);
            *p=0;
        }
        i++;
    }
    if ((i<argc)&& !strcmp(argv[i], "--passwd")) {
        if (++i == argc) usage();
        passwd = argv[i];
        i++;
    }

    // change the following to debug GUI RPC's asynchronous connection mechanism
    //
#if 1
    retval = rpc.init(hostname, port);
    if (retval) {
        fprintf(stderr, "can't connect to %s\n", hostname?hostname:"local host");
        exit(1);
    }
#else
    retval = rpc.init_asynch(hostname, 60., false);
    while (1) {
        retval = rpc.init_poll();
        if (!retval) break;
        if (retval == ERR_RETRY) {
            printf("sleeping\n");
            sleep(1);
            continue;
        }
        fprintf(stderr, "can't connect: %d\n", retval);
        exit(1);
    }
    printf("connected\n");
#endif

    if (strlen(passwd)) {
        retval = rpc.authorize(passwd);
        if (retval) {
            fprintf(stderr, "Authorization failure: %d\n", retval);
            exit(1);
        }
    }

    char* cmd = next_arg(argc, argv, i);
    if (!strcmp(cmd, "--get_state")) {
        CC_STATE state;
        retval = rpc.get_state(state);
        if (!retval) state.print();
    } else if (!strcmp(cmd, "--get_tasks")) {
        RESULTS results;
        retval = rpc.get_results(results);
        if (!retval) results.print();
    } else if (!strcmp(cmd, "--get_file_transfers")) {
        FILE_TRANSFERS ft;
        retval = rpc.get_file_transfers(ft);
        if (!retval) ft.print();
    } else if (!strcmp(cmd, "--get_daily_xfer_history")) {
        DAILY_XFER_HISTORY dxh;
        retval = rpc.get_daily_xfer_history(dxh);
        if (!retval) dxh.print();
    } else if (!strcmp(cmd, "--get_project_status")) {
        PROJECTS ps;
        retval = rpc.get_project_status(ps);
        if (!retval) ps.print();
    } else if (!strcmp(cmd, "--get_simple_gui_info")) {
        SIMPLE_GUI_INFO info;
        retval = rpc.get_simple_gui_info(info);
        if (!retval) info.print();
    } else if (!strcmp(cmd, "--get_disk_usage")) {
        DISK_USAGE du;
        retval = rpc.get_disk_usage(du);
        if (!retval) du.print();
    } else if (!strcmp(cmd, "--task")) {
        RESULT result;
        char* project_url = next_arg(argc, argv, i);
        strcpy(result.project_url, project_url);
        char* name = next_arg(argc, argv, i);
        strcpy(result.name, name);
        char* op = next_arg(argc, argv, i);
        if (!strcmp(op, "suspend")) {
            retval = rpc.result_op(result, "suspend");
        } else if (!strcmp(op, "resume")) {
            retval = rpc.result_op(result, "resume");
        } else if (!strcmp(op, "abort")) {
            retval = rpc.result_op(result, "abort");
        } else {
            fprintf(stderr, "Unknown op %s\n", op);
        }
    } else if (!strcmp(cmd, "--project")) {
        PROJECT project;
        strcpy(project.master_url, next_arg(argc, argv, i));
        canonicalize_master_url(project.master_url);
        char* op = next_arg(argc, argv, i);
        if (!strcmp(op, "reset")) {
            retval = rpc.project_op(project, "reset");
        } else if (!strcmp(op, "suspend")) {
            retval = rpc.project_op(project, "suspend");
        } else if (!strcmp(op, "resume")) {
            retval = rpc.project_op(project, "resume");
        } else if (!strcmp(op, "detach")) {
            retval = rpc.project_op(project, "detach");
        } else if (!strcmp(op, "update")) {
            retval = rpc.project_op(project, "update");
        } else if (!strcmp(op, "suspend")) {
            retval = rpc.project_op(project, "suspend");
        } else if (!strcmp(op, "resume")) {
            retval = rpc.project_op(project, "resume");
        } else if (!strcmp(op, "nomorework")) {
            retval = rpc.project_op(project, "nomorework");
        } else if (!strcmp(op, "allowmorework")) {
            retval = rpc.project_op(project, "allowmorework");
        } else if (!strcmp(op, "detach_when_done")) {
            retval = rpc.project_op(project, "detach_when_done");
        } else if (!strcmp(op, "dont_detach_when_done")) {
            retval = rpc.project_op(project, "dont_detach_when_done");
        } else {
            fprintf(stderr, "Unknown op %s\n", op);
        }
    } else if (!strcmp(cmd, "--project_attach")) {
        char url[256];
        strcpy(url, next_arg(argc, argv, i));
        canonicalize_master_url(url);
        char* auth = next_arg(argc, argv, i);
        retval = rpc.project_attach(url, auth, "");
    } else if (!strcmp(cmd, "--file_transfer")) {
        FILE_TRANSFER ft;

        ft.project_url = next_arg(argc, argv, i);
        ft.name = next_arg(argc, argv, i);
        char* op = next_arg(argc, argv, i);
        if (!strcmp(op, "retry")) {
            retval = rpc.file_transfer_op(ft, "retry");
        } else if (!strcmp(op, "abort")) {
            retval = rpc.file_transfer_op(ft, "abort");
        } else {
            fprintf(stderr, "Unknown op %s\n", op);
        }
    } else if (!strcmp(cmd, "--set_run_mode")) {
        char* op = next_arg(argc, argv, i);
        double duration;
        if (i >= argc || (argv[i][0] == '-')) {
            duration = 0;
        } else {
            duration = atof(next_arg(argc, argv, i));
        }
        if (!strcmp(op, "always")) {
            retval = rpc.set_run_mode(RUN_MODE_ALWAYS, duration);
        } else if (!strcmp(op, "auto")) {
            retval = rpc.set_run_mode(RUN_MODE_AUTO, duration);
        } else if (!strcmp(op, "never")) {
            retval = rpc.set_run_mode(RUN_MODE_NEVER, duration);
        } else {
            fprintf(stderr, "Unknown op %s\n", op);
        }
    } else if (!strcmp(cmd, "--set_gpu_mode")) {
        char* op = next_arg(argc, argv, i);
        double duration;
        if (i >= argc || (argv[i][0] == '-')) {
            duration = 0;
        } else {
            duration = atof(next_arg(argc, argv, i));
        }
        if (!strcmp(op, "always")) {
            retval = rpc.set_gpu_mode(RUN_MODE_ALWAYS, duration);
        } else if (!strcmp(op, "auto")) {
            retval = rpc.set_gpu_mode(RUN_MODE_AUTO, duration);
        } else if (!strcmp(op, "never")) {
            retval = rpc.set_gpu_mode(RUN_MODE_NEVER, duration);
        } else {
            fprintf(stderr, "Unknown op %s\n", op);
        }
    } else if (!strcmp(cmd, "--set_network_mode")) {
        char* op = next_arg(argc, argv, i);
        double duration;
        if (i >= argc || (argv[i][0] == '-')) {
            duration = 0;
        } else {
            duration = atof(next_arg(argc, argv, i));
        }
        if (!strcmp(op, "always")) {
            retval = rpc.set_network_mode(RUN_MODE_ALWAYS, duration);
        } else if (!strcmp(op, "auto")) {
            retval = rpc.set_network_mode(RUN_MODE_AUTO, duration);
        } else if (!strcmp(op, "never")) {
            retval = rpc.set_network_mode(RUN_MODE_NEVER, duration);
        } else {
            fprintf(stderr, "Unknown op %s\n", op);
        }
    } else if (!strcmp(cmd, "--get_proxy_settings")) {
        GR_PROXY_INFO pi;
        retval = rpc.get_proxy_settings(pi);
        if (!retval) pi.print();
    } else if (!strcmp(cmd, "--set_proxy_settings")) {
        GR_PROXY_INFO pi;
        pi.http_server_name = next_arg(argc, argv, i);
        pi.http_server_port = atoi(next_arg(argc, argv, i));
        pi.http_user_name = next_arg(argc, argv, i);
        pi.http_user_passwd = next_arg(argc, argv, i);
        pi.socks_server_name = next_arg(argc, argv, i);
        pi.socks_server_port = atoi(next_arg(argc, argv, i));
        pi.socks5_user_name = next_arg(argc, argv, i);
        pi.socks5_user_passwd = next_arg(argc, argv, i);
        pi.noproxy_hosts = next_arg(argc, argv, i);
        if (pi.http_server_name.size()) pi.use_http_proxy = true;
        if (pi.http_user_name.size()) pi.use_http_authentication = true;
        if (pi.socks_server_name.size()) pi.use_socks_proxy = true;
        retval = rpc.set_proxy_settings(pi);
    } else if (!strcmp(cmd, "--get_message_count")) {
        int seqno;
        retval = rpc.get_message_count(seqno);
        if (!retval) {
            printf("Greatest message sequence number: %d\n", seqno);
        }
    } else if (!strcmp(cmd, "--get_messages")) {
        int seqno;
        if (i == argc) {
            seqno = 0;
        } else {
            seqno = atoi(next_arg(argc, argv, i));
        }
        retval = rpc.get_messages(seqno, messages);
        if (!retval) {
            unsigned int j;
            for (j=0; j<messages.messages.size(); j++) {
                MESSAGE& md = *messages.messages[j];
                strip_whitespace(md.body);
                printf("%d: %s (%s) [%s] %s\n",
                    md.seqno,
                    time_to_string(md.timestamp),
                    prio_name(md.priority),
                    md.project.c_str(),
                    md.body.c_str()
                );
            }
        }
    } else if (!strcmp(cmd, "--get_notices")) {
        int seqno;
        if (i == argc) {
            seqno = 0;
        } else {
            seqno = atoi(next_arg(argc, argv, i));
        }
        retval = rpc.get_notices(seqno, notices);
        if (!retval) {
            unsigned int j;
            for (j=0; j<notices.notices.size(); j++) {
                NOTICE& n = *notices.notices[j];
                strip_whitespace(n.description);
                printf("%d: (%s) %s\n",
                    n.seqno,
                    time_to_string(n.create_time),
                    n.description.c_str()
                );
            }
        }
    } else if (!strcmp(cmd, "--get_host_info")) {
        HOST_INFO hi;
        retval = rpc.get_host_info(hi);
        if (!retval) hi.print();
    } else if (!strcmp(cmd, "--join_acct_mgr")) {
        char* am_url = next_arg(argc, argv, i);
        char* am_name = next_arg(argc, argv, i);
        char* am_passwd = next_arg(argc, argv, i);
        retval = rpc.acct_mgr_rpc(am_url, am_name, am_passwd);
        if (!retval) {
            while (1) {
                ACCT_MGR_RPC_REPLY amrr;
                retval = rpc.acct_mgr_rpc_poll(amrr);
                if (retval) {
                    printf("poll status: %s\n", boincerror(retval));
                } else {
                    if (amrr.error_num) {
                        printf("poll status: %s\n", boincerror(amrr.error_num));
                        if (amrr.error_num != ERR_IN_PROGRESS) break;
                        boinc_sleep(1);
                    } else {
                        int j, n = (int)amrr.messages.size();
                        if (n) {
                            printf("Messages from account manager:\n");
                            for (j=0; j<n; j++) {
                                printf("%s\n", amrr.messages[j].c_str());
                            }
                        }
                        break;
                    }
                }
            }
        }
    } else if (!strcmp(cmd, "--quit_acct_mgr")) {
        retval = rpc.acct_mgr_rpc("", "", "");
    } else if (!strcmp(cmd, "--run_benchmarks")) {
        retval = rpc.run_benchmarks();
    } else if (!strcmp(cmd, "--get_project_config")) {
        char* gpc_url = next_arg(argc, argv,i);
        retval = rpc.get_project_config(string(gpc_url));
        if (!retval) {
            while (1) {
                PROJECT_CONFIG pc;
                retval = rpc.get_project_config_poll(pc);
                if (retval) {
                    printf("poll status: %s\n", boincerror(retval));
                } else {
                    if (pc.error_num) {
                        printf("poll status: %s\n", boincerror(pc.error_num));
                        if (pc.error_num != ERR_IN_PROGRESS) break;
                        boinc_sleep(1);
                    } else {
                        pc.print();
                        break;
                    }
                }
            }
        }
    } else if (!strcmp(cmd, "--lookup_account")) {
        ACCOUNT_IN lai;
        lai.url = next_arg(argc, argv, i);
        lai.email_addr = next_arg(argc, argv, i);
        lai.passwd = next_arg(argc, argv, i);
        retval = rpc.lookup_account(lai);
        printf("status: %s\n", boincerror(retval));
        if (!retval) {
            ACCOUNT_OUT lao;
            while (1) {
                retval = rpc.lookup_account_poll(lao);
                if (retval) {
                    printf("poll status: %s\n", boincerror(retval));
                } else {
                    if (lao.error_num) {
                        printf("poll status: %s\n", boincerror(lao.error_num));
                        if (lao.error_num != ERR_IN_PROGRESS) break;
                        boinc_sleep(1);
                    } else {
                        lao.print();
                        break;
                    }
                }
            }
        }
    } else if (!strcmp(cmd, "--create_account")) {
        ACCOUNT_IN cai;
        cai.url = next_arg(argc, argv, i);
        cai.email_addr = next_arg(argc, argv, i);
        cai.passwd = next_arg(argc, argv, i);
        cai.user_name = next_arg(argc, argv, i);
        retval = rpc.create_account(cai);
        printf("status: %s\n", boincerror(retval));
        if (!retval) {
            ACCOUNT_OUT lao;
            while (1) {
                retval = rpc.create_account_poll(lao);
                if (retval) {
                    printf("poll status: %s\n", boincerror(retval));
                } else {
                    if (lao.error_num) {
                        printf("poll status: %s\n", boincerror(lao.error_num));
                        if (lao.error_num != ERR_IN_PROGRESS) break;
                        boinc_sleep(1);
                    } else {
                        lao.print();
                        break;
                    }
                }
            }
        }
    } else if (!strcmp(cmd, "--read_global_prefs_override")) {
        retval = rpc.read_global_prefs_override();
    } else if (!strcmp(cmd, "--read_cc_config")) {
        retval = rpc.read_cc_config();
        printf("retval %d\n", retval);
    } else if (!strcmp(cmd, "--network_available")) {
        retval = rpc.network_available();
    } else if (!strcmp(cmd, "--get_cc_status")) {
        CC_STATUS cs;
        retval = rpc.get_cc_status(cs);
        if (!retval) {
            retval = cs.network_status;
        }
        cs.print();
    } else if (!strcmp(cmd, "--quit")) {
        retval = rpc.quit();
    } else {
        usage();
    }
    if (retval < 0) {
        show_error(retval);
    }

#if defined(_WIN32) && defined(USE_WINSOCK)
    WSACleanup();
#endif
    exit(retval);
}
コード例 #12
0
ファイル: ss_app.cpp プロジェクト: UweBeckert/boinc
int main(int argc, char** argv) {
    int retval;
    bool test = false;

    for (int i=1; i<argc; i++) {
        if (!strcmp(argv[i], "--test")) {
            test = true;
        }
        if (!strcmp(argv[i], "--retry_connect")) {
            retry_connect = true;
        }
    }

    // Initialize the BOINC Diagnostics Framework
    int dwDiagnosticsFlags =
#ifdef _DEBUG
        BOINC_DIAG_HEAPCHECKENABLED |
        BOINC_DIAG_MEMORYLEAKCHECKENABLED |
#endif
        BOINC_DIAG_DUMPCALLSTACKENABLED | 
        BOINC_DIAG_PERUSERLOGFILES |
        BOINC_DIAG_REDIRECTSTDERR |
        BOINC_DIAG_REDIRECTSTDOUT |
        BOINC_DIAG_TRACETOSTDOUT;

    diagnostics_init(dwDiagnosticsFlags, "stdoutscrgfx", "stderrscrgfx");

#ifdef _WIN32
    WinsockInitialize();
#endif

    if (test) {
        retval = rpc.init(NULL);
        if (!retval) {
            retval = update_data();
        }
        exit(ERR_CONNECT);
    }
    
#ifdef __APPLE__
    long brandId = 0;
    // For branded installs, the installer put a branding file in our data directory
    FILE *f = fopen("/Library/Application Support/BOINC Data/Branding", "r");
    if (f) {
        fscanf(f, "BrandId=%ld\n", &brandId);
        fclose(f);
    }
    if ((brandId < 0) || (brandId > (NUMBRANDS-1))) {
        brandId = 0;
    }
    brand_name = brandName[brandId];
    logo_file = logoFile[brandId];
#endif

    boinc_graphics_loop(argc, argv, "BOINC screensaver");

    boinc_finish_diag();

#ifdef _WIN32
    WinsockCleanup();
#endif

    return 0;
}