Beispiel #1
0
/* Main function that also spawns the thread */
int main(int argc, char** argv) {
    srand(time(NULL));
    pthread_t readThread, writeThread;
    struct Parameters args;
    int connfd;
    long first_prime, sec_prime, e, c, d;

    if(argc < 3) {
        printf("Run client with 'client [host name] [port number]'\n");
        exit(0);
    }

    char host[20];
    strcpy(host, argv[1]);
    connfd = connectTo(host, atoi(argv[2]));

    printf("\nEnter two numbers (m n) to generate keys based on the mth and nth primes: ");
    scanf("%ld %ld", &first_prime, &sec_prime);
    printf("\nGenerating keys...\n");
    generatePrimeNumbers(&first_prime, &sec_prime);
    generateKeys(first_prime, sec_prime, &e, &d, &c);
    printf("Your public key (will be sent to server): %ld %ld\n", e, c);
    printf("Your private key (will not be sent): %ld %ld\n", d, c);

    args.connfd = connfd;
    args.clientE = e;
    args.clientN = c;
    args.clientD = d;
    receive_key(&args);
    send_key(&args);

    pthread_create(&writeThread, NULL, write_data, &args);
    pthread_create(&readThread, NULL, read_data, &args);

    pthread_join(writeThread, NULL);
    pthread_join(readThread, NULL);

    close(connfd);
    exit(0);
}
Beispiel #2
0
/**
 * The main render loop of the GUI
 */
void GUI::render() {

  if(m_sleeping) {
//     process_keys();
    return;
  }

  if(m_displaying_dialog) {
    if(m_dialog_buzz) buzzer_nonblocking_buzz(1);
    return;
  }

  if(m_displaying_dialog_complete) {
    m_displaying_dialog_complete=false;
    m_pause_display_updates = false;
    display_clear(0);
    clear_pending_keys();
    redraw();
  }

  if(m_repeating) {
    // This would be better incremented in a timer, but I don't want to use another timer.
    if(m_repeat_time == m_repeat_delay) {
      // verify button still pressed
      if(cap_ispressed(m_repeat_key) == false) {
        m_repeating=false;
        m_repeat_time=0;
      } else {
        if(m_repeat_key == KEY_DOWN) { receive_key(KEY_DOWN,KEY_PRESSED); }
        if(m_repeat_key == KEY_UP  ) { receive_key(KEY_UP  ,KEY_PRESSED); }
        m_repeat_time = 0;
        m_repeated = true;
      }
    }
    m_repeat_time++;
  }


  // following two items really need to be atomic...
  int32_t cscreen = current_screen;

  if(clear_next_render) {
    clear_next_render=false;
    clear_screen(clear_screen_screen,clear_screen_selected);
    first_render=true;
  }

  bool do_redraw = false;
  if(m_redraw) do_redraw = true;
  m_redraw = false;

  render_lock(m_screen_lock);
  for(int32_t n=0;n<screens_layout[cscreen].item_count;n++) {

    if(first_render) {
      if(screens_layout[current_screen].items[n].type == ITEM_TYPE_ACTION) {
        receive_gui_events.receive_gui_event(screens_layout[cscreen].items[n].text,
                                             screens_layout[cscreen].items[n].text);
      }
    }

    //bool selected = false;
    bool select_render = false;
    if(n == selected_item     ) select_render = true;
    if(n == last_selected_item) select_render = true;

    if(first_render || select_render || do_redraw) {
      //bool do_render = true;

      // don't render labels, just because they are near other things...
      //if(!first_render && select_render && (screens_layout[cscreen].items[n].type == ITEM_TYPE_LABEL)) {
      //  do_render = false;
      //}

      //if(do_render)
      bool selected = false;
      if(selected_item == n) selected=true;
      render_item(screens_layout[cscreen].items[n],selected);
    }
  }
  //last_selected_item = selected_item;

  first_render=false;
  process_keys();
}