[trunk] Fix compilation:
[openjpeg.git] / src / bin / jpip / opj_dec_server.c
1 /*
2  * $Id: opj_dec_server.c 54 2011-05-10 13:22:47Z kaori $
3  *
4  * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5  * Copyright (c) 2002-2011, Professor Benoit Macq
6  * Copyright (c) 2010-2011, Kaori Hagihara
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 /*! \file
32  *  \brief opj_dec_server is a server to decode JPT-stream and communicate locally with JPIP client, which is coded in java.
33  *
34  *  \section impinst Implementing instructions
35  *  Launch opj_dec_server from a terminal in the same machine as JPIP client image viewers. \n
36  *   % ./opj_dec_server [portnumber]\n
37  *  ( portnumber=50000 by default)\n
38  *  Keep it alive as long as image viewers are open.\n
39  *
40  *  To quite the opj_dec_server, send a message "quit" through the telnet.\n
41  *   % telnet localhost 50000\n
42  *     quit\n
43  *  Be sure all image viewers are closed.\n
44  *  Cache file in JPT format is stored in the working directly before it quites.
45  *  
46  */
47
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include "opj_config.h"
51 #include "openjpip.h"
52
53 #ifdef _WIN32
54 WSADATA initialisation_win32;
55 #endif
56
57 int main(int argc, char *argv[]){
58   
59   dec_server_record_t *server_record;
60   client_t client;
61   int port = 50000;
62   int erreur;
63   (void)erreur;
64
65   if( argc > 1)
66     port = atoi( argv[1]);
67
68 #ifdef _WIN32
69   erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
70   if( erreur!=0)
71     fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
72   else
73     printf( "Initialisation Winsock\n");
74 #endif /*_WIN32*/
75   
76   server_record = init_dec_server( port);
77   
78   while(( client = accept_connection( server_record)) != -1 )
79     if(!handle_clientreq( client, server_record))
80       break;
81   
82   terminate_dec_server( &server_record);
83
84 #ifdef _WIN32
85   if( WSACleanup() != 0){
86     printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
87   }else{
88     printf("\nWSACleanup OK\n");
89   }
90 #endif
91
92   return 0;
93 }