Exemplo n.º 1
0
int mainprog(void)
{
	int res=0;
	/* Initialisation des listes */
	InitChListe(&PLCs);

	res=OpenDb(DBHOST,USER,PASS,DB);
	if (res<0) {Log(LOG_CRIT,"OpenDb (%d) : %s\n",res,MysqlErrorMsg);return(res);}
	else
	{
		Plc_count=GetPlcList(NULL,&CONTROLLERs);
		if (Plc_count<0) Log(LOG_CRIT,"Get Plc count error (%d) : %s\n",Plc_count,MysqlErrorMsg);
			else
			{
				if (Plc_count==0) Log(LOG_NOTICE,"There is no Plcs\n");
					else Log(LOG_NOTICE,"There is : %d Plcs\n",Plc_count);
			}
		Tag_count=GetCount("select * from DEFINITION");
		if (Tag_count<0) Log(LOG_CRIT,"Get Tag count error (%d) : %s\n",Tag_count,MysqlErrorMsg);
			else
			{
				if (Tag_count==0) Log(LOG_NOTICE,"There is no Tags\n");
					else Log(LOG_NOTICE,"There is : %d Tags\n",Tag_count);
			}
		if ((Plc_count>0)&&(Tag_count>0))
		{
			Tag_count=0;
			Plc_count=GetPlcList(&PLCs,&CONTROLLERs);
			if (PLCs.Count>0)
			{
				Log(LOG_NOTICE,"There is %d PLC to create\n",PLCs.Count);
				ELEMENT *elt=GetFirst(&PLCs);
				while (elt!=NULL)
				{
					PLC *plc=elt->Data;
					res=GetTag(plc);
					if (res>0) Tag_count+=res;
					else
						{
							if (res==0) Log(LOG_NOTICE,"(%s) there is no Tag for PLC : %s\n",MysqlErrorMsg,plc->PlcName);
								else Log(LOG_CRIT,"Get Tag error (%d) : %s for PLC : %s\n",res,MysqlErrorMsg,plc->PlcName);
						}
					Optimise(plc);
					elt=GetNext(&PLCs,elt);
				}
			} else Log(LOG_CRIT,"Get Plc error (%d) : %s\n",res,MysqlErrorMsg);
			// Appel Logger
			if (Tag_count>0) res=Logger(&PLCs);
		} else Log(LOG_WARNING,"There is nothing to do. exiting...\n");
		CloseDb;
	}
	return(res);
}
// -----------------------------------------------------------------------------
// CUpnpSecurityDbConnection::OpenDatabaseL
// Prepare database for use, create new if not exist.
// -----------------------------------------------------------------------------
//
void CUpnpSecurityDbConnection::OpenDatabaseL()
    {
    EnsureDiskSpaceL();

    if ( OpenDb( iDbFileName ) != KErrNone )
        {
        User::LeaveIfError( CreateDbFile( iDbFileName ) );
        }

    if ( !Validate() )
        {
        CreateTablesL();
        }
    }
Exemplo n.º 3
0
int SM_Manager::ShowDb() {
	CloseDb();
	if (OpenDb(DataName) != 0)
		return -1;
	rmm.OpenFile("tablelist", tablefh);
	RM_FileScan rfs = RM_FileScan(rmm.getFileManager(), rmm.getBufPageManager());
	 RM_Record rec;
	rfs.OpenScan(tablefh, STRING, 0, 0, NO_OP, NULL);
	cout << "----- begin -----" << endl;
	while (rfs.GetNextRec(rec) != -1) {
		cout << rec.rid << " , " << rec.data << endl;
	}
	cout << "----- end -----" << endl;
	rmm.CloseFile(tablefh);
	return 0;
}
Exemplo n.º 4
0
int cmdline_main(int argc,char *argv[])
{
  QApplication a(argc,argv,false);
  
  //
  // Load Configs
  //
  admin_config=new MldConfig();
  admin_config->load();

  //
  // Open Database
  //
  if(!OpenDb(admin_config->mysqlDbname(),admin_config->mysqlUsername(),
	     admin_config->mysqlPassword(),admin_config->mysqlHostname(),
	     false)) {
    return 1;
  }

  return 0;
}
Exemplo n.º 5
0
int SM_Manager::Exec(const char *instr) {
	vector<string> argv;
	string cur;
	cout << instr << endl;
	for (int i = 0; ; i++) {
		if (instr[i] == ' ' || instr[i] == '(' || instr[i] == ')' || instr[i] == ',' || instr[i] == 0) {
			if (cur.length() > 0) {
				argv.push_back(cur);
				cur = "";
			}
			if (instr[i] == 0){
				break;
			}
		}
		else {
			cur = cur + instr[i];
		}
	}
	if (argv.size() < 3)
		return -1;
	if (argv[0] == "CREATE" && argv[1] =="DATABASE") {
		CreateDb(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "DROP" && argv[1] == "DATABASE") {
		DropDb(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "USE" && argv[1] == "DATABASE") {
		CloseDb();
		OpenDb(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "SHOW" && argv[1] == "DATABASE") {
		ShowDb(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "CREATE" && argv[1] == "TABLE") {
		string tablename = argv[2];
		vector<AttrInfo> attrs;
		for (int i = 3; i < argv.size();) {
			AttrInfo attr;
			if (argv[i] == "PRIMARY" && argv[i + 1] == "KEY") {
				attr.primaryKey = true;
				i += 2;
			}
			cout << argv[i] << endl;
			strcpy(attr.attrName, argv[i].c_str());
			i += 1;
			if (argv[i] == "int") {
				attr.attrType = MyINT;
				attr.attrLength = 4;
				i += 1;
				cout << "lala" << endl;
			} else if (argv[i] == "float") {
				attr.attrType = FLOAT;
				attr.attrLength = 4;
				i += 1;
			} else if (argv[i] == "char") {
				attr.attrType = STRING;
				attr.attrLength = atoi(argv[i + 1].c_str());
				i += 2;
			}
			if (i + 1 < argv.size() && argv[i] == "NOT" && argv[i + 1] == "NULL") {
				attr.notNull = true;
				i += 2;
			}
			attrs.push_back(attr);
		}
		AttrInfo *x = new AttrInfo[attrs.size()];
		for (int i = 0; i < attrs.size(); i++)
			x[i] = attrs[i];
		CreateTable(tablename.c_str(), attrs.size(), x);
		delete x;
		return 0;
	}
	if (argv[0] == "DROP" && argv[1] == "TABLE") {
		DropTable(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "SHOW" && argv[1] == "TABLE") {
		ShowTable(argv[2].c_str());
		return 0;
	}
	return 0;
}
Exemplo n.º 6
0
int mainprog(void)
{	int res=0,return_len;
	TMxMsg *msg=NULL,*msg5=NULL,*msg6=NULL;
	int nfds;
	fd_set rfds, afds;
	struct timeval to;

	nfds = getdtablesize();
	FD_ZERO(&afds);
	FD_SET(MXsock, &afds);

	res=OpenDb(DBHOST,USER,PASS,DB);
	if (res<0) {Log(LOG_CRIT,"OpenDb (%d) : %s\n",res,MysqlErrorMsg);return(res);}
	else
	{
		res=BuildTags(&Tags);
		if (res<=0)
		{
			Log(LOG_WARNING,"Nothing to do\n");
			Terminated=1;
		} else
		{
			int i;
			TAGSimplex *Tag;
			for(i=0;i<Tags.Count;i++)
			{
				Tag=Tags.Data[i];
				Log(LOG_DEBUG,"%d : %s adresse : %d (%d)\n",i,Tag->TagName,Tag->Address,Tag->Bobine);
			}
		}
		//Terminated=1;
		bzero(&mybuffer,sizeof(mybuffer));
		while (!Terminated)
		{
			if (MXsock<0)
			{
				Log(LOG_INFO,"Attempting reconnection (%d connections lost)\n",connlost);
				MXsock=OpenSock(MXADDRESS,MXPORT);
				if (MXsock>=0)
				{
					Log(LOG_NOTICE,"Reconnection OK\n");
				}else
				{
					sleep(WAITTORECONNECT);
					Log(LOG_NOTICE,"Waiting before attempting reconnection (connections retries %d)\n",++connretries);
					continue;
				};
			}
			memcpy(&rfds, &afds, sizeof(rfds));
			to.tv_sec=UPDATERATE;
			to.tv_usec=0;
			switch (select(nfds, &rfds, 0, 0,&to))
			{
				case -1:if(errno == EINTR) continue;
					else Log(LOG_WARNING,"surveillance des descripteurs\n");
				case 0:	continue; // timeout
				default:
					if( FD_ISSET(MXsock, &rfds) )
					{
						return_len=read(MXsock,&inbuf,sizeof(inbuf));
						Log(LOG_DEBUG,"Recu  : %d\n",return_len);
						if (return_len>0)
						{	Addbuffer(&mybuffer,&inbuf,return_len);
							Log(LOG_DEBUG,"Com recu : %d buffersize =%d\n",return_len,mybuffer.Size);
							if (MsgInBuffer(&mybuffer)==0) // get a message
							{	if (CheckMsgOk(&mybuffer)==0) // Message well formatted
								{
									Log(LOG_DEBUG,"Entering DecodeBubber\n");
									msg=DecodeBuffer(&mybuffer);
									/*   */
									Affiche(msg);
									switch (msg->Funct)
									{
										case 3:
											Update(&Tags,msg);
											free(msg);
											break;
										case 4:
											switch (msg->SubFunct)
											{
												case 5:
												case 6:
													if ((msg->SubFunct==5)&&(msg5!=NULL))
													{
														Log(LOG_WARNING,"Reliquat de bobine\n");
														InsBobine(&Tags,msg5,msg6);
														if (msg5!=NULL) {free(msg5);msg5=NULL;};
														if (msg6!=NULL) {free(msg6);msg6=NULL;};
													}
													if (msg->SubFunct==5) msg5=msg;
													if (msg->SubFunct==6) msg6=msg;
													if ((msg5!=NULL)&&(msg6!=NULL))
													{
														Log(LOG_INFO,"Recu bobine\n");
														InsBobine(&Tags,msg5,msg6);
														if (msg5!=NULL) {free(msg5);msg5=NULL;};
														if (msg6!=NULL) {free(msg6);msg6=NULL;};
													}
													break;
												default:
													free(msg);
													break;
											}
											break;
										default:
											free(msg);
											break;
									}
									bzero(&mybuffer,sizeof(mybuffer));
									msg_ACK++;
									Log (LOG_INFO,"Msg recu OK : %d\n",msg_ACK);
								}else
								{
									bzero(&mybuffer,sizeof(mybuffer));
									Reply(MXsock,NAK);
									Log (LOG_NOTICE,"Msg recu mauvais: %d\n",msg_NACK++);
								}
							}else
							{ /* Erreur ?? */
								if (mybuffer.Size>=BufferMaxSize)
								{
									Log(LOG_WARNING,"******** Buffer sature ************\n");
									bzero(&mybuffer,sizeof(mybuffer));
								}
							}
						} else
						{
							close(MXsock);
							FD_CLR(MXsock,&afds);
							MXsock=-1;
							Log(LOG_WARNING,"Server connection lost !\n");
							continue;
						}
					}
			}
		}
		return(0);
		CloseDb;
	}
}
Exemplo n.º 7
0
MainWidget::MainWidget(QWidget *parent,const char *name)
  :QWidget(parent,name)
{
  QString sql;
  QSqlQuery *q;

  //
  // Fix the Window Size
  //
  setMinimumWidth(sizeHint().width());
  setMaximumWidth(sizeHint().width());
  setMinimumHeight(sizeHint().height());
  setMaximumHeight(sizeHint().height());

  //
  // Create Fonts
  //
  QFont font=QFont("Helvetica",12,QFont::Bold);
  font.setPixelSize(12);
  QFont default_font("Helvetica",12,QFont::Normal);
  default_font.setPixelSize(12);
  QFont title_font=QFont("Helvetica",16,QFont::Bold);
  title_font.setPixelSize(16);
  qApp->setFont(default_font);

  //
  // Create And Set Icon
  //
  mdb_callcommander_map=new QPixmap(callcommander_xpm);
  setIcon(*mdb_callcommander_map);

  //
  // Reload Socket
  //
  admin_reload_socket=new Q3SocketDevice(Q3SocketDevice::Datagram);

  //
  // Load Configs
  //
  admin_config=new MldConfig();
  admin_config->load();

  //
  // Open Database
  //

  /*
  QStringList drivers=QSqlDatabase::drivers();
  for(unsigned i=0;i<drivers.size();i++) {
      QMessageBox::information(this,"DRIVERS",drivers[i]);
  }
  */
  OpenDb(admin_config->mysqlDbname(),admin_config->mysqlUsername(),
	 admin_config->mysqlPassword(),admin_config->mysqlHostname(),true);

  //
  // Log In
  //
  QString password;
  Login *login=new Login(&admin_loginname,&password,true,this);
  if(login->exec()!=0) {
    exit(0);
  }
  sql=QString("select LOGIN_NAME from USERS where ")+
    "(LOGIN_NAME=\""+EscapeString(admin_loginname)+"\")&&"+
    "(PASSWORD=\""+EscapeString(password)+"\")";
  q=new QSqlQuery(sql);
  if(q->size()<=0) {
    QMessageBox::information(this,"Login Failed","Invalid Login!");
    exiting=true;
    delete q;
  }
  else {
    delete q;
    sql=
      QString().sprintf("select ADMIN_PRIV from USERS where LOGIN_NAME=\"%s\"",
			(const char *)admin_loginname);
    q=new QSqlQuery(sql);
    q->first();
    if(q->value(0).toString().lower()!="y") {
      QMessageBox::information(this,"Login Failed",
		      "This user does not have \nadministrative permissions!");
      exiting=true;
    }
    delete q;
    setCaption(QString().sprintf("Call Administrator - User: %s",
				 (const char *)admin_loginname));
  }

  //
  // Title
  //
  QLabel *label=new QLabel("CallCommander",this,"main_title_label");
  label->setGeometry(10,5,sizeHint().width()-20,20);
  label->setFont(title_font);
  label->setAlignment(Qt::AlignCenter);

  label=new QLabel("Database Administrator",this,"sub_title_label");
  label->setGeometry(10,25,sizeHint().width()-20,20);
  label->setFont(default_font);
  label->setAlignment(Qt::AlignCenter);

  //
  // Manage Users Button
  //
  QPushButton *button=new QPushButton(this,"users_button");
  button->setGeometry(10,50,120,60);
  button->setFont(font);
  button->setText("Manage\n&Users");
  connect(button,SIGNAL(clicked()),this,SLOT(manageUsersData()));

  //
  // Manage Shows Button
  //
  button=new QPushButton(this,"shows_button");
  button->setGeometry(150,50,120,60);
  button->setFont(font);
  button->setText("Manage\n&Shows");
  connect(button,SIGNAL(clicked()),this,SLOT(manageShowsData()));

  //
  // Manage Directory Button
  //
  button=new QPushButton(this,"directory_button");
  button->setGeometry(10,120,120,60);
  button->setFont(font);
  button->setText("Manage\n&Directory");
  connect(button,SIGNAL(clicked()),this,SLOT(manageDirectoryData()));

  //
  // CallerID Source Button
  //
  button=new QPushButton(this,"callerid_button");
  button->setGeometry(150,120,120,60);
  button->setFont(font);
  button->setText("Manage &CallerID\nSources");
  connect(button,SIGNAL(clicked()),this,SLOT(manageCallerIdData()));

  //
  // Manage Virtual Systems Vutton
  //
  button=new QPushButton(this,"virtual_button");
  button->setGeometry(10,190,120,60);
  button->setFont(font);
  button->setText("Manage &Virtual\nSystems");
  connect(button,SIGNAL(clicked()),this,SLOT(manageVirtualData()));

  //
  // Logic Modules Button
  //
  button=new QPushButton(this,"logic_modules_button");
  button->setGeometry(150,190,120,60);
  button->setFont(font);
  button->setText("Manage &Logic\nModules");
  connect(button,SIGNAL(clicked()),this,SLOT(manageLogicModuleData()));

  //
  // System Info Button
  //
  button=new QPushButton(this,"sysinfo_button");
  button->setGeometry(80,260,120,60);
  button->setFont(font);
  button->setText("System\n&Info");
  connect(button,SIGNAL(clicked()),this,SLOT(showInfoData()));

  //
  // Quit Button
  //
  button=new QPushButton(this,"quit_button");
  button->setGeometry(10,sizeHint().height()-70,sizeHint().width()-20,60);
  button->setFont(font);
  button->setText("&Quit");
  connect(button,SIGNAL(clicked()),this,SLOT(quitMainWidget()));
}
Exemplo n.º 8
0
MainObject::MainObject(QObject *parent,const char *name)
  : QObject(parent,name)
{
  std::vector<QString> group_names;
  std::vector<QString> bad_cuts;
  QString sql;
  RDSqlQuery *q;
  
  //
  // Read Command Options
  //
  RDCmdSwitch *cmd=
    new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdcheckcuts",RDCHECKCUTS_USAGE);
  for(unsigned i=0;i<cmd->keys();i++) {
    if(cmd->key(i)=="--group") {
      group_names.push_back(cmd->value(i));
      cmd->setProcessed(i,true);
    }
  }
  if(!cmd->allProcessed()) {
    fprintf(stderr,"rdcheckcuts: unknown option\n");
    exit(256);
  }

  //
  // Open Configuration
  //
  cut_config=new RDConfig();
  cut_config->load();

  //
  // Open Database
  //
  if(!OpenDb()) {
    fprintf(stderr,"rdcheckcuts: unable to open database\n");
    exit(256);
  }

  //
  // Build Group List
  //
  if(group_names.size()==0) {
    sql="select NAME from GROUPS order by NAME";
    q=new RDSqlQuery(sql);
    while(q->next()) {
      group_names.push_back(q->value(0).toString());
    }
    delete q;
  }

  //
  // Scan Cuts
  //
  for(unsigned i=0;i<group_names.size();i++) {
    ValidateGroup(group_names[i],&bad_cuts);
  }

  //
  // Render Output
  //
  for(unsigned i=0;i<bad_cuts.size();i++) {
    RenderCut(bad_cuts[i]);
  }

  exit(0);
}