Example #1
0
rfbBool VeyonCoreConnection::handleVeyonMessage( rfbClient* client, rfbServerToClientMsg* msg )
{
	auto coreConnection = (VeyonCoreConnection *) rfbClientGetClientData( client, VeyonCoreConnectionTag );
	if( coreConnection )
	{
		return coreConnection->handleServerMessage( client, msg->type );
	}

	return false;
}
Example #2
0
void IRCServer::readData()
{
    while (socket_m->canReadLine())
    {
        QByteArray messageInRawText = socket_m->readLine();
        Message message = MessageParser::receivedRawTextToMessage(messageInRawText);

        emit messageReceived(message);

        if (message.isServerMessage())
            handleServerMessage(message);
        else if (message.isChannelMessage())
            handleChannelMessage(message);
    }
}
Example #3
0
// Constructor
MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine)
    :
      QMainWindow(parent),
      m_posInitialized(false),
      force_exit(false),
      icon_TrayConn(res::trayConnected()),
      icon_TrayDisconn(res::trayDisconnected()),
      icon_CurTray(icon_TrayDisconn)
{
    setupUi(this);
    stackedWidget->addWidget(new transfers_widget(this));
    stackedWidget->addWidget(new search_widget(this));
    stackedWidget->addWidget(new preferences_widget(this));
    stackedWidget->setCurrentIndex(0);
    setWindowTitle(tr("qDonkey %1").arg(misc::versionString()));
    QCoreApplication::instance()->installEventFilter(this);

    //QApplication::setOverrideCursor(Qt::WaitCursor);
    m_last_file_error = QDateTime::currentDateTime().addSecs(-1); // imagine last file error event was 1 seconds in past

#ifdef Q_WS_WIN
    m_nTaskbarButtonCreated = RegisterWindowMessage(L"TaskbarButtonCreated");
#else
    m_nTaskbarButtonCreated = 0;
#endif

    Preferences pref;

    // Clean exit on log out
    connect(static_cast<SessionApplication*>(qApp), SIGNAL(sessionIsShuttingDown()), this, SLOT(deleteSession()));

    this->setWindowIcon(QIcon(res::favicon()));

#ifdef Q_WS_MAC
    connect(static_cast<QMacApplication*>(qApp), SIGNAL(newFileOpenMacEvent(QString)), this, SLOT(processParams(QString)));
#endif

    statusBar = new status_bar(this, QMainWindow::statusBar());
    m_pwr = new PowerManagement(this);

    // Configure session according to options
    loadPreferences(false);

    // Start connection checking timer
    guiUpdater = new QTimer(this);
    connect(guiUpdater, SIGNAL(timeout()), this, SLOT(updateGUI()));
    guiUpdater->start(2000);

    // Accept drag 'n drops
    //setAcceptDrops(true);
    createKeyboardShortcuts();

#ifdef Q_WS_MAC
    setUnifiedTitleAndToolBarOnMac(true);
#endif

    // View settings



    // Auto shutdown actions
/*    QActionGroup * autoShutdownGroup = new QActionGroup(this);
    autoShutdownGroup->setExclusive(true);
    autoShutdownGroup->addAction(actionAutoShutdown_Disabled);
    autoShutdownGroup->addAction(actionAutoExit_mule);
    autoShutdownGroup->addAction(actionAutoShutdown_system);
    autoShutdownGroup->addAction(actionAutoSuspend_system);

#if !defined(Q_WS_X11) || defined(QT_DBUS_LIB)
    actionAutoShutdown_system->setChecked(pref.shutdownWhenDownloadsComplete());
    actionAutoSuspend_system->setChecked(pref.suspendWhenDownloadsComplete());
#else
    actionAutoShutdown_system->setDisabled(true);
    actionAutoSuspend_system->setDisabled(true);
#endif

    actionAutoExit_mule->setChecked(pref.shutdownqBTWhenDownloadsComplete());

    if (!autoShutdownGroup->checkedAction())
        actionAutoShutdown_Disabled->setChecked(true);
*/

    readSettings();

    show();
    activateWindow();
    raise();

    // Start watching the executable for updates
    executable_watcher = new QFileSystemWatcher();
    connect(executable_watcher, SIGNAL(fileChanged(QString)), this, SLOT(notifyOfUpdate(QString)));
    executable_watcher->addPath(qApp->applicationFilePath());

    // Add torrent given on command line
    processParams(torrentCmdLine);
#ifdef Q_WS_MAC
    //qt_mac_set_dock_menu(icon_CurTray);
#endif

    // Make sure the Window is visible if we don't have a tray icon
    if (!systrayIcon && isHidden())  {
        show();
        activateWindow();
        raise();
    }

    connect(Session::instance(), SIGNAL(serverNameResolved(QString)), this, SLOT(handleServerNameResolved(QString)));
    connect(Session::instance(), SIGNAL(serverConnectionInitialized(quint32,quint32,quint32)), this, SLOT(handleServerConnectionInitialized(quint32,quint32,quint32)));
    connect(Session::instance(), SIGNAL(serverConnectionClosed(QString)), this, SLOT(handleServerConnectionClosed(QString)));
    connect(Session::instance(), SIGNAL(serverStatus(int,int)), this, SLOT(handleServerStatus(int,int)));
    connect(Session::instance(), SIGNAL(serverMessage(QString)), this, SLOT(handleServerMessage(QString)));
    connect(Session::instance(), SIGNAL(serverIdentity(QString,QString)), this, SLOT(handleServerIdentity(QString,QString)));

    connect(Session::instance(), SIGNAL(transferAdded(QED2KHandle)), SLOT(addedTransfer(QED2KHandle)));
    connect(Session::instance(), SIGNAL(transferFinished(QED2KHandle)), SLOT(finishedTransfer(QED2KHandle)));

    //Tray actions.
    //connect(actionToggleVisibility, SIGNAL(triggered()), this, SLOT(toggleVisibility()));
    //connect(actionStart_All, SIGNAL(triggered()), Session::instance(), SLOT(resumeAllTransfers()));
    //connect(actionPause_All, SIGNAL(triggered()), Session::instance(), SLOT(pauseAllTransfers()));

    actionConnect->trigger();
    Session::instance()->loadDirectory(pref.inputDir());
}
int main(int argc, char *argv[])
{
   int sockfd, portno, n, count = 0;
   struct sockaddr_in serv_addr;
   struct hostent *server;
   char config[50];
   char gipaddress[50], gport[5], *gtoken;
   //char item_type[15], sipaddress[50], sport[5], sarea[5];
   //char input[50] = "./SensorInputFile.txt";
   char *itoken, *stoken;
   int  starttime, endtime, value;
   char buffer[256];
   char *reg, *currvalue;
   //char inputfilename[] = "./";
   char input[50];

   strcpy(config, argv[1]);
   strcpy(input, argv[2]);
   //strcpy(input, strcat(inputfilename, input));
   
   /* Reading configuration file*/
   cfile = fopen (config,"r");
   if (cfile == NULL) {
	perror("ERROR opening config file ");
	exit(1);
   }   
   
   while ( fgets (config_read , 100 , cfile) != NULL ) {
       	//printf("Config file: %s\n", config_read);
	if(count == 0) {
	   /* Tokening the stream on :*/
	        gtoken =  strtok(config_read, ":");
		//for(int i=0;i<2;i++){
	       	//while (token != NULL){
	        //printf("Token1: %s\n", gtoken);
		strcpy(gipaddress, gtoken);
		gtoken = strtok(NULL, ":");
		//printf("Token2: %s\n", gtoken);
		strcpy(gport, gtoken);
		gtoken = strtok(NULL, ":");
		count++;
	}
	else if(count ==1) {
		stoken = strtok(config_read, ":");
		//printf("Token3: %s\n", stoken);
		strcpy(item_type, stoken);
		stoken = strtok(NULL, ":");
		//printf("Token4: %s\n", stoken);
                strcpy(sipaddress, stoken);
                stoken = strtok(NULL, ":");
		//printf("Token5: %s\n", stoken);
                strcpy(sport, stoken);
                stoken = strtok(NULL, ":");
		//printf("Token6: %s\n", stoken);
                strcpy(sarea, stoken);
                stoken = strtok(NULL, ":");
	}
	
   }
   
   //printf("Gateway IP: %s\n", gipaddress);
   //printf("Gateway port %s\n", gport);
   //printf("Token3 %s\n", item_type);
   //printf("Token4 %s\n", sipaddress);
   //printf("Token5 %s\n", sport);
   //printf("Token6 %s\n", sarea);

   fclose(cfile);
  
   /* Reading configuration file*/
   ifile = fopen (input,"r");
   if (ifile == NULL) {
        perror("ERROR opening config file ");
        exit(1);
   }

   /*while ( fgets (input_read , 100 , ifile) != NULL ) {
        printf("Input file: %s", input_read);
   }
   
   
   if (argc <3) {
      fprintf(stderr,"usage %s hostname port\n", argv[0]);
      exit(0);
   }
   */

   //fclose(ifile);   

   /* Prepare register request*/
   reg = prepareMessage(0, NULL);
   //printf("Prepare message: %s\n",reg);
   

   portno = atoi(gport);
   
   /* Create a socket point */
   sockfd = socket(AF_INET, SOCK_STREAM, 0);
   
   if (sockfd < 0)
   {
      perror("ERROR opening socket");
      exit(1);
   }
   server = gethostbyname(gipaddress);
   
   if (server == NULL) {
      fprintf(stderr,"ERROR, no such host\n");
      exit(0);
   }
   
   bzero((char *) &serv_addr, sizeof(serv_addr));
   serv_addr.sin_family = AF_INET;
   bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
   serv_addr.sin_port = htons(portno);
   
   /* Now connect to the server */
   if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
   {
      perror("ERROR connecting");
      exit(1);
   }
   
   /* Now ask for a message from the user, this message
   * will be read by server
   */
   while(1) {
   	//printf("Please enter the message: ");
	  bzero(buffer,256);
	   //fgets(buffer,255,stdin);
	   //printf("Message: %s\n", reg);
	   strcpy(buffer, reg);
   
	   /* Send message to the server */
	   if (state == 1) {
		   n = write(sockfd, buffer, strlen(buffer));
	   }
   
	   if (n < 0)
	   {
	      perror("ERROR writing to socket");
	      exit(1);
	   }
   
	   /* Now read server response */
	   bzero(buffer,256);
	   n = read(sockfd, buffer, 255);
   
	   if (n < 0)
	   {
	      perror("ERROR reading from socket");
	      exit(1);
	   } else {
		   handleServerMessage(buffer);
	   }
	   //printf("printing buffer: %s\n",buffer);
	   sleep(interval);

	   // Prepare Message
	   reg = NULL;
	   char temp[10];
	   strcpy(temp,fetchValue());
	   //printf("Temp: %s\n", temp);
	   reg = prepareMessage(2, temp);
	   timeCounter = timeCounter + interval;
	   printf("CurrValue Message: %s\n",reg);
	   }
  
	   bzero(buffer,256); 
   
   return 0;
}