Logo Search packages:      
Sourcecode: capisuite version File versions  Download package

CapiSuite::CapiSuite ( int  argc,
char **  argv 
)

Constructor. General initializations.

Creates a Capi object, enables listening, calls readConfiguration, and initializes the Python interpreter in multithreading mode. It immediately releases the global Python lock after doing initialization.

Also an IdleScript object is created and will regularly call the given script.

Parameters:
argc commandline argument count as given to main()
argv commandline arguments as given to main()

Definition at line 51 of file capisuite.cpp.

References capi, config, daemonmode, debug, debug_level, error, Capi::getInfo(), idle, prefix(), py_state, readCommandline(), readConfiguration(), Capi::registerApplicationInterface(), IdleScript::requestTerminate(), save_cStringIO, Capi::setListenFaxG3(), and Capi::setListenTelephony().

:capi(NULL),waiting(),config(),idle(NULL),py_state(NULL),debug(NULL),error(NULL),finish_flag(false),custom_configfile(),daemonmode(false)
{
      if (capisuiteInstance!=NULL) {
            cerr << "FATAL error: More than one instances of CapiSuite created" << endl;
            exit(1);
      }
      capisuiteInstance=this;

      readCommandline(argc,argv);
      readConfiguration();

      try {
            if (daemonmode)
                        // set daemon mode
                  if (daemon(0,0)!=0) {
                        (*error) << prefix() <<  "FATAL error: Can't fork off daemon" << endl;
                        exit(1);
                  }

            debug_level=atoi(config["log_level"].c_str());

            (*debug) << prefix() << "CapiSuite " << VERSION << " started." << endl;
            (*error) << prefix() << "CapiSuite " << VERSION << " started." << endl;

            string DDIStopListS=config["DDI_stop_numbers"];
            vector<string> DDIStopList;
            DDIStopList.push_back("");

            int j=0;          
            for (int i=0;i<DDIStopListS.length();i++) {
                if (DDIStopListS[i]==',') {
                  DDIStopList.push_back("");
                  j++;
                } else {
                  DDIStopList[j]+=DDIStopListS[i];
                }
            }

            // backend init
            capi=new Capi(*debug,debug_level,*error,atoi(config["DDI_length"].c_str()),atoi(config["DDI_base_length"].c_str()),DDIStopList);
            capi->registerApplicationInterface(this);

                string info;
            if (debug_level>=2)
                  info=capi->getInfo(true);
            else
                  info=capi->getInfo(false);
            (*debug) << prefix();
            for (int i=0;i<info.size();i++) {
                  (*debug) << info[i];
                  if (i!=info.size()-1 && info[i]=='\n')
                        (*debug) << prefix();
            }

            capi->setListenTelephony(0); // TODO: 0 = all, evtl. einstellbar?
            capi->setListenFaxG3(0); // TODO: 0 = all, evtl. einstellbar?

            // initialization of the Python interpreter to be thread safe (taken out of PyApache 4.26)
            Py_Initialize();
            PycString_IMPORT; // initialize cStringIO module
            if (!(save_cStringIO=PycStringIO)) { // save it as it will be overwritten by each #include<cStringIO.h> with NULL (sic)
                  (*error) << prefix() << "FATAL error: error during Python interpreter initialization (cString)" << endl;
                  exit(1);
            }
            PyEval_InitThreads();  // init and acquire lock
            py_state=PyEval_SaveThread();  // release lock, save thread context
            if (!py_state) {
                  (*error) << prefix() << "FATAL error: can't release python lock" << endl;
                  exit(1);
            }

            // idle script object
            int interval=atoi(config["idle_script_interval"].c_str());
            if (interval && config["idle_script"]!="")
                  idle=new IdleScript(*debug,debug_level,*error,capi,config["idle_script"],interval,py_state,save_cStringIO);

            // signal handling
            signal(SIGTERM,exit_handler);
            signal(SIGINT,exit_handler);  // this must be located after pyhton initialization
            signal(SIGHUP,hup_handler);
      }
        catch (CapiError e) {
            capisuiteInstance=NULL;
            if (idle) {
                  idle->requestTerminate();
            }
            if (py_state) {
                  PyEval_RestoreThread(py_state); // switch to right thread context, acquire lock
                  py_state=NULL;
                  Py_Finalize();
            }
                if (capi)
                  delete capi;
                (*error) << prefix() << "Can't start Capi abstraction. The given error message was: " << e << endl << endl;
                exit(1);
        }
        catch (ApplicationError e) {
            capisuiteInstance=NULL;
            if (idle) {
                  idle->requestTerminate();
            }
            if (py_state) {
                  PyEval_RestoreThread(py_state); // switch to right thread context, acquire lock
                  py_state=NULL;
                  Py_Finalize();
            }
                if (capi)
                  delete capi;
                (*error) << prefix() << "Can't start application. The given error message was: " << e << endl;
                exit(1);
        }
}


Generated by  Doxygen 1.6.0   Back to index