[trunk] propagate the new OPJ_ symbol and type to openjpip
[openjpeg.git] / src / lib / openjpip / imgsock_manager.h
1 /*
2  * $Id$
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 #ifndef         IMGSOCK_MANAGER_H_
32 # define        IMGSOCK_MANAGER_H_
33
34 #include "byte_manager.h"
35 #include "sock_manager.h"
36 #include "opj_includes.h"
37
38 #define NUM_OF_MSGTYPES 9
39 typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, SIZREQ, JP2SAVE, QUIT, MSGERROR} msgtype_t;
40
41 /**
42  * indeitify client message type
43  *
44  * @param [in] connected_socket file descriptor of the connected socket
45  * @return                      message type
46  */
47 msgtype_t identify_clientmsg( SOCKET connected_socket);
48
49 /**
50  * receive a JPT- JPP- stream from client
51  *
52  * @param [in]  connected_socket file descriptor of the connected socket
53  * @param [out] target           address of received target file name string pointer ( malloced, if not received, NULL)
54  * @param [out] tid              address of received target identifier string pointer ( malloced, if not received, null string)
55  * @param [out] cid              address of received channel identifier string pointer ( malloced, if not received, null string)
56  * @param [out] streamlen        length of the received codestream
57  * @return                       JPT- JPP- codestream
58  */
59 Byte_t * receive_JPIPstream( SOCKET connected_socket, char **target, char **tid, char **cid, OPJ_SIZE_T *streamlen);
60
61 /**
62  * send PGM/PPM image stream to the client
63  *
64  * @param [in]  connected_socket file descriptor of the connected socket
65  * @param [in]  pnmstream        PGM/PPM image codestream
66  * @param [in]  width            width  of the PGM/PPM image (different from the original image)
67  * @param [in]  height           height of the PGM/PPM image
68  * @param [in]  numofcomp        number of components of the image
69  * @param [in]  maxval           maximum value of the image (only 255 supported)
70  */
71 void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int width, unsigned int height, unsigned int numofcomp, Byte_t maxval);
72
73 /**
74  * send XML data stream to the client
75  *
76  * @param [in]  connected_socket file descriptor of the connected socket
77  * @param [in]  xmlstream        xml data stream
78  * @param [in]  length           legnth of the xml data stream
79  */
80 void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, OPJ_SIZE_T length);
81
82 /**
83  * send TID data stream to the client
84  *
85  * @param [in]  connected_socket file descriptor of the connected socket
86  * @param [in]  tid              tid string
87  * @param [in]  tidlen           legnth of the tid string
88  */
89 void send_TIDstream( SOCKET connected_socket, const char *tid, OPJ_SIZE_T tidlen);
90
91 /**
92  * send CID data stream to the client
93  *
94  * @param [in]  connected_socket file descriptor of the connected socket
95  * @param [in]  cid              cid string
96  * @param [in]  cidlen           legnth of the cid string
97  */
98 void send_CIDstream( SOCKET connected_socket, const char *cid, OPJ_SIZE_T cidlen);
99
100 /**
101  * send SIZ data stream to the client
102  *
103  * @param [in]  connected_socket file descriptor of the connected socket
104  * @param [in]  width            original width  of the image
105  * @param [in]  height           original height of the image
106  */
107 void send_SIZstream( SOCKET connected_socket, unsigned int width, unsigned int height);
108
109 /**
110  * send response signal to the client
111  *
112  * @param [in]  connected_socket file descriptor of the connected socket
113  * @param [in]  succeed          whether if the requested process succeeded
114  */
115 void response_signal( SOCKET connected_socket, OPJ_BOOL succeed);
116
117 #endif /* !IMGSOCK_MANAGER_H_ */
118
119 /*! \file
120  * PROTOCOL specification to communicate with opj_dec_server
121  *
122  *\section sec1 JPIP-stream
123  * Cache JPT- JPP- stream in server
124  *
125  * client -> server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n  tidstring\\n  cidstring\\n) bytelengthvalue\\n data \n
126  * server -> client: 1 or 0 (of 1Byte response signal)
127  * 
128  *\section sec2 PNM request
129  * Get decoded PGM/PPM image
130  *
131  * client -> server: PNM request\\n [cid/tid]string\\n fw\\n fh\\n \n
132  * server -> client: P6 or P5 (2Byte) width (2Byte Big endian) height (2Byte Big endian) maxval (1Byte) data
133  *
134  *\section sec3 XML request
135  * Get XML data
136  *
137  * client -> server: XML request\\n \n
138  * server -> client: XML (3Byte) length (2Byte Big endian) data
139  *
140  *\section sec4 TID request
141  * Get target ID of target image
142  *
143  * client -> server: TID request\\n targetname\\n \n
144  * server -> client: TID (3Byte) length (1Byte) tiddata
145  *
146  *\section sec5 CID request
147  * Get Channel ID of identical target image
148  *
149  * client -> server: CID request\\n targetname\\n \n
150  * server -> client: CID (3Byte) length (1Byte) ciddata
151  *
152  *\section sec6 CID destroy
153  * Close Channel ID
154  *
155  * client -> server: CID destroy\\n ciddata \n
156  * server -> client: 1 or 0 (of 1Byte response signal)
157  *
158  *\section sec7 SIZ request
159  * Get original size of image
160  *
161  * client -> server: SIZ request\\n  tidstring\\n  cidstring\\n \n
162  * server -> client: SIZ (3Byte) width (3Byte Big endian) height (3Byte Big endian)
163  *
164  *\section sec8 JP2 save
165  * Save in JP2 file format
166  *
167  * client -> server: JP2 save\\n ciddata \n
168  * server -> client: 1 or 0 (of 1Byte response signal)
169  *
170  *\section sec9 QUIT
171  * Quit the opj_dec_server program
172  *
173  * client -> server: quit or QUIT
174  */