Statistics
| Branch: | Revision:

root / rgbdslam / external / siftgpu / src / ServerSiftGPU / server.cpp @ 9240aaa3

History | View | Annotate | Download (4.32 KB)

1
////////////////////////////////////////////////////////////////////////////
2
//        File:                server.cpp
3
//        Author:                Changchang Wu
4
//        Description :        driver of a SiftGPU Server.
5
//
6
//        Copyright (c) 2007 University of North Carolina at Chapel Hill
7
//        All Rights Reserved
8
//
9
//        Permission to use, copy, modify and distribute this software and its
10
//        documentation for educational, research and non-profit purposes, without
11
//        fee, and without a written agreement is hereby granted, provided that the
12
//        above copyright notice and the following paragraph appear in all copies.
13
//        
14
//        The University of North Carolina at Chapel Hill make no representations
15
//        about the suitability of this software for any purpose. It is provided
16
//        'as is' without express or implied warranty. 
17
//
18
//        Please send BUG REPORTS to ccwu@cs.unc.edu
19
//
20
////////////////////////////////////////////////////////////////////////////
21
#include <string.h>
22
#include <iostream>
23
#include <stdio.h>
24
using std::cout;
25

    
26
#include "../SiftGPU/SiftGPU.h"
27

    
28
//if you included ServerSiftGPU.h here. 
29
//CreateRemoteSiftGPU can be replaced by new ServerSiftGPU();
30

    
31
int main(int argc, char** argv)
32
{
33

    
34
        if(argc >= 2 && strcmp(argv[1], "-server") == 0)
35
        {        
36
                //run siftgpu server
37
                std::cout << "Starting server process...\n";
38
                int port = 7777;
39
                if(argc >= 3) sscanf(argv[2], "%d", &port);
40
                //////////////////////////////////////
41
                RunServerLoop(port, argc - 3, argv + 3);
42
        }else if(argc >=2 && strcmp(argv[1], "-test") == 0)
43
        {
44
                //start server on same computer and connect...
45
        //note we are using a SiftGPU pointer..
46
                SiftGPU* siftgpu = CreateRemoteSiftGPU();
47
                siftgpu->ParseParam(argc - 2, argv + 2);
48
        if(siftgpu->VerifyContextGL()) 
49
        {
50
                        //files on the matchines where the server runs
51
                    siftgpu->RunSIFT("../data/800-1.jpg");
52
                    siftgpu->RunSIFT("../data/800-2.jpg");
53
        }
54
        delete siftgpu; //this will terminate the server
55
        }else if(argc >=4 && strcmp(argv[1], "-test_remote") == 0)
56
        {
57
                ////test client that connects to remote server...
58
        char server_name[1024];  int port = 7777;        
59
        strcpy(server_name, argv[2]);
60
        sscanf(argv[3], "%d", &port);
61
                SiftGPU* siftgpu = CreateRemoteSiftGPU(port, server_name);//new ServerSiftGPU(port, server_name);
62
                siftgpu->ParseParam(argc - 4, argv + 4);
63
        if(siftgpu->VerifyContextGL()) 
64
        {
65
                        //files on the matchines where the server runs
66
                    siftgpu->RunSIFT("../data/800-1.jpg");
67
                    siftgpu->RunSIFT("../data/800-2.jpg");
68
        }
69
        delete siftgpu;
70
        }else if(argc >=2 && strcmp(argv[1], "-test2") == 0)
71
        {
72
                //test using two siftgpu servers...usage:
73
        //server_siftgpu -test2 [server1_params] [-server2 [server2_params]]
74

    
75
        ////////////////////////////////////////////
76
        //they need to use different ports.
77
        SiftGPU* siftgpu1 = CreateRemoteSiftGPU(7777);//new ServerSiftGPU(7777);
78
        SiftGPU* siftgpu2 = CreateRemoteSiftGPU(8888);//new ServerSiftGPU(8888);
79

    
80
        //split the parameters for the two servers
81
        int argc1 = 0, argc2 = 0;
82
        char** argv1 = argv + 2, **argv2 = 0;
83
        while(argc1 + 2 < argc && strcmp(argv[argc1 + 2], "-server2"))
84
        {
85
            argc1++;
86
        }
87
        if(argc1 + 3 < argc && strcmp(argv[argc1 + 2], "-server2") == 0)
88
        {
89
            argv2 = argv + argc1 + 3;
90
            argc2 = argc - argc1 - 3;
91
        }
92

    
93
        //initialize the two servers with their siftgpu parameters
94
        siftgpu1->ParseParam(argc1, argv1);
95
                siftgpu2->ParseParam(argc2, argv2);
96
        if(siftgpu1->VerifyContextGL() && siftgpu2->VerifyContextGL()) 
97
        {
98
                    siftgpu1->RunSIFT("../data/800-1.jpg");
99
            siftgpu2->RunSIFT("../data/800-1.jpg");
100
                    siftgpu1->RunSIFT("../data/800-2.jpg");
101
            siftgpu2->RunSIFT("../data/800-2.jpg");
102
        }
103
        delete siftgpu1;
104
        delete siftgpu2;
105
        }else
106
        {
107
        std::cout
108
        <<"try -test [siftgpu_param] to create a local server and a client\n"
109
        <<"try -test2 [siftgpu_param1] [-server2 [siftgpu_param2]]\n"
110
        <<"            to create two servers and two clients\n"
111
        <<"try -test_remote remote_sever_name remote_server_port\n"
112
        <<"            to create a client and connect to remote server\n"
113
        <<"use -server port [siftgpu_param] to start a server\n"
114
        <<"Note [siftgpu_param] allows you to select GPU from multi-GPUs\n"
115
        <<"\n";
116
        }
117
        return 1;
118
}
119