Ejemplo n.º 1
0
void
BBPhoneAccount::onProcessStarted()
{
    Q_DEBUG("Process started!");

    m_sock = new QLocalSocket(this);
    if (NULL == m_sock) {
        Q_WARN("Failed to allocate local socket");
        return;
    }

    m_sock->connectToServer ("qgvdial");
    if (!m_sock->waitForConnected (1000)) {
        Q_WARN("Waiting for a second to connect to server");
        QTimer::singleShot (1000, this, SLOT(onProcessStarted()));
        delete m_sock;
        m_sock = NULL;
        return;
    }

    Q_DEBUG("Socket connected");

    if (!pingPong()) {
        return;
    }

    connect(m_sock, SIGNAL(readyRead()), this, SLOT(onGetNumber()));
    m_sock->write("getNumber");

    m_TimerLogMessage.start ();
}//BBPhoneAccount::onProcessStarted
Ejemplo n.º 2
0
static void runPingTest(TestRunner& tr)
{
   tr.test("Ping");

   Config cfg = tr.getApp()->getConfig()["pong"];

   // Stats and control
   PingPong pingPong(cfg);

   // create kernel
   Kernel k;

   // set thread stack size in engine (128k)
   k.getEngine()->getThreadPool()->setThreadStackSize(
      cfg["threadStackSize"]->getUInt32());

   // optional for testing --
   // limit threads to 2: one for accepting, 1 for handling
   //k.getEngine()->getThreadPool()->setPoolSize(2);
   k.getEngine()->getThreadPool()->setPoolSize(cfg["threads"]->getUInt32());

   // start engine
   k.getEngine()->start();

   // create server
   Server server;
   server.setMaxConnectionCount(cfg["maxConnections"]->getInt32());
   InternetAddress address("0.0.0.0", cfg["port"]->getUInt32());

   // create SSL/generic http connection servicer
   HttpConnectionServicer hcs;
//   SslContext context;
//   SslSocketDataPresenter presenter1(&context);
//   NullSocketDataPresenter presenter2;
//   SocketDataPresenterList list(false);
//   list.add(&presenter1);
//   list.add(&presenter2);
   //server.addConnectionService(&address, &hcs);//, &list);
   server.addConnectionService(
      &address, &hcs, NULL, "pong",
      cfg["maxConnections"]->getInt32(),
      cfg["backlog"]->getInt32());

   // create test http request servicer
   NoContentServicer noContentSrv(&pingPong, "/");
   hcs.addRequestServicer(&noContentSrv, false);

   PingServicer ping(&pingPong, "/pong");
   hcs.addRequestServicer(&ping, false);

   const int bufsize = 4096;
   char buf[bufsize];
   memset(buf, '.', bufsize);
   DataServicer data(&pingPong, "/data", buf, bufsize);
   hcs.addRequestServicer(&data, false);

   StatsServicer stats(&pingPong, "/stats");
   hcs.addRequestServicer(&stats, false);

   ResetServicer reset(&pingPong, "/reset");
   hcs.addRequestServicer(&reset, false);

   QuitServicer quit(&pingPong, "/quit");
   hcs.addRequestServicer(&quit, false);

   if(server.start(&k))
   {
      uint64_t num = cfg["num"]->getUInt64();
      MO_INFO("Server started.");
      if(num == 0)
      {
         MO_INFO("Servicing forever. CTRL-C to quit.");
      }
      {
         MO_INFO("Servicing approximately %" PRIu64 " connections.", num);
      }
   }
   else if(Exception::get() != NULL)
   {
      MO_ERROR("Server started with errors=%s\n",
         Exception::get()->getMessage());
   }

   // start timing
   pingPong.reset();

   // either serve for limited time, or wait for lock
   uint32_t time = cfg["time"]->getUInt32();
   if(time != 0)
   {
      Thread::sleep(time);
   }
   else
   {
      pingPong.getLock().wait();
   }

   server.stop();
   MO_INFO("Server stopped.");

   // stop kernel engine
   k.getEngine()->stop();

   tr.passIfNoException();
}
Ejemplo n.º 3
0
int main (int argc, char *argv[])
{
  int i ;
  int lcd ;
  int bits, rows, cols ;

  struct tm *t ;
  time_t tim ;

  char buf [32] ;

  if (argc != 4)
    return usage (argv [0]) ;

  printf ("Raspberry Pi LCD test\n") ;
  printf ("=====================\n") ;

  bits = atoi (argv [1]) ;
  cols = atoi (argv [2]) ;
  rows = atoi (argv [3]) ;

  if (!((rows == 1) || (rows == 2) || (rows == 4)))
  {
    fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  if (!((cols == 16) || (cols == 20)))
  {
    fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  wiringPiSetup () ;

  if (bits == 4)
    lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;
  else
    lcdHandle = lcdInit (rows, cols, 8, 11, 10, 0,1,2,3,4,5,6,7) ;

  if (lcdHandle < 0)
  {
    fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
    return -1 ;
  }

  lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ;
  lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

  waitForEnter () ;

  if (rows > 1)
  {
    lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

    if (rows == 4)
    {
      lcdPosition (lcdHandle, 0, 2) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "=-") ;
      lcdPuts (lcdHandle, "=3") ;

      lcdPosition (lcdHandle, 0, 3) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "-=") ;
      lcdPuts (lcdHandle, "-4") ;
    }
  }

  waitForEnter () ;

  lcdCharDef  (lcdHandle, 2, newChar) ;

  lcdClear    (lcdHandle) ;
  lcdPosition (lcdHandle, 0, 0) ;
  lcdPuts     (lcdHandle, "User Char: ") ;
  lcdPutchar  (lcdHandle, 2) ;

  lcdCursor      (lcdHandle, TRUE) ;
  lcdCursorBlink (lcdHandle, TRUE) ;

  waitForEnter () ;

  lcdCursor      (lcdHandle, FALSE) ;
  lcdCursorBlink (lcdHandle, FALSE) ;
  lcdClear       (lcdHandle) ;

  for (;;)
  {
    scrollMessage (0, cols) ;
    
    if (rows == 1)
      continue ;

    tim = time (NULL) ;
    t = localtime (&tim) ;

    sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;

    lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
    lcdPuts     (lcdHandle, buf) ;

    if (rows == 2)
      continue ;

    sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;

    lcdPosition (lcdHandle, (cols - 10) / 2, 2) ;
    lcdPuts     (lcdHandle, buf) ;

    pingPong (lcd, cols) ;
  }

  return 0 ;
}
Ejemplo n.º 4
0
void sendFile(const char* fileName, PacketSender& packetSender, int studentNo)
{
    static const char progressChar[] = "...--oo*OO0";

    uint8_t Sector[SECTORSIZE];
    FILE* infile;
    struct stat stat_p;
    int sectNo = 0;

    // check the size of file
    stat(fileName, &stat_p);

    infile = fopen(fileName, "rb");
    if (infile == 0) {
        eggog("Error: cannot open %s\n", fileName);
    }

    info("Sending file %s to workstation %d\n", fileName, studentNo);

    // Send ping
    if (!pingPong(packetSender, studentNo)) eggog("No reply from workstation %d\n", studentNo);

    // Create file on the net disk
    {
        NetCreateFilePacket createFile(0, studentNo, fileName);
        packetSender.SendPacketVal(createFile);
        if (!packetSender.ReceivePacket()) {
            eggog("No ack of create file from %d\n", studentNo);
        }
    }
    verbose("\nGot re: NET_CREATE_FILE.\n");

    // Reading the file sector-by-sector and writing them onto the net disk

    info("\nNumber of sectors to send: %zd\n", 
        (size_t) ((stat_p.st_size / sizeof (Sector)) + (stat_p.st_size % sizeof (Sector))));

    while (!feof(infile))
    {
        if (fread(Sector, sizeof(Sector), 1, infile) == 0) break;

        {
            NetMasterDataPacket data(0, studentNo, Sector, SECTORSIZE);
            packetSender.SendPacketVal(data);

            NetWriteFilePacket writeFile(0, studentNo, packetSender.GetNetFCB());
            packetSender.SendPacketVal(writeFile);
            if (!packetSender.ReceivePacket()) {
                eggog("No ack of file write from %d\n", studentNo);
            }
        }
        verbose("\nSent sector No.%d", sectNo);

        if ((sectNo+1) % 10 == 0) {
            info("%3d%c", sectNo+1, ((sectNo+1) % 100 == 0) ? '\n' : ' ');
        }
        else {
            info("%c\010", progressChar[sectNo % 10]);
        }

        sectNo++;
    }

    // close the file on the net disk
    {
        NetCloseFilePacket closeFile(0, studentNo, packetSender.GetNetFCB());
        packetSender.SendPacketVal(closeFile);
        if (!packetSender.ReceivePacket()) {
            eggog("No ack of file close from %d\n", studentNo);
        }
    }
    info("\nSendFile Done.\n");

}