Esempio n. 1
0
int main(int argc, char** argv) {


    extern dexpd_config conf0;
    int socknum = 0;
    int sock_id = 0;

    int wd = 0;
    int notify_fd = 0;
    int option_index = 0;

    char *peer_str;
    char c;
    int peer_num;

    pthread_t notify_th;
    pthread_t reconnect_th;
    pthread_t listenv6;

    struct sockaddr_in peer_addr;

    static struct option long_options[] = {
        {"dennis",no_argument,0, 'T'},
        {0, 0, 0, 0}
    };

    c = getopt_long (argc, argv, "T",long_options, &option_index);

    switch(c) {

    case 'T':

        dennis_tribute();
        break;

    default:

        break;

    }



    socklen_t addr_len = sizeof(peer_addr);

    printf ("\n");

    printf ("        /\\\n");
    printf ("       /01\\\n");
    printf ("      /0011\\\n");
    printf ("     /000111\\     [[ Obsidian 0.1 == Clement Game 2011 ]]\n");
    printf ("    /00001111\\\n");
    printf ("   /0000011000\\\n");
    printf ("   \\0000000000/\n\n");


    init_config();


    if (conf0.use_tls) {
        printf("initializing TLS config...\n");
        conf0.ctx=(SSL_CTX*)initialize_ctx(conf0.tls_server_cert,"password");
        load_dh_params(conf0.ctx,conf0.tls_server_dh);
    }

    printf("Loading catalog from %s...\n",conf0.data_dir);

    load_catalog(conf0.data_dir);
    printf("starting inotify events listener...\n");

    //inotify init functions on datadir;
    notify_fd = inotify_init();
    wd = inotify_add_watch(notify_fd, conf0.data_dir, IN_CLOSE_WRITE|IN_MOVED_TO);

    //starting a new thread for inotify events read
    pthread_create(&notify_th,NULL,notify_thread,&notify_fd);


    printf("initating connections with peers...\n");
    connectAll();
    pthread_create(&reconnect_th,NULL,reconnect_loop,NULL);

    printf("listening on %s:%d...\n",conf0.listening_addr,conf0.listening_port);

    socknum  = create_socket(conf0.listening_addr,conf0.listening_port);

    if (conf0.use_ipv6) {

        printf("listening on %s:%d...\n",conf0.ipv6_listening_addr,conf0.listening_port);
        pthread_create(&listenv6,NULL,listen_v6,NULL);

    }



    while(1) {

        if((sock_id = accept(socknum,(struct sockaddr*)&peer_addr,&addr_len))<0) {

            fprintf(stderr,"ERROR: CANNOT ACCEPT NEW CONNECTION ON %s:%d",conf0.listening_addr,conf0.listening_port);

        }

        else {

            peer_str = inet_ntoa(peer_addr.sin_addr);
            printf("New Connection From %s\n",peer_str);

            //gerer la notion de public ici
            if ( (peer_num = isPeer(peer_str,sock_id)) < 0 && conf0.pub == 0) {

                fprintf(stderr,"ERROR: REMOTE HOST NOT In PEERS LIST\n");
                close(sock_id);

            }

            else if (conf0.pub == 1) {

                printf("Notice: Accepting public connection for host %s\n",peer_str);
                createPeer(peer_str,sock_id,1);

            }

            else {

                conf0.peers[peer_num].ssl = NULL;
                pthread_create(&conf0.peers[peer_num].ioth,NULL,dexp_serv_ioth,(void*)&conf0.peers[peer_num]);


            }



        }



    }


}
int main() {
    cv::namedWindow("Planetarium", cv::WINDOW_NORMAL);

    planetarium wall;

    wall.psf_spread_size = 8;

    wall.screen_distance = 5.954;
    wall.screen_width = 1920;
    wall.screen_height = 1080;
    wall.screen_horizontal_pixel_size = 2.364 / wall.screen_width;
    wall.screen_vertical_pixel_size = 1.335 / wall.screen_height;

    // Orion
    wall.attitude_ra = 84*M_PI/180;
    wall.attitude_de = 2*M_PI/180;

    // Juno
    // wall.attitude_ra = -2.885402;
    // wall.attitude_de = 0.133802;
    // Twist: 0.054906

    wall.I_ref = 1.0;
    wall.m_ref = 6.0;
    wall.sigma_0 = 1.0;

    wall.camera_x_offset = 0.0;
    wall.camera_y_offset = 0.0;

    // Load star catalog
    cv::Mat catalog = load_catalog("../hip6.tsv");

    cv::Mat image = wall.render(catalog);

    int k;
    while((k = cvWaitKey(30)) != 27) {
        if (k >= 65361 and k <= 65364) {
            // Left
            if (k == 65361) {
                wall.attitude_ra += 1*M_PI/180;
            }
            // Right
            else if (k == 65363) {
                wall.attitude_ra -= 1*M_PI/180;
            }
            // Up
            else if (k == 65362) {
                wall.attitude_de += 1*M_PI/180;
            }
            // Down
            else if (k == 65364) {
                wall.attitude_de -= 1*M_PI/180;
            }
            std::cout << "Attitude: Right Ascension: " << 180/M_PI * wall.attitude_ra << std::endl;
            std::cout << "          Declination    : " << 180/M_PI * wall.attitude_de << std::endl;
            image = wall.render(catalog);
        } else if (k == 102) {
            cvSetWindowProperty("Planetarium", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN );
        }

        cv::imshow("Planetarium", image);
    }

    return 0;
}