test1_main.c

00001 /*   
00002  *   (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net)
00003  *
00004  *   This file is part of FREESECS.
00005  *
00006  *   FREESECS is free software: you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation, either version 3 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   FREESECS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with FREESECS, see COPYING.
00018  *   If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 #include <stdio.h>
00021 #include <unistd.h>
00022 #include <stdlib.h>
00023 #include "hsmsd_cli.h"
00024 
00025 static FILE *fp = NULL;
00026 
00027 
00028 void hsms_msg_handler(hsmsd_msg_t* msg)
00029 {
00030     unsigned char *begin = NULL, *end = NULL, *iter = NULL;
00031     unsigned int ctr = 0;
00032     printf("hsms_msg_handler: s%df%d\n", msg->stream, msg->function);
00033     
00034     if(fp)
00035     {
00036         fprintf(fp, "s%df%d, len=%d\n", msg->stream, msg->function, msg->data_len);
00037     
00038         begin   = &msg->data[0];
00039         end     = &msg->data[0] + msg->data_len;
00040         for(iter = begin; iter < end; ++iter)
00041         {
00042             fprintf(fp, "0x%x, ", *iter);
00043             if(ctr++ > 10)
00044             {
00045                 fprintf(fp, "\n");
00046                 ctr = 0;
00047             }
00048         }
00049         fprintf(fp, "\n\n\n");
00050         fflush(fp);
00051     }
00052     
00053     free(msg);
00054 }
00055 
00056 void hsms_cnx_state_handler(hsmsd_cnx_state_t state)
00057 {
00058     static char str_state[][32] = {"NOT CONNECTED", "NOT SELECTED", "SELECTED"};
00059 
00060     printf("hsms_cnx_state_handler: %s\n", str_state[state]);
00061 }
00062 
00063 void hsmsd_cnx_error_handler(int err)
00064 {
00065     printf("hsmsd_cnx_error_handler: %d\n", err);
00066 }
00067 
00068 
00069 int main(int argc, char **argv)
00070 {
00071     int r;
00072     hsmsd_handle_t h;
00073 
00074     r = hsmsd_alloc_handle(&h, "hsms1");
00075     printf("hsmsd_alloc_handle returned %d\n", r);
00076     if(r) exit(-1);
00077 
00078     r = hsmsd_subscribe_for_msgs(h, (hsmsd_msg_handler_t)hsms_msg_handler );
00079     printf("hsmsd_subscribe_for_msgs returned %d\n", r);
00080     if(r) exit(-2);
00081 
00082     r = hsmsd_subscribe_for_cnx_state(h, (hsmsd_cnx_state_handler_t)hsms_cnx_state_handler);
00083     printf("hsmsd_subscribe_for_cnx_state returned %d\n", r);
00084     if(r) exit(-3);
00085 
00086     r = hsmsd_subscribe_for_cnx_error(h, (hsmsd_cnx_error_handler_t)hsmsd_cnx_error_handler);
00087     printf("hsmsd_subscribe_for_cnx_error returned %d\n", r);
00088     if(r) exit(-4);
00089 
00090     fp = fopen("./msgs.txt", "w+");
00091     if(!fp) exit(-5);
00092 
00093     r = hsmsd_cnx_start(h);
00094     printf("hsmsd_cnx_start returned %d\n", r);
00095     if(r) exit(-6);
00096 
00097     while(1) sleep(2);
00098 
00099 
00100     exit(0);
00101 }

Generated on Fri Oct 3 15:30:01 2008 for FREESECS hsms by  doxygen 1.5.1