Exemplo n.º 1
0
/*
-- FUNCTION: main
--
-- DATE: September 23, 2011
--
-- REVISIONS:
--
-- DESIGNER: Karl Castillo
--
-- PROGRAMMER: Karl Castillo
--
-- INTERFACE: int main(int argc, char** argv)
--				argc - number of arguments
--				argv - the arguments
--
-- RETURNS: int - 0
--
-- NOTES:
-- This is the main function where the arguments are parsed and proper 
-- preparations are done. These preparations include initializing sockets.
*/
int main(int argc, char** argv)
{
	char* ipAddr = 0;
	int option = 0;
	int controlSocket = 0;

	if(argc < 3) {
		fprintf(stderr, "Not Enough Arguments\n");
		fprintf(stderr, USAGE, argv[0]);
        exit(EXIT_FAILURE);
	}

	while((option = getopt(argc, argv, ":i:")) != -1)
    {
        switch(option)
        {
        case 'i':
            ipAddr = optarg;
            break;
        default:
            fprintf(stderr, USAGE, argv[0]);
            exit(EXIT_FAILURE);
        }
    }
    
	controlSocket = initConnection(DEF_PORT, ipAddr);
	processCommand(&controlSocket);

	return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    initConnection();
    
    char file_name[FILE_NAME_MAX_SIZE+1];
    bzero(file_name, FILE_NAME_MAX_SIZE+1);
    if (argc>1){
        strncpy(file_name,argv[1],strlen(argv[1]));
    }
    FILE *fp = NULL;
    if (ShakeHands(file_name, &fp)>0){
        printf("Sending...\n"); 
        fp = fopen(file_name, "rb");
        if (NULL == fp){
            printf("File:\t %s can not open to read.\n",file_name);exit(1);
        }
        struct timeval start,finish;
        gettimeofday(&start,NULL);
        Transfer(client_socket,server_addr, &fp);
        fclose(fp);
        gettimeofday(&finish,NULL);
        printf("Send File:\t %s To Server [%s] Finished.\n", file_name, IP);
        double duration = (double)((finish.tv_sec-start.tv_sec)*1000000.0+finish.tv_usec-start.tv_usec)/1000000.0;
        printf("Duration: %.3lf sec\n",duration);
    }
    
    return 0;
}
Exemplo n.º 3
0
GLC_QuickView::GLC_QuickView(QWindow *pParent)
    : QQuickView(pParent)
    , m_pContext(NULL)
    , m_pQOpenGLContext(NULL)
{
    initConnection();
}
Exemplo n.º 4
0
int main(int argc, char** argv)
{
   const char* path = "/etc/epgd/epg.dat";

   if (argc > 1)
      path = argv[1];

   // read deictionary

   dbDict.setFilterFromNameFct(toFieldFilter);

   if (dbDict.in(path, ffEpgd) != success)
   {
      tell(0, "Invalid dictionary configuration, aborting!");
      return 1;
   }

   dbDict.show();

   return 0;

   initConnection();

   // demoStatement();
   // joinDemo();
   // insertDemo();

   tell(0, "uuid: '%s'", getUniqueId());

   exitConnection();

   return 0;
}
Exemplo n.º 5
0
int request_usr(simple_person ** arr, int * size, int id,char * conect, tOPC opc)
{

	char opOK=0,qty_people=0;
	int full_size;
	clsvbuff buff;

	initConnection(TYPE_MSG_Q);

	buff.opc=opc;
	buff.id_client=id;
	write_info(&buff);
	read_info(&opOK,sizeof(char),buff.id_client);
	if(opOK==NOTOK)
	{
		return NOTOK;
	}
	read_info((char*)&qty_people,sizeof(char),buff.id_client);
	*size=qty_people;
	full_size=sizeof(simple_person) * (*size);

	if(full_size>0)
	{
		*arr=malloc(full_size);
		if(*arr==NULL)
			return NOTOK;
		read_info((char*) (*arr),full_size,buff.id_client);
	}

	return OK;
}
Exemplo n.º 6
0
TcpControl::TcpControl(QWidget *parent) :
    QWidget(parent)
{
    init();
    tcpSocket=new QTcpSocket(this);
    initConnection();
}
Exemplo n.º 7
0
int run(char *hostname)
{
    chdir("./dropbox/");    //change current directory because stat function is searching inside current directory only
    char *server_req = malloc(BUFFER_SIZE);
    if(server_req == NULL)
    {
        fprintf(stderr,"Cannot allocate %d bytes for buffer\n",BUFFER_SIZE);
        return 0;
    }
    int socket = 0;
    while(1)
    {
        if(initConnection(&socket,hostname))
        {
            if(!sync_(&socket,&server_req)) //sync was not successful
            {
                printf("Client will exit.\n");
                break;
            }
            close(socket);
        }
        else
            break;
        sleep(15); //sleep 15 seconds
    }
    free(server_req);
    return 1;
}
Exemplo n.º 8
0
int
runDaemon(int debug)
{
  char			packetPtr[PACKETLEN];
  size_t	       	packetSize;
  struct sockaddr_in	sa;

  if (checkOtherProcess())
    return (EXIT_FAILURE);
  signal(SIGTERM, sigHandler);
  signal(SIGINT, sigHandler);
  signal(SIGUSR1, sigHandler);

  if (!debug) {
    daemon(1, 1);
    if (savePid())
      return EXIT_FAILURE;
  }

  fprintf(stderr, "Daemon started\n");

  initConnection(&sa);
  while (1) {
    setClient(acceptClient(&sa));
    bzero(packetPtr, PACKETLEN);
    getPacket(packetPtr, &packetSize);
    handlePacket(packetPtr, packetSize);
    setClient(-1);
  }
  setSock(-1);
  return EXIT_SUCCESS;
}
Exemplo n.º 9
0
Random* Random::getInstance(){
	if(_SlaveRandom == 0){
		_SlaveRandom = new Random();

		initConnection();
	}
	return _SlaveRandom;
}
Exemplo n.º 10
0
void MRmiClient::invoke(const char* objectName, const char* method,
                          const QVariant& arg0)
{
    Q_D(MRmiClient);
    initConnection();
    d->stream() << (quint16)0 << (quint16)1 << objectName << method << arg0;
    finalizeConnection();
}
Exemplo n.º 11
0
void MaSslSocket::ioProc(int mask, int isPoolThread)
{
	if (mask & MPR_READABLE && !initialized) {
		if (initConnection() == 0) {
			initialized = 1;
		}
	}
	this->MprSocket::ioProc(mask, isPoolThread);
}
Exemplo n.º 12
0
BasicInfoRpt::BasicInfoRpt(QWidget* parent, const QString& title)
    : BaseStyleWidget(parent)
    , BaseReport()
{
    initUI(title);
    initModel();
    initConnection();
    selectOSInfo();
}
Exemplo n.º 13
0
int main(int argc, const char * argv[]) {
    
    int port;
    
    port = openSerialPort("/dev/tty....");
    initConnection(port);
    initListener();
    
    return 0;
}
Exemplo n.º 14
0
void MRmiClient::invoke(const char* objectName, const char* method)
{
    Q_D(MRmiClient);
    initConnection();

    /* packet is composed of |block size|argument length|arguments...| */
    d->stream() << (quint16)0 << (quint16)0 << objectName << method;

    finalizeConnection();
}
Exemplo n.º 15
0
ProcessListWidget::ProcessListWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::ProcessListWidget)
, itemModel()
{
    ui->setupUi(this);
    this->resize(540, 360);

    initTableView();
    initConnection();
    refreshTableItems();
}
Exemplo n.º 16
0
void MRmiClient::invoke(const char* objectName, const char* method,
                          const QVariant& arg0,   const QVariant& arg1,
                          const QVariant& arg2,   const QVariant& arg3,
                          const QVariant& arg4,   const QVariant& arg5,
                          const QVariant& arg6)
{
    Q_D(MRmiClient);
    initConnection();
    d->stream() << (quint16)0 << (quint16)7 << objectName << method << arg0
    << arg1 << arg2 << arg3 << arg4 << arg5 << arg6;
    finalizeConnection();
}
Exemplo n.º 17
0
int main(int argc, char **argv) {

  // 
  // Make sure we've been given a port to listen on.
  //
  if (argc != 2) {
    fprintf(stderr, "usage: %s <port>\n", argv[0]);
    exit(0);
  }
  
  arena_t *arena = newArena();
  int listener = initConnection(atoi(argv[1]));
  
  int clients = 0
  while (1) {
  	clients++;
  	
  //
  // Build a client's profile to send to a handler thread
  //
  client_t *client = (client_t *)malloc(sizeof(client_t));
  
  //
  // Accept a connection from a client, get a file descriptor for communicating
  // with the client
  //
  client->id = clients;
  int client = acceptClientOn(listener);
  }
  
  //
  // create a thread to handle the client
  //
  pthread_t tid;
  pthread_create(&tid,NULL,playSolitaire, (void *)client);

  unsigned long seed = 0;
  if (argc == 1) {
    struct timeval tp; 
    gettimeofday(&tp,NULL); 
    seed = tp.tv_sec;
  } else {
    seed = atol(argv[1]);
  }
  printf("Shuffling with seed %ld.\n",seed);
  srand48(seed);


  deck_t *deck = newDeck();
  shuffle(deck);
  playSolitaire(client);
}
Exemplo n.º 18
0
void Recorder::startRecording(QString hostname, quint16 port)
{
    qInfo() << "StartRecording!";

    if (constants::IS_NETWORKING)
    {
        initConnection(hostname, port);
    }
    else
    {
        startTimers();
    }
}
Exemplo n.º 19
0
void Server::incomingConnection( const qintptr socketHandle )
{
    QThread* workerThread = new QThread( this );
    ServerWorker* worker = new ServerWorker( socketHandle );

    worker->moveToThread( workerThread );

    connect( workerThread, SIGNAL( started( )),
             worker, SLOT( initConnection( )));
    connect( worker, SIGNAL( connectionClosed( )),
             workerThread, SLOT( quit( )));

    // Make sure the thread will be deleted
    connect( workerThread, SIGNAL( finished( )), worker, SLOT( deleteLater( )));
    connect( workerThread, SIGNAL( finished( )),
             workerThread, SLOT( deleteLater( )));

    // public signals/slots, forwarding from/to worker
    connect( worker, SIGNAL( registerToEvents( QString, bool,
                                               deflect::EventReceiver* )),
             this, SIGNAL( registerToEvents( QString, bool,
                                             deflect::EventReceiver* )));
    connect( this, SIGNAL( _pixelStreamerClosed( QString )),
             worker, SLOT( closeConnection( QString )));
    connect( this, SIGNAL( _eventRegistrationReply( QString, bool )),
             worker, SLOT( replyToEventRegistration( QString, bool )));

    // Commands
    connect( worker, SIGNAL( receivedCommand( QString, QString )),
             &_impl->commandHandler, SLOT( process( QString, QString )));

    // PixelStreamDispatcher
    connect( worker, SIGNAL( addStreamSource( QString, size_t )),
             &_impl->pixelStreamDispatcher, SLOT(addSource( QString, size_t )));
    connect( worker,
             SIGNAL( receivedSegement( QString, size_t, deflect::Segment )),
             &_impl->pixelStreamDispatcher,
             SLOT( processSegment( QString, size_t, deflect::Segment )));
    connect( worker,
             SIGNAL( receivedFrameFinished( QString, size_t )),
             &_impl->pixelStreamDispatcher,
             SLOT( processFrameFinished( QString, size_t )));
    connect( worker,
             SIGNAL( removeStreamSource( QString, size_t )),
             &_impl->pixelStreamDispatcher,
             SLOT( removeSource( QString, size_t )));

    workerThread->start();
}
Exemplo n.º 20
0
int log_usr(clsvbuff buff, char * connect)
{
	char ans;

	initConnection(TYPE_FIFO);

	write(fd_fifo,&buff,sizeof(clsvbuff));
	while(!serv_read);//while the server not has read the fifo.
	serv_read=false;
	read(fd_fifo,&ans,sizeof(char));
	kill(pid_serv,SIG_CLI_READ);

	close(fd_fifo);
	return ans;
}
Exemplo n.º 21
0
void PostgreChartProvider::initialize(QString host,
                                      uint port,
                                      QString dbname,
                                      QString username,
                                      QString password,
                                      int detailLevel)
{
    dbHost = host;
    dbPort = port;
    dbName = dbname;
    dbUser = username;
    dbPass = password;
    this->detailLevel = detailLevel;
    initConnection();
}
Exemplo n.º 22
0
int register_usr(clsvbuff buff, int * rta,char * connect)
{
	char opOk=0;

	initConnection(TYPE_FIFO);

	write(fd_fifo,&buff,sizeof(clsvbuff));
	while(!serv_read);//while the server not has read the fifo.
	serv_read=false;
	read(fd_fifo,&opOk,sizeof(char));
	read(fd_fifo,rta,sizeof(int));
	kill(pid_serv,SIG_CLI_READ);

	close(fd_fifo);
	return opOk;
}
Exemplo n.º 23
0
ProcessInfoForm::ProcessInfoForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ProcessInfoForm),
    mItemModel(),
    mMenu(NULL),
    mProcessInfo(NULL),
    mCurProcess()
{
    ui->setupUi(this);

    mProcessInfo = SystemInfoProvider::getInstance()->getProcessInfo();

    ui->rdoAllProcess->setChecked(true);
    initTableView();
    initConnection();
    refreshViews();
}
Exemplo n.º 24
0
int get_person(person *p,int person_id,int src_id,char * conect)
{
	char opOK=0;
	clsvbuff buff;

	initConnection(TYPE_MSG_Q);

	buff.opc=GET_INFO;
	buff.id_client=src_id;
	buff.data.clsv_get_info.id=person_id;

	write_info(&buff);

	read_info(&opOK, sizeof(char), buff.id_client);
	read_info((char *)p, sizeof(person), buff.id_client);

	return opOK;
}
Exemplo n.º 25
0
void StationInfoDialog::showEvent(QShowEvent *event)
{
    //Put the dialog in the screen center
    const QRect screen = QApplication::desktop()->screenGeometry();
    this->move( screen.center() - this->rect().center() );
    ui->checkBox_connectionChanged->setChecked(false);

    ui->label_activeSensor->setText("no sensor connected");
    this->setWindowTitle(QString("information abaout " + OiFeatureState::getActiveFeature()->getFeature()->getFeatureName()));
    if(OiFeatureState::getActiveFeature()->getStation() != NULL && OiFeatureState::getActiveFeature()->getStation()->sensorPad->instrument != NULL){
        ui->label_activeSensor->setText(OiFeatureState::getActiveFeature()->getStation()->sensorPad->instrument->getMetaData()->name);
        ui->lineEdit_configName->setText(OiFeatureState::getActiveFeature()->getStation()->getInstrumentConfig()->name);
        getReadingType();
        getSensorConfiguration();
        getSensorParameters();
        initConnection();
    }

    event->accept();
}
Exemplo n.º 26
0
int evaluate(boolean * match,boolean opinion,int person_id, int src_id,char * conect)
{
	char opOK=0;
	clsvbuff buff;

	initConnection(TYPE_MSG_Q);

	buff.id_client=src_id;
	buff.opc=EVALUATION;
	buff.data.clsv_evaluation.id=person_id;
	buff.data.clsv_evaluation.like=opinion;

	write_info(&buff);

	read_info(&opOK, sizeof(char), buff.id_client);
	read_info((char *)match, sizeof(boolean), buff.id_client);
	if(opOK==NOTOK)
		return NOTOK;
	return OK;
}
Exemplo n.º 27
0
int init(int argc, char **args) {

    puts("Start Server...");
    char *port;
    puts("Parse Arguments from console...");
    if (parseArguments(argc, args, &port) == EXIT_FAILURE)
        return EXIT_FAILURE;

    puts("Initiating connection...");
    if (initConnection(port) == EXIT_FAILURE)
        return EXIT_FAILURE;
        
    if (initPoll() == EXIT_FAILURE) {
        return EXIT_FAILURE;
    }
    
    clientList = clientVector_construct(8);
    printf("Gnuddels-Server started on the port %s!\n", port);

    return EXIT_SUCCESS;
}
Exemplo n.º 28
0
TextEditer::TextEditer(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TextEditer)
{
    ui->setupUi(this);
	initMenu();
	initToolBar();
	initCenterWidget();
	initStatusBar();
	initLocSize();
	initConnection();

	textEdit->setFont(QFont("FreeMono", 10));	/* 默认字体 */
	textEdit->setTabStopWidth(40);	/* Tab键跳格参数, 系统默认为80, 修改为40 */

	isUntitled = true;	/* 新文件未命名 */
	isSaved = false;	/* 新文件未保存 */
	curFile = "";
	hasFile = false;	/* 没有文件打开 */
	setWindowTitle(tr("TextEditer"));
}
Exemplo n.º 29
0
int main(int argc, char *argv[])
{
    initConnection();
    for(;;)
    {
        char message[BUFFER_SIZE];
        FILE *fp = NULL;
        int req_num = 0;
        req_num = WaitShakeHands(message, &fp);
        // req_num 对应请求的dataID:1表示下载,2表示显示目录,3表示上传。若req_num<0,则无须后续传输。
        if ( req_num==1 )
        {
            Packet req;
            Recvfrom(server_socket, (char *)&req, sizeof(Packet),0, (struct sockaddr *)&client_addr, &clen);
            if ( req.dataID == 0 && req.flag ==-1)
                Transfer(server_socket, client_addr,&fp);
        }
        else if (req_num == 2)
        {
            Packet req;
            Recvfrom(server_socket, (char *)&req, sizeof(Packet),0, (struct sockaddr *)&client_addr, &clen);
            if ( req.dataID == 0 && req.flag ==-1)
                Show_dir(server_socket, client_addr);
        }
        else if (req_num == 3)
        {
            char file_name[BUFFER_SIZE],md5sum[33]={'\0'};
            int filesize;
            sscanf(message,"%s\t%d\t%s",file_name,&filesize,md5sum);
            fp = fopen(file_name, "wb");
            if (NULL == fp){
                printf("File:\t %s can not open to write.\n",file_name);exit(1);}
            printf("Begin Recvfile.\n");
            FileReceive(server_socket, client_addr,&fp);
            fclose(fp);
        }
        printf("Finished.\n");
    }
    return 0;
}
Exemplo n.º 30
0
int main(int argc, char *argv[]) {
	logger = log_create("MaRTA.log", "MaRTA", 1, log_level_from_string("TRACE"));
	cantJobs = 0;
	if (argc != 2) {
		log_error(logger, "Missing config file");
		freeMaRTA();
		return EXIT_FAILURE;
	}
	if (!initConfig(argv[1])) {
		log_error(logger, "Config failed");
		freeMaRTA();
		return EXIT_FAILURE;
	}

	nodes = list_create();
	signal(SIGINT, freeMaRTA);

	initConnection();

	list_destroy_and_destroy_elements(nodes, (void *) freeNode);
	freeMaRTA();
	return EXIT_SUCCESS;
}