Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

main.cpp

Go to the documentation of this file.
00001 
00002 
00008 /********************************************************************
00009 Description: main
00010 part of the 3Dsia project
00011 created: xandi, 31.1.2000
00012 
00013 History:
00014     date,   name,       changes,                    in funtion
00015 
00016 ********************************************************************/
00017 
00018 #include "misc.h"
00019 
00020 #include "visualThread.h"
00021 #include "outputThread.h"
00022 #include "coreThread.h"
00023 #include "configFrontEndPlugIn.h"
00024 
00025 #include "../common/options.h"
00026 #include "../common/config.h"
00027 #include "../common/matrixThread.h"
00028 
00029 #include <dlfcn.h>
00030 #include <string>
00031 
00032 #ifdef TEXTONLYFRONTEND
00033 #define PLUGINNAME "textonlyFrontEnd.so"
00034 #endif
00035 
00036 #ifdef QTFRONTEND
00037 #define PLUGINNAME "qtFrontEnd.so"
00038 #endif
00039 
00040 /*...................................................................
00041 Description: main :)
00042 Args:
00043 Returns:
00044 Created: xandi, 31.1.2000
00045 [ToDo:]
00046 [Comments:]
00047 Changes:
00048         Added dbThread, outputThread    xandi, 120400
00049 -------------------------------------------------------------------*/
00050 
00051 Buffer* matrixBufIn = 0; 
00052 map<int,Buffer*> clientBufferIn; 
00053 
00054 int main (int argc, char** argv)
00055     {
00056     ThreadArgs* targs = new ThreadArgs;
00057 
00058     targs->argc = argc;
00059     targs->argv = argv;
00060 
00061     Config* myConf = new Config ();
00062 
00063     string username;
00064     string password;
00065     string server;
00066 
00067     int   tmpBool = false;
00068     FILE* tmpFile = fopen (CLIENT_CONFIG_FILE, "r");
00069 
00070     if (tmpFile != NULL) tmpBool = true;
00071 
00072     if (tmpBool) {
00073     if (myConf->openConfig (CLIENT_CONFIG_FILE)) {
00074             if (myConf->searchTag ("User")) {
00075             username = myConf->getCharVariable ("Name");
00076             password = myConf->getCharVariable ("Password");
00077             server   = myConf->getCharVariable ("Server");
00078             };
00079     };
00080     } else {
00081         printf ("Configuration-file not present, starting configuration-frontend...\n");
00082 
00083         struct ConfigFrontEndPlugIn* CFEPlugIn;
00084         typedef void* (*pfnPlugIn) (void);
00085         pfnPlugIn getPlugIn;
00086         void*     handler;
00087         string    tmpStr;
00088 
00089         tmpStr = CLIENT_PLUGIN_DIR;
00090         tmpStr+= "/";
00091         tmpStr+= PLUGINNAME;
00092 
00093         if ((handler = dlopen (tmpStr.c_str (), RTLD_NOW)) != NULL) {
00094             if ((getPlugIn = (pfnPlugIn)dlsym (handler, "GetConfigFrontEndPlugIn")) != NULL) {
00095             CFEPlugIn = (ConfigFrontEndPlugIn*) getPlugIn ();
00096             CFEPlugIn->init ();
00097             CFEPlugIn->run (targs->argc, targs->argv);
00098 
00099             dlclose (handler);
00100             } else {
00101             printf ("Not a configuration-frontend-plugin !");
00102             exit (1);
00103             };
00104         } else {
00105             printf ("Could not open configuration-frontend-plugin !");
00106             printf ("%s\n", dlerror ());
00107             exit (1);
00108         };
00109 
00110         printf ("\nConfiguration complete, starting client...\n");
00111     };
00112 
00113     fprintf(stderr,"\n[3Dsia Reference Client v %d.%d.%d]",VERSION_MAJOR,
00114                                                            VERSION_MINOR,
00115                                                            PATCH_LEVEL );
00116     fprintf(stderr," written 2000 by Marc Haisenko & Alexander Feder\n");
00117 
00118     if ( (argc > 4) || (argv[1] == "-h") || (argv[1] == "--help") )
00119         {
00120         fprintf(stderr,"\nusage:\n");
00121         fprintf(stderr,"\t   %s \n",argv[0]);
00122         fprintf(stderr,"\tor %s Username Password ServerIP\n",argv[0]);
00123         exit(1);
00124         }
00125 
00126     switch (argc) {
00127     case 4 : server   = argv[3];
00128     case 3 : password = argv[2];
00129     case 2 : username = argv[1];
00130     default: break;
00131     };
00132 
00133     if (username == "") username = "clonewar";
00134     if (password == "") password = "idpman";
00135     if (server   == "") server   = "127.0.0.1";
00136 
00137     targs->argc = 4;
00138     targs->argv[1] = const_cast<char*>(username.c_str());
00139     targs->argv[2] = const_cast<char*>(password.c_str());
00140     targs->argv[3] = const_cast<char*>(server.c_str());
00141 
00142     extern Buffer* outputBufferIn;
00143 
00144     outputBufferIn = new Buffer(); //in order to prevent any segfaults if threads try to access this buffer even if outputThread didn't even yet created it..
00145 
00146     //CAREFUL: Following will not work once the client is capable of connecting to more servers than one at the same time
00147     matrixBufIn    = new Buffer();
00148     clientBufferIn[CLIENT_OUTPUT] = outputBufferIn;
00149 
00150     pthread_t oThread; //output
00151     pthread_t mThread; //matrix
00152     pthread_t cThread; //core
00153 
00154     pthread_create (&mThread, NULL, MatrixThread, NULL);
00155     pthread_create (&cThread, NULL, coreThread, targs);
00156     pthread_create (&oThread, NULL, outputThread, targs);
00157 
00158     pthread_join (oThread, NULL);
00159     pthread_join (mThread, NULL);
00160     pthread_join (cThread, NULL);
00161 
00162     fprintf(stderr,"\nbye!\n");
00163 
00164     return 0;
00165     }

Generated at Sat May 13 13:50:19 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000