added tid request support to JPIP client and JPIP server quit request

This commit is contained in:
Kaori Hagihara 2011-08-25 17:13:04 +00:00
parent 4da816e459
commit 40fe9e6d67
18 changed files with 243 additions and 93 deletions

View File

@ -5,9 +5,13 @@ What's New for OpenJPIP
! : changed ! : changed
+ : added + : added
August 25, 2011
+ [kaori] added tid request support to JPIP client
+ [kaori] added quit JPIP server request
August 24, 2011 August 24, 2011
+ [kaori] added cachemodel_manager, which had been managed in target_manager previously + [kaori] added cachemodel_manager, which had been managed in target_manager previously
+ [kaori] added tid request support + [kaori] added tid request support to JPIP server
August 16, 2011 August 16, 2011
* [antonin] fixed cmake support for openjpip * [antonin] fixed cmake support for openjpip

View File

@ -91,6 +91,11 @@ Server:
2. Launch opj_server from the server terminal: 2. Launch opj_server from the server terminal:
% spawn-fcgi -f ./opj_server -p 3000 -n % spawn-fcgi -f ./opj_server -p 3000 -n
For shutting down JPIP server:
%GET http://hostname/myFCGI?quitJPIP
Notice, http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
Requst message "quitJPIP" can be changed in Makfile, modify -DQUIT_SIGNAL=\"quitJPIP\"
Client: Client:
1. Launch image decoding server, and keep it alive as long as image viewers are open 1. Launch image decoding server, and keep it alive as long as image viewers are open
% ./opj_dec_server % ./opj_dec_server

View File

@ -101,8 +101,6 @@ target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname)
target->next=NULL; target->next=NULL;
fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", target->tid);
if( targetlist->first) // there are one or more entries if( targetlist->first) // there are one or more entries
targetlist->last->next = target; targetlist->last->next = target;
else // first entry else // first entry
@ -220,9 +218,6 @@ target_param_t * search_targetBytid( char tid[], targetlist_param_t *targetlist)
foundtarget = foundtarget->next; foundtarget = foundtarget->next;
} }
fprintf( FCGI_stdout, "Status: 404\r\n");
fprintf( FCGI_stdout, "Reason: tid %s not found\r\n", tid);
return NULL; return NULL;
} }

View File

@ -61,12 +61,13 @@ void delete_cachelist(cachelist_param_t **cachelist)
free( *cachelist); free( *cachelist);
} }
cache_param_t * gene_cache( char *targetname, int csn, char *cid) cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid)
{ {
cache_param_t *cache; cache_param_t *cache;
cache = (cache_param_t *)malloc( sizeof(cache_param_t)); cache = (cache_param_t *)malloc( sizeof(cache_param_t));
strcpy( cache->filename, targetname); strcpy( cache->filename, targetname);
strcpy( cache->tid, tid);
cache->csn = csn; cache->csn = csn;
cache->cid = (char **)malloc( sizeof(char *)); cache->cid = (char **)malloc( sizeof(char *));
*cache->cid = (char *)malloc( MAX_LENOFCID); *cache->cid = (char *)malloc( MAX_LENOFCID);
@ -175,6 +176,14 @@ void add_cachecid( char *cid, cache_param_t *cache)
cache->numOfcid ++; cache->numOfcid ++;
} }
void update_cachetid( char *tid, cache_param_t *cache)
{
if( tid[0] != '0' && strcmp( tid, cache->tid) !=0){
fprintf( stderr, "tid is updated to %s for %s\n", tid, cache->filename);
strcpy( cache->tid, tid);
}
}
void remove_cidInCache( char *cid, cache_param_t *cache); void remove_cidInCache( char *cid, cache_param_t *cache);
void remove_cachecid( char *cid, cachelist_param_t *cachelist) void remove_cachecid( char *cid, cachelist_param_t *cachelist)
@ -225,6 +234,7 @@ void print_cache( cache_param_t *cache)
fprintf( stdout,"cache\n"); fprintf( stdout,"cache\n");
fprintf( stdout,"\t filename: %s\n", cache->filename); fprintf( stdout,"\t filename: %s\n", cache->filename);
fprintf( stdout,"\t tid: %s\n", cache->tid);
fprintf( stdout,"\t csn: %d\n", cache->csn); fprintf( stdout,"\t csn: %d\n", cache->csn);
fprintf( stdout,"\t cid:"); fprintf( stdout,"\t cid:");

View File

@ -37,9 +37,13 @@
//! maximum length of target name //! maximum length of target name
#define MAX_LENOFTARGET 128 #define MAX_LENOFTARGET 128
//! maximum length of target identifier
#define MAX_LENOFTID 30
//! cache parameters //! cache parameters
typedef struct cache_param{ typedef struct cache_param{
char filename[MAX_LENOFTARGET]; //!< file name char filename[MAX_LENOFTARGET]; //!< file name
char tid[MAX_LENOFTID]; //!< taregt identifier
int csn; //!< codestream number int csn; //!< codestream number
char **cid; //!< dynamic array of channel identifiers char **cid; //!< dynamic array of channel identifiers
int numOfcid; //!< number of cids int numOfcid; //!< number of cids
@ -74,10 +78,11 @@ void delete_cachelist(cachelist_param_t **cachelist);
* *
* @param[in] targetname target file name * @param[in] targetname target file name
* @param[in] csn codestream number * @param[in] csn codestream number
* @param[in] tid target identifier
* @param[in] cid channel identifier * @param[in] cid channel identifier
* @return pointer to the generated cache * @return pointer to the generated cache
*/ */
cache_param_t * gene_cache( char *targetname, int csn, char *cid); cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid);
/** /**
* delete a cache * delete a cache
@ -132,6 +137,16 @@ cache_param_t * search_cacheBycid( char cid[], cachelist_param_t *cachelist);
*/ */
void add_cachecid( char *cid, cache_param_t *cache); void add_cachecid( char *cid, cache_param_t *cache);
/**
* update tid of a cache
*
* @param[in] tid target identifier
* @param[in] cache cache pointer
*/
void update_cachetid( char *tid, cache_param_t *cache);
/** /**
* remove cid in cache * remove cid in cache
* *

View File

@ -94,7 +94,7 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
{ {
int receive_size; int receive_size;
char buf[BUF_LEN]; char buf[BUF_LEN];
char *magicid[] = { "JPIP-stream", "PNM request", "XML request", "CID request", "CID destroy", "JP2 save", "QUIT"}; char *magicid[] = { "JPIP-stream", "PNM request", "XML request", "TID request", "CID request", "CID destroy", "JP2 save", "QUIT"};
int i; int i;
receive_size = receive_line( connected_socket, buf); receive_size = receive_line( connected_socket, buf);
@ -106,7 +106,7 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
for( i=0; i<NUM_OF_MSGTYPES; i++){ for( i=0; i<NUM_OF_MSGTYPES; i++){
if( strncasecmp( magicid[i], buf, strlen(magicid[i])) == 0){ if( strncasecmp( magicid[i], buf, strlen(magicid[i])) == 0){
printf("Client message: %s\n", magicid[i]); printf("%s\n", magicid[i]);
return i; return i;
} }
} }
@ -115,10 +115,10 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
return MSGERROR; return MSGERROR;
} }
Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, int *streamlen) Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen)
{ {
Byte_t *jpipstream=NULL, *ptr; Byte_t *jpipstream=NULL, *ptr;
char buf[BUF_LEN], versionstring[] = "version 1.1"; char buf[BUF_LEN], versionstring[] = "version 1.2";
int linelen, redlen, remlen; int linelen, redlen, remlen;
target[0] = 0; target[0] = 0;
@ -138,6 +138,10 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, i
// register cid option // register cid option
strcpy( target, buf); strcpy( target, buf);
if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL;
strcpy( tid, buf);
if((linelen = receive_line( connected_socket, buf)) == 0) if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL; return NULL;
strcpy( cid, buf); strcpy( cid, buf);
@ -147,8 +151,7 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, i
} }
*streamlen = atoi( buf); *streamlen = atoi( buf);
fprintf( stderr, "Receiveing Data length: %d\n", *streamlen); fprintf( stderr, "Receive Data: %d Bytes\n", *streamlen);
jpipstream = (unsigned char *)malloc( (*streamlen)); jpipstream = (unsigned char *)malloc( (*streamlen));
ptr = jpipstream; ptr = jpipstream;
@ -162,7 +165,6 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, i
remlen -= redlen; remlen -= redlen;
ptr = ptr + redlen; ptr = ptr + redlen;
} }
fprintf( stderr, " done\n");
return jpipstream; return jpipstream;
} }
@ -183,17 +185,29 @@ void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length)
send_stream( connected_socket, xmlstream, length); send_stream( connected_socket, xmlstream, length);
} }
void send_IDstream( SOCKET connected_socket, char *id, int idlen, char *label);
void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen) void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen)
{
send_IDstream( connected_socket, cid, cidlen, "CID");
}
void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen)
{
send_IDstream( connected_socket, tid, tidlen, "TID");
}
void send_IDstream( SOCKET connected_socket, char *id, int idlen, char *label)
{ {
Byte_t header[4]; Byte_t header[4];
header[0] = 'C'; header[0] = label[0];
header[1] = 'I'; header[1] = label[1];
header[2] = 'D'; header[2] = label[2];
header[3] = cidlen & 0xff; header[3] = idlen & 0xff;
send_stream( connected_socket, header, 4); send_stream( connected_socket, header, 4);
send_stream( connected_socket, cid, cidlen); send_stream( connected_socket, id, idlen);
} }
void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int width, unsigned int height, unsigned int numofcomp, Byte_t maxval) void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int width, unsigned int height, unsigned int numofcomp, Byte_t maxval)

View File

@ -48,8 +48,8 @@ typedef int SOCKET;
*/ */
SOCKET open_listeningsocket(); SOCKET open_listeningsocket();
#define NUM_OF_MSGTYPES 7 #define NUM_OF_MSGTYPES 8
typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, CIDREQ, CIDDST, JP2SAVE, QUIT, MSGERROR} msgtype_t; typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, JP2SAVE, QUIT, MSGERROR} msgtype_t;
/** /**
* indeitify client message type * indeitify client message type
@ -64,11 +64,12 @@ msgtype_t identify_clientmsg( SOCKET connected_socket);
* *
* @param [in] connected_socket file descriptor of the connected socket * @param [in] connected_socket file descriptor of the connected socket
* @param [out] target received target file name (if not received, null string) * @param [out] target received target file name (if not received, null string)
* @param [out] tid received target identifier (if not received, null string)
* @param [out] cid received channel identifier (if not received, null string) * @param [out] cid received channel identifier (if not received, null string)
* @param [out] streamlen length of the received codestream * @param [out] streamlen length of the received codestream
* @return JPT- JPP- codestream * @return JPT- JPP- codestream
*/ */
Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, int *streamlen); Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen);
/** /**
* send PGM/PPM image stream to the client * send PGM/PPM image stream to the client
@ -91,6 +92,15 @@ void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int wi
*/ */
void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length); void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length);
/**
* send TID data stream to the client
*
* @param [in] connected_socket file descriptor of the connected socket
* @param [in] tid tid string
* @param [in] tidlen legnth of the tid string
*/
void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen);
/** /**
* send CID data stream to the client * send CID data stream to the client
* *
@ -125,7 +135,7 @@ int receive_line(SOCKET connected_socket, char *buf);
*\section sec1 JPIP-stream *\section sec1 JPIP-stream
* Cache JPT- JPP- stream in server * Cache JPT- JPP- stream in server
* *
* client -> server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n cidstring\\n) bytelengthvalue\\n data \n * client -> server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n tidstring\\n cidstring\\n) bytelengthvalue\\n data \n
* server -> client: 1 or 0 (of 1Byte response signal) * server -> client: 1 or 0 (of 1Byte response signal)
* *
*\section sec2 PNM request *\section sec2 PNM request
@ -140,25 +150,31 @@ int receive_line(SOCKET connected_socket, char *buf);
* client -> server: XML request\\n \n * client -> server: XML request\\n \n
* server -> client: XML (3Byte) length (2Byte Big endian) data * server -> client: XML (3Byte) length (2Byte Big endian) data
* *
*\section sec4 CID request *\section sec4 TID request
* Get target ID of target image
*
* client -> server: TID request\\n targetname\\n \n
* server -> client: TID (3Byte) length (1Byte) tiddata
*
*\section sec5 CID request
* Get Channel ID of identical target image * Get Channel ID of identical target image
* *
* client -> server: CID request\\n targetname\\n \n * client -> server: CID request\\n targetname\\n \n
* server -> client: CID (3Byte) length (1Byte) ciddata * server -> client: CID (3Byte) length (1Byte) ciddata
* *
*\section sec5 CID destroy *\section sec6 CID destroy
* Close Channel ID * Close Channel ID
* *
* client -> server: CID destroy\\n ciddata \n * client -> server: CID destroy\\n ciddata \n
* server -> client: 1 or 0 (of 1Byte response signal) * server -> client: 1 or 0 (of 1Byte response signal)
* *
*\section sec6 JP2 save *\section sec7 JP2 save
* Save in JP2 file format * Save in JP2 file format
* *
* client -> server: JP2 save\\n ciddata \n * client -> server: JP2 save\\n ciddata \n
* server -> client: 1 or 0 (of 1Byte response signal) * server -> client: 1 or 0 (of 1Byte response signal)
* *
*\section sec7 QUIT *\section sec8 QUIT
* Quit the opj_dec_server program * Quit the opj_dec_server program
* *
* client -> server: quit or QUIT * client -> server: quit or QUIT

View File

@ -99,6 +99,14 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
*/ */
void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist); void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist);
/**
* handle TargetID request message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
*/
void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
/** /**
* handle ChannelID request message * handle ChannelID request message
* *
@ -164,6 +172,10 @@ int main(int argc, char *argv[]){
handle_XMLreqMSG( connected_socket, jpipstream, cachelist); handle_XMLreqMSG( connected_socket, jpipstream, cachelist);
break; break;
case TIDREQ:
handle_TIDreqMSG( connected_socket, cachelist);
break;
case CIDREQ: case CIDREQ:
handle_CIDreqMSG( connected_socket, cachelist); handle_CIDreqMSG( connected_socket, cachelist);
break; break;
@ -183,7 +195,7 @@ int main(int argc, char *argv[]){
break; break;
} }
printf("cut the connection. listening to port\n"); printf("\t end of the connection\n\n");
if( closesocket(connected_socket) != 0){ if( closesocket(connected_socket) != 0){
perror("close"); perror("close");
return -1; return -1;
@ -221,10 +233,10 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
Byte_t *newjpipstream; Byte_t *newjpipstream;
int newstreamlen = 0; int newstreamlen = 0;
cache_param_t *cache; cache_param_t *cache;
char target[MAX_LENOFTARGET], cid[MAX_LENOFCID]; char target[MAX_LENOFTARGET], tid[MAX_LENOFTID], cid[MAX_LENOFCID];
metadatalist_param_t *metadatalist; metadatalist_param_t *metadatalist;
newjpipstream = receive_JPIPstream( connected_socket, target, cid, &newstreamlen); newjpipstream = receive_JPIPstream( connected_socket, target, tid, cid, &newstreamlen);
parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue); parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue);
@ -235,11 +247,13 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist); parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
// cid registration // cid registration
if( target[0] != 0 && cid[0] != 0){ if( target[0] != 0 && tid[0] != 0 && cid[0] != 0){
if((cache = search_cache( target, cachelist))) if((cache = search_cache( target, cachelist))){
add_cachecid( cid, cache); add_cachecid( cid, cache);
update_cachetid( tid, cache);
}
else{ else{
cache = gene_cache( target, msgqueue->last->csn, cid); cache = gene_cache( target, msgqueue->last->csn, tid, cid);
insert_cache_into_list( cache, cachelist); insert_cache_into_list( cache, cachelist);
} }
} }
@ -294,6 +308,22 @@ void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_pa
free( xmlstream); free( xmlstream);
} }
void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
{
char target[MAX_LENOFTARGET], *tid = NULL;
cache_param_t *cache;
int tidlen = 0;
receive_line( connected_socket, target);
cache = search_cache( target, cachelist);
if( cache){
tid = cache->tid;
tidlen = strlen(tid);
}
send_TIDstream( connected_socket, tid, tidlen);
}
void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist) void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
{ {
char target[MAX_LENOFTARGET], *cid = NULL; char target[MAX_LENOFTARGET], *cid = NULL;

View File

@ -1 +1 @@
opj_viewer-20110824.jar opj_viewer-20110825.jar

View File

@ -50,17 +50,20 @@ public class ImageManager extends JPIPHttpClient
String refcid = ImgdecClient.query_cid( j2kfilename); String refcid = ImgdecClient.query_cid( j2kfilename);
byte[] jpipstream; byte[] jpipstream;
if( refcid == null) if( refcid == null){
String reftid = ImgdecClient.query_tid( j2kfilename);
if( reftid == null)
jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, true); jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, true);
else
jpipstream = super.requestViewWindow( j2kfilename, reftid, reqfw, reqfh, true);
}
else else
jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, true); jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, true);
System.err.println( "decoding to PNM image"); System.err.println( "decoding to PNM image");
pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, cid, fw, fh); pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh);
System.err.println( " done"); System.err.println( " done");
// System.out.println( "fw: " + fw + " fh: " + fh + "pnm w: ");
return pnmimage.createROIImage( rx, ry, rw, rh); return pnmimage.createROIImage( rx, ry, rw, rh);
} }

View File

@ -40,9 +40,9 @@ public class ImgdecClient{
return get_PNMstream( cid, fw, fh); return get_PNMstream( cid, fw, fh);
} }
public static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String cid, int fw, int fh) public static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String tid, String cid, int fw, int fh)
{ {
send_JPIPstream( jpipstream, j2kfilename, cid); send_JPIPstream( jpipstream, j2kfilename, tid, cid);
return get_PNMstream( cid, fw, fh); return get_PNMstream( cid, fw, fh);
} }
@ -56,7 +56,7 @@ public class ImgdecClient{
System.err.println("Sending " + jpipstream.length + "Data Bytes to decodingServer"); System.err.println("Sending " + jpipstream.length + "Data Bytes to decodingServer");
os.writeBytes("JPIP-stream\n"); os.writeBytes("JPIP-stream\n");
os.writeBytes("version 1.1\n"); os.writeBytes("version 1.2\n");
os.writeBytes( jpipstream.length + "\n"); os.writeBytes( jpipstream.length + "\n");
os.write( jpipstream, 0, jpipstream.length); os.write( jpipstream, 0, jpipstream.length);
@ -71,7 +71,7 @@ public class ImgdecClient{
} }
} }
public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String cid) public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
{ {
try{ try{
Socket imgdecSocket = new Socket( "localhost", 5000); Socket imgdecSocket = new Socket( "localhost", 5000);
@ -85,8 +85,12 @@ public class ImgdecClient{
System.err.println("Sending " + length + "Data Bytes to decodingServer"); System.err.println("Sending " + length + "Data Bytes to decodingServer");
os.writeBytes("JPIP-stream\n"); os.writeBytes("JPIP-stream\n");
os.writeBytes("version 1.1\n"); os.writeBytes("version 1.2\n");
os.writeBytes( j2kfilename + "\n"); os.writeBytes( j2kfilename + "\n");
if( tid == null)
os.writeBytes( "0\n");
else
os.writeBytes( tid + "\n");
os.writeBytes( cid + "\n"); os.writeBytes( cid + "\n");
os.writeBytes( length + "\n"); os.writeBytes( length + "\n");
os.write( jpipstream, 0, length); os.write( jpipstream, 0, length);
@ -189,7 +193,27 @@ public class ImgdecClient{
public static String query_cid( String j2kfilename) public static String query_cid( String j2kfilename)
{ {
String cid = null; int []retmsglabel = new int[3];
retmsglabel[0] = 67;
retmsglabel[1] = 73;
retmsglabel[2] = 68;
return query_id( "CID request", j2kfilename, retmsglabel);
}
public static String query_tid( String j2kfilename)
{
int []retmsglabel = new int[3];
retmsglabel[0] = 84;
retmsglabel[1] = 73;
retmsglabel[2] = 68;
return query_id( "TID request", j2kfilename, retmsglabel);
}
public static String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel)
{
String id = null;
try{ try{
Socket imgdecSocket = new Socket( "localhost", 5000); Socket imgdecSocket = new Socket( "localhost", 5000);
@ -197,23 +221,23 @@ public class ImgdecClient{
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[4]; byte []header = new byte[4];
os.writeBytes("CID request\n"); os.writeBytes( reqmsghead + "\n");
os.writeBytes( j2kfilename + "\n"); os.writeBytes( j2kfilename + "\n");
read_stream( is, header, 4); read_stream( is, header, 4);
if( header[0] == 67 && header[1] == 73 && header[2] == 68){ if( header[0] == retmsglabel[0] && header[1] == retmsglabel[1] && header[2] == retmsglabel[2]){
int length = header[3]&0xff; int length = header[3]&0xff;
if( length > 0){ if( length > 0){
byte []ciddata = new byte[ length]; byte []iddata = new byte[ length];
read_stream( is, ciddata, length); read_stream( is, iddata, length);
cid = new String( ciddata); id = new String( iddata);
} }
} }
else else
System.err.println("Error in query_cid(), not starting with CID"); System.err.println("Error in query_id("+ reqmsghead + "), wrong to start with " + header);
} }
catch (UnknownHostException e) { catch (UnknownHostException e) {
System.err.println("Trying to connect to unknown host: " + e); System.err.println("Trying to connect to unknown host: " + e);
@ -221,7 +245,7 @@ public class ImgdecClient{
System.err.println("IOException: " + e); System.err.println("IOException: " + e);
} }
return cid; return id;
} }
public static void read_stream( DataInputStream is, byte []stream, int length) public static void read_stream( DataInputStream is, byte []stream, int length)

View File

@ -77,45 +77,57 @@ public class JPIPHttpClient
public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid) public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid)
{ {
return requestViewWindow( null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false); return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false);
} }
public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh, String reqcid) public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh, String reqcid)
{ {
return requestViewWindow( null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false); return requestViewWindow( null, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false);
} }
public byte[] requestViewWindow( String target, int reqfw, int reqfh) public byte[] requestViewWindow( String target, int reqfw, int reqfh)
{ {
return requestViewWindow( target, reqfw, reqfh, -1, -1, -1, -1, null, false); return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, false);
} }
public byte[] requestViewWindow( String target, int reqfw, int reqfh, boolean reqcnew) public byte[] requestViewWindow( String target, int reqfw, int reqfh, boolean reqcnew)
{ {
if( cid == null) // 1 channel allocation only if( cid == null) // 1 channel allocation only
return requestViewWindow( target, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew); return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew);
else
return null;
}
public byte[] requestViewWindow( String target, String reqtid, int reqfw, int reqfh, boolean reqcnew)
{
if( cid == null) // 1 channel allocation only
return requestViewWindow( target, reqtid, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew);
else else
return null; return null;
} }
public byte[] requestViewWindow( String target, int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh) public byte[] requestViewWindow( String target, int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
{ {
return requestViewWindow( target, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false); return requestViewWindow( target, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false);
} }
public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid, boolean reqcnew) public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid, boolean reqcnew)
{ {
return requestViewWindow( null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew); return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew);
} }
public byte[] requestViewWindow( String target, public byte[] requestViewWindow( String target,
String reqtid,
int reqfw, int reqfh, int reqfw, int reqfh,
int reqrx, int reqry, int reqrx, int reqry,
int reqrw, int reqrh, int reqrw, int reqrh,
String reqcid, boolean reqcnew) String reqcid, boolean reqcnew)
{ {
String urlstring = const_urlstring( target, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew); if( reqtid != null)
tid = reqtid;
String urlstring = const_urlstring( target, reqtid, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew);
return GETrequest( urlstring); return GETrequest( urlstring);
} }
@ -152,6 +164,13 @@ public class JPIPHttpClient
Map<String,java.util.List<String>> headers = urlconn.getHeaderFields(); Map<String,java.util.List<String>> headers = urlconn.getHeaderFields();
java.util.List<String> hvaluelist; java.util.List<String> hvaluelist;
String status = headers.get(null).get(0);
System.err.println( status);
if( !status.contains("OK"))
System.err.println( headers.get("Reason"));
System.err.println( headers.get("Content-type"));
if(( hvaluelist = headers.get("JPIP-fsiz")) != null){ if(( hvaluelist = headers.get("JPIP-fsiz")) != null){
String hvalueline = hvaluelist.get(0); String hvalueline = hvaluelist.get(0);
fw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue(); fw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
@ -243,6 +262,7 @@ public class JPIPHttpClient
} }
private String const_urlstring( String target, private String const_urlstring( String target,
String reqtid,
int reqfw, int reqfh, int reqfw, int reqfh,
int reqrx, int reqry, int reqrx, int reqry,
int reqrw, int reqrh, int reqrw, int reqrh,
@ -258,6 +278,11 @@ public class JPIPHttpClient
urlstring = urlstring.concat( "&"); urlstring = urlstring.concat( "&");
urlstring = urlstring.concat( "target=" + target); urlstring = urlstring.concat( "target=" + target);
} }
if( reqtid != null){
if( !urlstring.endsWith("?"))
urlstring = urlstring.concat( "&");
urlstring = urlstring.concat( "tid=" + reqtid);
}
if( reqfw != -1 && reqfh != -1){ if( reqfw != -1 && reqfh != -1){
if( !urlstring.endsWith("?")) if( !urlstring.endsWith("?"))
urlstring = urlstring.concat( "&"); urlstring = urlstring.concat( "&");

View File

@ -1 +1 @@
opj_viewer_xerces-20110824.jar opj_viewer_xerces-20110825.jar

View File

@ -9,7 +9,8 @@ opj_server_CPPFLAGS = \
-I$(top_srcdir)/applications/jpip/libopenjpip \ -I$(top_srcdir)/applications/jpip/libopenjpip \
-I$(top_builddir)/applications/jpip/libopenjpip \ -I$(top_builddir)/applications/jpip/libopenjpip \
@FCGI_CFLAGS@ \ @FCGI_CFLAGS@ \
-DSERVER -DSERVER \
-DQUIT_SIGNAL=\"quitJPIP\"
opj_server_CFLAGS = opj_server_CFLAGS =
opj_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_server.la @FCGI_LIBS@ -lm opj_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_server.la @FCGI_LIBS@ -lm
opj_server_SOURCES = \ opj_server_SOURCES = \

View File

@ -1,7 +1,7 @@
LIBDIR = ../libopenjpip LIBDIR = ../libopenjpip
LIBFNAME = $(LIBDIR)/libopenjpip_server.a LIBFNAME = $(LIBDIR)/libopenjpip_server.a
CFLAGS = -O3 -Wall -m32 -DSERVER -I$(LIBDIR) CFLAGS = -O3 -Wall -m32 -DSERVER -DQUIT_SIGNAL=\"quitJPIP\" -I$(LIBDIR)
LDFLAGS = -L$(LIBDIR) -lm -lfcgi -lopenjpip_server LDFLAGS = -L$(LIBDIR) -lm -lfcgi -lopenjpip_server
ALL = opj_server ALL = opj_server

View File

@ -55,6 +55,9 @@
#include "imgreg_manager.h" #include "imgreg_manager.h"
#include "msgqueue_manager.h" #include "msgqueue_manager.h"
#ifndef QUIT_SIGNAL
#define QUIT_SIGNAL "quitJPIP"
#endif
#ifdef SERVER #ifdef SERVER
#include "fcgi_stdio.h" #include "fcgi_stdio.h"
@ -103,6 +106,9 @@ int main(void)
query_string = getenv("QUERY_STRING"); query_string = getenv("QUERY_STRING");
#endif //SERVER #endif //SERVER
if( strcmp( query_string, QUIT_SIGNAL) == 0)
break;
fprintf( FCGI_stdout, "Content-type: image/jpt-stream\r\n"); fprintf( FCGI_stdout, "Content-type: image/jpt-stream\r\n");
query_param_t query_param; query_param_t query_param;
@ -131,6 +137,8 @@ int main(void)
delete_msgqueue( &msgqueue); delete_msgqueue( &msgqueue);
} }
fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
delete_sessionlist( &sessionlist); delete_sessionlist( &sessionlist);
delete_targetlist( &targetlist); delete_targetlist( &targetlist);
@ -216,8 +224,10 @@ bool parse_JPIPrequest( query_param_t query_param,
session_param_t *cursession = NULL; session_param_t *cursession = NULL;
channel_param_t *curchannel = NULL; channel_param_t *curchannel = NULL;
if( query_param.target[0] != '\0' || query_param.tid[0] != '\0'){
if( !identify_target( query_param, targetlist, &target)) if( !identify_target( query_param, targetlist, &target))
return false; return false;
}
if( query_param.cid[0] != '\0'){ if( query_param.cid[0] != '\0'){
if( !associate_channel( query_param, sessionlist, &cursession, &curchannel)) if( !associate_channel( query_param, sessionlist, &cursession, &curchannel))
@ -241,32 +251,30 @@ bool parse_JPIPrequest( query_param_t query_param,
bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target) bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target)
{ {
if( query_param.target[0] !='\0') if( query_param.tid[0] !='\0' && strcmp( query_param.tid, "0") != 0 ){
if( !( *target = search_target( query_param.target, targetlist)))
if(!( *target = gene_target( targetlist, query_param.target)))
return false;
if( query_param.tid[0] !='\0'){
if( strcmp( query_param.tid, "0") != 0 ){
if( query_param.cid[0] != '\0'){ if( query_param.cid[0] != '\0'){
fprintf( FCGI_stdout, "Reason: Target can not be specified both through tid and cid\r\n"); fprintf( FCGI_stdout, "Reason: Target can not be specified both through tid and cid\r\n");
fprintf( FCGI_stdout, "Status: 400\r\n"); fprintf( FCGI_stdout, "Status: 400\r\n");
return false; return false;
} }
if( !( *target = search_targetBytid( query_param.tid, targetlist))) if( ( *target = search_targetBytid( query_param.tid, targetlist)))
return true;
}
if( query_param.target[0] !='\0')
if( !( *target = search_target( query_param.target, targetlist)))
if(!( *target = gene_target( targetlist, query_param.target)))
return false; return false;
if( *target){
fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid);
return true;
} }
else{ else{
if( *target) fprintf( FCGI_stdout, "Reason: target not found\r\n");
fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid);
else{
fprintf( FCGI_stdout, "Reason: target not specified\r\n");
fprintf( FCGI_stdout, "Status: 400\r\n"); fprintf( FCGI_stdout, "Status: 400\r\n");
return false; return false;
} }
}
}
return true;
} }
bool associate_channel( query_param_t query_param, bool associate_channel( query_param_t query_param,