Ejemplo n.º 1
0
//Files definition section
//Called to setup all the basic sockets
int InitializeClient(void)
{
  int server_len, RC;
  printf("----Initialization\n");
  //Listening port for the Node File transfer handler
  if((qPortSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  {
    return -1;
  }
  qPortAddr.sin_family = AF_INET;
  qPortAddr.sin_addr.s_addr = htons(INADDR_ANY);
  qPortAddr.sin_port = htons(qPort);
  server_len = sizeof(qPortAddr);
  if((bind(qPortSocket, (struct sockaddr *) &qPortAddr, server_len)) < 0)
  {
    return -2;
  }
  
  //A socket to connect to the iServer
  if((uPortSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  {
    return -3;
  }
  //Name the socket as agreed with server.
  uPortAddr.sin_family = AF_INET;
  uPortAddr.sin_addr.s_addr = inet_addr(ServerIP);
  uPortAddr.sin_port = htons(uPort);
  server_len = sizeof(uPortAddr);
  if((RC = connect(uPortSocket, (struct sockaddr *)&uPortAddr, server_len)) == 1)
  {
     return -4;
  }
  
  //Get a list of all the files in the Shared Directory (Current Directory)
  if(fList() != 0)
  {
    return -5;
  }
  
  //Send Start Signal
  strcpy(OutBuffer, "SRT [");
  strcat(OutBuffer, MyIP);
  strcat(OutBuffer, ":");
  strcat(OutBuffer, MyPort);
  strcat(OutBuffer, "]");
  printf("-----To Server: %s\n",OutBuffer);
  write(uPortSocket, OutBuffer, strlen(OutBuffer));
  
  //Send the files list
  fLsend('N');
  
  return 0;
}
Ejemplo n.º 2
0
Entries Directory::entries() const
{
  FileSystem& fs = FileSystem::instance();
  Directory saveDir( fs.workingDirectory() );
  Directory changeDd = *this;
  fs.changeWorkingDirectoryTo( changeDd );
    
  Entries fList( changeDd.toString(), Path::nativeCase, false );
  fList = fs.getFileList();

  fs.changeWorkingDirectoryTo( saveDir );
  return fList;
}
Ejemplo n.º 3
0
FileList FileDir::getEntries() const
{
  FileSystem& fs = FileSystem::instance();
  FileDir saveDir( fs.getWorkingDirectory() );
  FileDir changeDd = *this;
  fs.changeWorkingDirectoryTo( changeDd );
    
	FileList fList( changeDd.toString(), false, false );
	fList = fs.getFileList();

  fs.changeWorkingDirectoryTo( saveDir );
  return fList;
}
Ejemplo n.º 4
0
void ParticleCreatorLatticeBCC::createParticles()
{    
  //RandomNumberGenerator m_rng;
  point_t box_size, spacing, offset;
  //    cuboid_t box;
  // offset due to wall particles
  //    point_t offset = ((Boundary*) m_parent) -> offset();
  double density;
  //    gsl_rng *rng;

//   size_t seed;

  /* We need the manager to check which group a particle has. */
  ManagerCell *manager = M_PHASE->manager();

  box_size = M_BOUNDARY->boundingBox().size();
  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "box_size=" << box_size);
  
  if (m_nlattice_points[0] == -1 &&
      m_nlattice_points[1] == -1 &&
      m_nlattice_points[2] == -1) 
  { 
    for (int i = 0; i < SPACE_DIMS; i++) {
      int n = (int) (box_size[i] / m_distance + 0.5);
      if (n < 1)
        n = 1;
      m_nlattice_points[i] = n;
    }
  }

  offset = M_BOUNDARY->boundingBox().corner1;

  initTransform();

//   if (m_randomize) {
//     seed = 2*getpid() + 1;
//   } else {
//     seed = 1;
//     MSG_INFO("ParticleCreatorLatticeBCC::randomizeVels", "randomize = no --> Numbers won't be random.");
//   }

  //    rng = gsl_rng_alloc(gsl_rng_default);

  //    gsl_rng_set(rng, seed);

  /*    MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "Box size for particles: (" <<
  ((Boundary*) m_parent)->wallBound().x << ", " <<
  ((Boundary*) m_parent)->wallBound().y << ", " <<
  ((Boundary*) m_parent)->wallBound().z << ")");*/

  density = 1;
  for (int i = 0; i < SPACE_DIMS; i++) {/*all this SPECIFIC*/
    
 //     bool dd_is_defined = adjustBoxSize(point_t &size, bool_point_t& frameRCfront,  bool_point_t& frameRCend):dd_defined;
//    spacing[i] = box_size[i]/(m_nlattice_points[i]-1);
    if(m_dd_defined){ /*all this SPECIFIC*/
      spacing[i] = 2*m_distance/(sqrt(3.));
      offset[i] += spacing[i]/4;
      density *= spacing[i];
    }
    else{      /*all this SPECIFIC*/
      // FIXME: the setting of m_distance in this case is a little bit of rubbish and could produce bugs, because m_distance is no array, but spacing is
      int n = m_nlattice_points[i];
      spacing[i] = (double) ((box_size[i] / n ));
      
      m_distance = spacing[i]*sqrt(3.)/2;
      offset[i] += spacing[i]/4;
      density *= spacing[i];
    }
  
  }
    
  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "spacing = " << spacing);

  /* The density that is generated may differ from the density wished in the configuration
  file because the particle are equally spaced in space and have the same distance from
  the boundaries (of the cube, of course). That means the REAL density can still differ
  from this value */
  
  /*SPECIFIC*/
  density = 2/density;

  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "density = " << density);

  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "lattice = " << m_nlattice_points);

  /* All particles sit in a surrounding box of identical size. This is of course assuming the
  Boundary is exactly as big as returnMaxBoxSize proposes. */

  // create the function list for m_properties.unknown()
  // fList will be deleted at the end of this function	
  list<FunctionFixed> fl;
  fList(fl);
  
  // creation of FREE particles
  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "Creating free particles." << ", spacing = " << spacing << ", offset = " << offset << ", m_nlattice_points = " << m_nlattice_points);
                
  for (int i = 0; i < m_nlattice_points[0]; i++)
    for (int j = 0; j < m_nlattice_points[1]; j++)
      for (int k = 0; k < m_nlattice_points[2]; k++)
        for (int l = 0; l < 2; l++) {
    point_t pos = { { {  /*SPECIFIC*/
      i*spacing[0]+offset[0]+l*spacing[0]/2.,
      j*spacing[1]+offset[1]+l*spacing[1]/2.,
      k*spacing[2]+offset[2]+l*spacing[2]/2.
    } } };
    Cell *c;
    Particle p;
	
    p.r = pos;
    p.setColour(m_colour);

    transformPos(p);

    c = manager->findCell(p.r);

    if (c) {
      if (M_BOUNDARY->isInside(p.r)) {
        p.g = c->group();

        for (int w = 0; w < SPACE_DIMS; w++)
          p.v[w] = m_rng.uniform() - 0.5;
        
        // compute all from m_properties.unknown()
        computeUnknown(fl.begin(), p);

        m_particles[p.g].newEntry() = p;
      }
//       else MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "NOT INSIDE: " << p.r << ", i = " << i << ", j = " << j << ", k = " << k << ", l = " << l);
    }
//     else MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "NO CELL: " << p.r << ", i = " << i << ", j = " << j << ", k = " << k << ", l = " << l);
    
      }
      scaleVels();

  // next will call the one in ParticleCreatorFree and then ParticleCreatorFreeF::transformVel
      flushParticles();
}
Ejemplo n.º 5
0
//Daemon to monitor the files
void fMonitor(void)
{
  
  char mBuffer[1000];
  int i,j,k;
  while(1)
  {
    sleep(30);
    RemoveCount = 0;
    AddCount = 0;
    //Copy Current File List to Old List
    for(i = 0; i < fileListSize; i++)
    {
      strcpy(fileListOld[i], fileList[i]);
    }
    OldListSize = i;
    if (fList() == 0)
    {
      for(i = 0; i < OldListSize; i++)
      {
	for(j = 0, k = 0; j < fileListSize; j++)
	{
	  if(strcmp(fileListOld[i], fileList[j]) == 0)
	  {
	    k++;
	  }
	}
	if(k == 0)
	{
	  strcpy(RemoveList[RemoveCount], fileListOld[i]);
	  RemoveCount++;
	}
      }
      for(i = 0; i < fileListSize; i++)
      {
	for(j = 0, k = 0; j < OldListSize; j++)
	{
	  if(strcmp(fileListOld[j], fileList[i]) == 0)
	  {
	    k++;
	  }
	}
	if(k == 0)
	{
	  strcpy(AddList[AddCount], fileList[i]);
	  AddCount++;
	}
      }
      if(RemoveCount > 0)
      {
	fLsend('R');
	/*
	for(i = 0; i < RemoveCount; i++)
	{
	  strcpy(mBuffer, "REM [");
	  strcat(mBuffer, RemoveList[i]);
	  strcat(mBuffer, "]");
	  write(uPortSocket, mBuffer, strlen(mBuffer);
	  sleep(1);
	}*/
      }
      if(AddCount > 0)
      {
	fLsend('A');
	/*for(i = 0; i < AddCount; i++)
	{
	  strcpy(mBuffer, "ADD [");
	  strcat(mBuffer, AddList[i]);
	  strcat(mBuffer, "]");
	  write(uPortSocket, mBuffer, strlen(mBuffer);
	  sleep(1);
	}*/
      }
    }
  }
  //Program control should never come here
  printf("--ERROR - App Node Daemon has stopped, use Ctrl C to kill the application.\n");
  exit(0);
}