Koala Library
koala_init.c
Go to the documentation of this file.
00001 //--------------------------------------------------------------------------------//
00002 //-                   KOALA( Koala extension board                       )                       -//
00003 //                                                                               -//
00004 //-  Copyright (C) Julien Tharin, K-Team S.A. 2013                               -//
00005 //-  This library is free software; you can redistribute it and/or               -//
00006 //-  modify it under the terms of the GNU Lesser General Public                  -//
00007 //-  License as published by the Free Software Foundation; either                -//
00008 //-  version 2.1 of the License, or any later version.                           -//
00009 //-                                                                              -//
00010 //-  This library is distributed in the hope that it will be useful,             -//
00011 //-  but WITHOUT ANY WARRANTY; without even the implied warranty of              -//
00012 //-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           -//
00013 //-  Lesser General Public License for more details.                             -//
00014 //-                                                                              -//
00015 //-  You should have received a copy of the GNU Lesser General Public            -//
00016 //-  License along with this library; if not, write to the Free Software         -//
00017 //-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   -//
00018 //-                                                                              -//
00019 //-                               __  __  ________                               -//
00020 //- K-Team S.A.                  |  |/  /|__    __|___  _____  ___  ___          -//
00021 //- Chemin des Plans-Praz 28,    |     / __ |  | _____|/  _  \|   \/   |         -//
00022 //- 1337 Vallorbe                |  |  \    |  | ____|/  /_\  |        |         -//
00023 //- Switzerland                  |__|\__\   |__|______|_/   \_|__|\/|__|         -//
00024 //- jtharin@k-team.com   tel:+41 24 423 89 56 fax:+41 24 423 8960                -//
00025 //-                                                                              -//
00026 //--------------------------------------------------------------------------------//
00027 
00029 
00032 
00033 
00034 /* ---- Include Files ---------------------------------------------------- */
00035 
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <getopt.h>
00039 
00040 #include "koala.h"
00041 
00042 
00043 /* ---- Private Constants and Types -------------------------------------- */
00044 static int koala_init_done = 0;
00045 
00046 // long options: --version , --debug
00047 struct option opts[] = {   
00048   { "debug" ,   0 , 0 , 'd' } ,
00049   { "version" , 0 , 0 , 'v' } ,
00050   { NULL      ,    0 , 0 , 0    }
00051 };
00052 
00053 
00054 char short_opts[] = "d:v"; // -v  -d
00055 
00056 /* ---- Internal Functions ----------------------------------------------- */
00057 
00058 
00059 
00060 /* ---- Exported Functions------------------------------------------------ */
00061 
00062 /*--------------------------------------------------------------------*/
00072 int koala_init( int argc , char * argv[] )
00073 {
00074   int opt, rc;
00075 
00076   if ( koala_init_done == 0 ) {
00077 
00078     for (;;) {
00079       opt = getopt_long( argc , argv , short_opts , opts , NULL );
00080       if ( opt == -1 )
00081         break;
00082                         
00083       switch( opt ) {
00084                         
00085                                 case 'd': // debug
00086                                         break;
00087 
00088         /* --koala-version */
00089         case 'v':
00090            printf("libkoala v%u.%u [%s]\n" ,KOALA_VERSION ,KOALA_REVISION , __DATE__ );
00091           break;
00092 
00093         default:
00094           break;
00095       }
00096     }
00097 
00098                 if (koala_robot_init()!=0)
00099                 {
00100                         return -1;
00101                 } 
00102 
00103                 
00104     atexit( koala_exit );
00105 
00106     koala_init_done = 1;
00107     
00108     return 0;
00109   }
00110 
00111   return 1;
00112 }
00113 
00114 /*--------------------------------------------------------------------*/
00121 void koala_exit(void)
00122 {
00123   if ( koala_init_done ) {
00124 
00125     koala_init_done = 0;
00126     
00127     koala_robot_release();
00128     
00129   }
00130 }