// --------------------------------------------------------------------------
//! read an element and all the child from the buffer starting at the given pointer
// --------------------------------------------------------------------------
void XipTreeRequestReceiver::readElementFromBuffer(RequestTreeElement * CurrentElement, char *buffer, int sizeBuffer)
{
	//recursive parsing function, calling itself on the childs elements when found


	#if _DEBUGINFILE__
	std::ofstream debugFile("c:\\RequestDebug.txt", std::ofstream::out | std::ofstream::app);
	if(debugFile.is_open())
	{
		debugFile << "readElement id:"<<CurrentElement->mElementID<<std::endl;
		debugFile << "readElement size:"<<sizeBuffer<<std::endl;
		debugFile <<"buffer ||";
		debugFile.write(buffer, sizeBuffer);
		debugFile.flush();
		debugFile <<"|| endbuffer"<<std::endl;
		debugFile.flush();
		debugFile.close();
	}
	#endif


	short childID;
	int childSize;	

	while(sizeBuffer > 0)
	{
		if(sizeBuffer > SIZESEPARATOR && buffer[0] == 'O' && buffer[1] == 'P')
		{

			buffer += 2;

			childID = ntohs(*((short *)buffer));
			buffer += sizeof(short);

			childSize = ntohl(*((int *)buffer));
			buffer += sizeof(int);


			RequestTreeElement * fChild = ++mPtrTabElement;
			fChild->init(childID);
			CurrentElement->addChildElement(fChild);
			nbUsedElement++;
		
			readElementFromBuffer(fChild, buffer, childSize);

			sizeBuffer -= (2 + sizeof(short) + sizeof(int) + childSize);
			buffer += childSize;
		}
		else
		{
			CurrentElement->mBuffer = buffer;
			CurrentElement->mBufferSize = sizeBuffer;
			buffer += sizeBuffer;
			sizeBuffer = 0;
		}
	}
}
// --------------------------------------------------------------------------
//! method used to receive the request
// --------------------------------------------------------------------------
void XipTreeRequestReceiver::receive()
{
	// receive the buffer, then call the function readElementFromBuffer to
	// read the tree from it

	int sizeRecBuf = 0;

	init();

	sizeRecBuf = mStream->recv(mSocketBuffer, XIP_STREAM_BUFFER_SIZE, 0);
	if(sizeRecBuf <= 0) 
    {
		//throw RadException(__LINE__, __FILE__, RadException::COMM_ERROR, L"Communication error (request received invalid )");
        return;
    }

	char * remainingBufferPtr = mSocketBuffer;

	if(!remainingBufferPtr && sizeRecBuf < 4 + 2*sizeof(short))
    {
		//throw RadException(__LINE__, __FILE__, RadException::INVALID_STATE_ERROR, L"Received buffer  invalid");
        return;
    }

	remainingBufferPtr += 2;

	short reqID = ntohs(*((short *)remainingBufferPtr));
	remainingBufferPtr += sizeof(short);

	int sizeReq = ntohl(*((int *)remainingBufferPtr));
	remainingBufferPtr += sizeof(int);

	mTabElements->init(reqID);
	nbUsedElement++;

	#if _DEBUGINFILE__
	std::ofstream debugFile("c:\\RequestDebug.txt", std::ofstream::out | std::ofstream::app);
	if(debugFile.is_open())
	{
		debugFile << "readElement id:"<<reqID<<" htons:"<<htons(reqID)<<std::endl;
		debugFile << "readElement size:"<<sizeReq<<std::endl;
		debugFile <<"buffer ||";
		debugFile.write(mSocketBuffer, sizeRecBuf);
		debugFile.flush();
		debugFile <<"|| endbuffer"<<std::endl;
		debugFile.flush();
		debugFile.close();
	}
	#endif	

	readElementFromBuffer(mTabElements, remainingBufferPtr ,sizeReq);
}
void handleQDebugMessages(QtMsgType type,
                          const QMessageLogContext& context, const QString& message)
{
    QScopedPointer<QTextStream> debugFileWriter;
#if PIPE_DEBUG_OUTPUT_TO_FILE
    QFile debugFile(DEBUG_LOG_NAME);

    if (debugFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
    {
        debugFileWriter.reset(new QTextStream(&debugFile));
    }
    else
#endif
    {
        debugFileWriter.reset(new QTextStream(stdout));
    }

    switch (type)
    {
        default:
        case QtDebugMsg:
            *debugFileWriter << "DEBUG: " << QDateTime::currentDateTime().toString("Thh:mm:ss:zzz: ")
                             << message << endl;
            break;

        case QtWarningMsg:
            *debugFileWriter << "WARNING: " << QDateTime::currentDateTime().toString("Thh:mm:ss:zzz: ")
                             << message << endl << "   " << printOutContext(context) << endl;
            break;

        case QtCriticalMsg:
            *debugFileWriter << "CRITICAL: " << QDateTime::currentDateTime().toString("Thh:mm:ss:zzz: ")
                             << message << endl << "   " << printOutContext(context) << endl;
            break;

        case QtFatalMsg:
            *debugFileWriter << "FATAL: " << QDateTime::currentDateTime().toString("Thh:mm:ss:zzz: ")
                             << message << endl << "   " << printOutContext(context) << endl;
            abort();
    }
}
Esempio n. 4
0
int main ( int argc, char *argv[] )
{
	std::ofstream logFile( "Log.txt" );
	SET_LOUT( logFile );

	D_COMMAND( std::ofstream debugFile( "Debug.txt" ); );
Esempio n. 5
0
void bbCloseFile( bbFile *f ){
	debugFile( f );
	file_set.erase( f );
	delete f;
}
Esempio n. 6
0
void NeuralNetwork::simulate(int timeSteps) {
  std::stringstream debugFilePath;
  debugFilePath << "netsimmpi-debug-process-" << world.rank() << ".txt";
  std::ofstream debugFile(debugFilePath.str().c_str());

  // debug
  for ( int i = 0; i < 10; i++) {
    Neuron* neuron = localNeuronList[i];
    debugFile << neuron->getTypeId() << ' ';
  }
  debugFile << std::endl;
  // debug

  boost::random::poisson_distribution<> externalSpikeDistribution(externalInputDistMean);

  int remoteSpikeCount = 0;

  int verbose = 0;

  for (int t = 1; t <= timeSteps; t++) {
    if ( t % 10000 == 0 ) {
    //if (t % 1 == 0) {
      std::cout << "process " << world.rank() << " t: " << t * dt << " ms total spiking neuron count: " << totalSpikingNeuronCount << std::endl;
    }
    // handle local spikes
    // deliver spikes arriving now
    // spikes from remote neurons have already been added to the appropriate list
    int spikingNeuronCount = 0;
    int receivedSpikeCount = 0;
    int spikeListIndex = t % maxSpikeDelay;
    if (verbose) std::cout << "spike list index " << spikeListIndex << std::endl;
    std::vector<double>* currentSpikeList = localSpikeList[spikeListIndex];
    if ( ! currentSpikeList->empty() ) {
      int c = 0;
      while (c < currentSpikeList->size()) {
        //std::cout << "  connection " << c << std::endl;
        // original (local) implementation
        //Connection* connection = currentSpikeList->at(c);
        //connection->target->receiveSpike(connection->efficacy);
        int neuronId = currentSpikeList->at(c);
        c++;
        double efficacy = currentSpikeList->at(c);
        c++;
        neuronList[neuronId]->receiveSpike(efficacy);
        receivedSpikeCount++;
        if (verbose) std::cout << "t " << t << " rank " << world.rank() << ": local neuron " << neuronId << " in world.rank " << world.rank() << " received spike with efficacy " << efficacy << std::endl;
      }
      currentSpikeList->clear();
    }
    if (verbose) std::cout << "t " << t << " rank " << world.rank() << ": " << receivedSpikeCount << " spike(s) received " << std::endl;
    //std::cout << "updating neuron activity" << std::endl;
    for ( int n = 0; n < localNeuronList.size(); n++ ) {
      //std::cout << "  n " << n << std::endl;
      LocalNeuron* neuron = localNeuronList.at(n);
      if ( neuron->refractoryTimeRemaining > 0 ) {
        neuron->refractoryTimeRemaining--;
        neuron->setActivity(neuronRestingPotential);
      }
      else {
        neuron->updateActivity(externalSpikeDistribution(rng));
        if ( neuron->getActivity() > spikeThreshold ) {
          // count number of neurons that spike this time step
          spikingNeuronCount++;
          totalSpikingNeuronCount++;
          if (verbose) std::cout << "t " << t << " rank " << world.rank() << ": local neuron " << neuron->getId() << " spiked" << std::endl;
          neuron->spikeNow(t, maxSpikeDelay);
          neuron->refractoryTimeRemaining = neuronRefractoryTime;
        }
      }
      // debug
      if ( n < 10 ) {
        debugFile << neuron->getActivity() << ' ';
      }
    }
    debugFile << std::endl;
    if (verbose) std::cout << "t " << t << " rank " << world.rank() << ": " << spikingNeuronCount << " neuron(s) spiked" << std::endl;

    //std::cout << "all_gather" << std::endl;
    // send spikes to remote neurons
    std::vector< std::vector<double> > remoteSpikeProcessList;
    if (verbose) std::cout << "t " << t << " rank " << world.rank() << " before all_gather remoteSpikeProcessList has size " << remoteSpikeProcessList.size() << std::endl;
    if (verbose) std::cout << "t " << t << " rank " << world.rank() << " sending remoteSpikeList[0] with size " << remoteSpikeList[0]->size() << std::endl;
    boost::mpi::all_gather(world, *remoteSpikeList[0], remoteSpikeProcessList);
    if (verbose) std::cout << "t " << t << " rank " << world.rank() << " after all_gather remoteSpikeProcessList has size " << remoteSpikeProcessList.size() << std::endl;

    for ( int allgather_rank = 0; allgather_rank < world.size(); allgather_rank++ ) {
      //std::cout << "process " << world.rank()
      //          << " reading remote spike list from mpi process with rank " 
      //          << allgather_rank << std::endl;
      // do not do anything with this process's neurons
      if ( allgather_rank == world.rank() ) {
        if (verbose) std::cout << "t " << t << " rank " << world.rank() << " skipping local spikes from process with rank " << allgather_rank << std::endl;
      }
      else {
        std::vector<double> _remoteSpikeList = remoteSpikeProcessList[allgather_rank];
        if (verbose) std::cout << "t " << t << " rank " << world.rank() << " remote spike list from process with rank " << allgather_rank << " has " << _remoteSpikeList.size() / 4 << " spikes (list size " << _remoteSpikeList.size() << ")" << std::endl;
        int s = 0;
        while ( s < _remoteSpikeList.size() ) {
          int sourceNeuronId = _remoteSpikeList[s];
          s++;
          int targetNeuronId = _remoteSpikeList[s];
          s++;
          double efficacy = _remoteSpikeList[s];
          s++;
          int arrivalTimeStep = _remoteSpikeList[s];
          s++;
          if ( arrivalTimeStep <= t ) {
            std::cout << "arrival time step " << arrivalTimeStep << " is less than current time step " << t << std::endl;
          }
          if (verbose) std::cout << "t " << t << " rank " << world.rank() << ": remote neuron " << sourceNeuronId << " sent a spike to neuron " << targetNeuronId << " with efficacy " << efficacy << " and arrival time " << arrivalTimeStep << std::endl;
          if ( (targetNeuronId % world.size()) == world.rank() ) {
            // the target neuron is local
            if ( (sourceNeuronId % world.size() == world.rank()) ) {
              std::cout << "source neuron is local !!!" << std::endl;
            }
            else {
              if (verbose) std::cout << "  neuron " << targetNeuronId << " is local to process with rank " << world.rank() << std::endl;
              LocalNeuron* localNeuron = (LocalNeuron*) neuronList[targetNeuronId];
              localNeuron->scheduleSpikeArrival(sourceNeuronId, arrivalTimeStep, maxSpikeDelay, efficacy);
              remoteSpikeCount++;
            }
          }
          else {
            // this neuron is not local
            if (verbose) std::cout << "  neuron " << targetNeuronId << "is NOT local to process with rank " << world.rank() << std::endl;            
          }
        }
      }
    }
    remoteSpikeList[0]->clear();
  }
  std::cout << "process " << world.rank() << " has remote spike count " << remoteSpikeCount << std::endl;
  std::cout << "process " << world.rank() << " has total spiking neuron count " << totalSpikingNeuronCount << std::endl;
}
Esempio n. 7
0
BOOL CPBXClientApp::InitInstance()
{
	
	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(REG_KEY_APP);

	CString lang = GetProfileString("Settings", "Language", "");
	SetLanguage(lang);
	   
	CString cmdLine = this->m_lpCmdLine;

	HWND hwnd = FindWindow(NULL, _T("BSOC Main Application Window"));

	m_bShellOpenFile = FALSE;	
	m_bAllowCmdLineOriginate = 1;	
	m_bDeveloperVersion = TRUE;

	if (cmdLine.Left(9).MakeLower()=="originate") {
		Semaphore s(ORIGINATE_FILE_MUTEX);
		CStdioFile debugFile(::theApp.GetInstallDir()+"\\originate.tmp", CFile::modeCreate | CFile::modeWrite);
		debugFile.SeekToEnd();
		debugFile.WriteString(cmdLine);
		debugFile.Close();		
		return TRUE;
	}	

	if (hwnd!=NULL) { //only one instance of OutCALL can be run		
		CString str;
		str.Format(_("%s is already running."), APP_NAME);
		MessageBox(NULL, str, APP_NAME, MB_ICONINFORMATION | MB_OK);
		return FALSE;
	}

	WSADATA		WSAData = { 0 };
	if ( 0 != WSAStartup( WSA_VERSION, &WSAData ) )
	{
		// Tell the user that we could not find a usable
		// WinSock DLL.
		if ( LOBYTE( WSAData.wVersion ) != LOBYTE(WSA_VERSION) ||
			 HIBYTE( WSAData.wVersion ) != HIBYTE(WSA_VERSION) )
			 ::MessageBox(NULL, _("Incorrect version of WS2_32.dll found."), APP_NAME, MB_OK | MB_ICONERROR);

		WSACleanup( );
		return FALSE;
	}	
	

	if (_tcscmp(this->m_lpCmdLine, _T("background"))==0) {
		Sleep(10000);
	} else if (cmdLine!="") {
		m_bShellOpenFile = TRUE;
		ReadConfigFile(cmdLine);		
	}

	AfxOleInit();
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	CMainFrame* pFrame = new CMainFrame;
	m_pMainWnd = pFrame;

	pFrame->CreateDatabaseTable("RecivedCalls", "CREATE TABLE RecivedCalls(Date TEXT, Time TEXT, Callee TEXT, CallerID TEXT, Sec NUMERIC)");
	pFrame->CreateDatabaseTable("PlacedCalls", "CREATE TABLE PlacedCalls(Date TEXT, Time TEXT, Callee TEXT, CallerID TEXT, Sec NUMERIC)");
	pFrame->CreateDatabaseTable("MissedCalls", "CREATE TABLE MissedCalls(NewCall NUMERIC, Date TEXT, Time TEXT, Callee TEXT, CallerID TEXT, Sec NUMERIC)");
	pFrame->CreateDatabaseTable("Contacts", "CREATE TABLE Contacts(Title TEXT, FirstName TEXT, MiddleName TEXT, LastName TEXT, Suffix TEXT, CompanyName TEXT, Assistant TEXT, Business TEXT, Business2 TEXT, BusinessFax TEXT, Callback TEXT, Car TEXT, Company TEXT, Home TEXT, Home2 TEXT, HomeFax TEXT, ISDN TEXT, Mobile TEXT, Other TEXT, OtherFax TEXT, Pager TEXT, PrimaryTel TEXT, Radio TEXT, Telex TEXT, TTYTDD TEXT)");

	// create and load the frame with its resources
	int left = (GetSystemMetrics(SM_CXSCREEN)-500)/2;	
	int top = (GetSystemMetrics(SM_CYSCREEN)-500)/2;
	

	pFrame->LoadFrame(IDR_MAINFRAME,
		WS_OVERLAPPEDWINDOW | WS_MINIMIZE | FWS_ADDTOTITLE, NULL,
		NULL);
	pFrame->MoveWindow(left, top, left+500, top+500);


	// The one and only window has been initialized, so show and update it.
	pFrame->ShowWindow(SW_HIDE);
	pFrame->UpdateWindow();

	//pFrame->SetWindowPos(&pFrame->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
	this->m_pMainWnd = pFrame;	
		
	// To create the main window, this code creates a new frame window
	// object and then sets it as the application's main window object.

	IntegrateIntoOutlook();
		
	BOOL showSettingsDlg = (GetProfileInt("Settings", "ShowSettingsOnStartup", 0)==1?TRUE:FALSE);
	CSettingsDlg settingsDlg;
	
	if (showSettingsDlg || (pFrame->IsOutCALLConfigured()==false)) {
		settingsDlg.DoModal();		
	}

	if (GetProfileInt("Settings", "ContactsLoaded", 0)==0 && GetProfileInt("Settings", "OutlookFeatures", 1)==1) {
		pFrame->LoadOutlookContacts(NULL);		
	}

	return TRUE;
}