Пример #1
0
DWORD WINAPI Server::ClientThread(LPVOID lpParam) //(insert to DEQUE) use MUTEX
{
	Singleton* log = Singleton::Instance();
	log->Add("Thread: Client runing");

	SOCKET sock = (SOCKET)lpParam; //Get socket

	while(f)
	{
		//recv DATA, create STRUCTURE and (insert to DEQUE)MUTEX
		//Send will be in APPLY THREAD
		if ( recv(sock,rdata.ch,sizeof(DWORD),0) != -1 ) //Wait data //save data to union
		{
			Message tmp;
			tmp.s = sock;
			tmp.data = rdata.i;

			WaitForSingleObject(hMutex,INFINITE);
			deque_data.push_back(tmp);
			ReleaseMutex(hMutex);
		}
		else
		{
			break;
		}
	}
	
	log->Add("Thread: Client stoped");
	return 0;
}
Пример #2
0
int main(void)
{
	HANDLE hE = CreateEvent(NULL,false,true,L"{@0001_Start_Program_Event}");
	if ( GetLastError() == ERROR_ALREADY_EXISTS ) 
	{	//program running
		return 0;
	}

	Singleton* log = Singleton::Instance();
	
	Server server;
	if ( server.Activate() )
	{
		cout << "ok" << endl;
	}

	int k = 10; 
	while (k)
	{
		system("cls");
		log->Show();
		system("@pause");
		k--;
		if (k == 1)
		{
			server.Deactivate(); //END THREADS
		}
	}
	system("@Pause");
	return 0;
}
Пример #3
0
int main(int argc , char *argv [])
{
	Singleton *singletonObj = Singleton ::GetInstance();
	cout<<singletonObj->GetTest()<<endl;

	return 0;
}
Пример #4
0
AnalitikaArtikliLista::~AnalitikaArtikliLista()
{
    disconnect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(selectionChanged(QModelIndex,QModelIndex)));
    disconnect(header, SIGNAL(sectionResized(int, int, int)), this, SLOT(procSectionResized(int, int, int)));
    disconnect(header_2, SIGNAL(sectionResized(int, int, int)), this, SLOT(procSectionResizedDetail(int, int, int)));


    Singleton *s = Singleton::Instance();
    QStringList tempVals = s->saveWidthList(colWidth);
    s->Set_Faktura_HeaderState(tempVals);
    QStringList tempdetailVals = s->saveWidthList(colDetailWidth);
    s->Set_FakturaDetail_HeaderState(tempdetailVals);


    delete ui;
    delete model;
    delete header;
    delete model_2;
    delete header_2;
    delete b;
    b = 0;
    delete bc;
    bc = 0;
    delete bd;
    bd = 0;
}
int main()
{
	Singleton* instance = Singleton::get();
	std::cout << instance->showData() << std::endl;

	return 0;
}
	void clearSet() { //bool forceClear
		int i;
		

		//bool doClear = forceClear;

		if (usingPoolId == -1) {
			
			if (isEntity) {
				usingPoolId = singleton->entityPool->requestPoolId(blockId,holderId);
				gpuRes = singleton->entityPool->holderPoolItems[usingPoolId];
			}
			else {
				usingPoolId = singleton->gpuPool->requestPoolId(blockId,holderId);
				gpuRes = singleton->gpuPool->holderPoolItems[usingPoolId];
			}
			

			readyForClear = true;
		}

		if (readyForClear) {
			readyForClear = false;
			
			for (i = 0; i < MAX_LAYERS; i++) {
				// clear fbo by binding it with auto flag
				singleton->bindFBODirect(gpuRes->getFBOS(i));
				singleton->unbindFBO();
			}
		}
		
	}
Пример #7
0
void setExecutor(
    std::shared_ptr<Exe> executor,
    Singleton<std::weak_ptr<Exe>>& sExecutor,
    Singleton<RWSpinLock, LockTag>& sExecutorLock) {
  RWSpinLock::WriteHolder guard(sExecutorLock.get());
  *sExecutor.get() = std::move(executor);
}
Пример #8
0
int main()
{
  Singleton *singleton = Singleton::getInstance();
  singleton->singletonOperation();

  return 0;
}
Пример #9
0
std::shared_ptr<Exe> getExecutor(
    Singleton<std::weak_ptr<Exe>>& sExecutor,
    Singleton<std::shared_ptr<DefaultExe>>& sDefaultExecutor,
    Singleton<RWSpinLock, LockTag>& sExecutorLock) {
  std::shared_ptr<Exe> executor;
  auto singleton = sExecutor.try_get();
  auto lock = sExecutorLock.try_get();

  {
    RWSpinLock::ReadHolder guard(lock.get());
    if ((executor = sExecutor.try_get()->lock())) {
      return executor;
    }
  }


  RWSpinLock::WriteHolder guard(lock.get());
  executor = singleton->lock();
  if (!executor) {
    std::weak_ptr<Exe> defaultExecutor = *sDefaultExecutor.try_get().get();
    executor = defaultExecutor.lock();
    sExecutor.try_get().get()->swap(defaultExecutor);
  }
  return executor;
}
Пример #10
0
int main()
{
	Singleton *s = Singleton::getInstance();
	s->printInfo();	

	Singleton *s2 = Singleton::getInstance();
	s2->printInfo();	

	Singleton *s3 = Singleton::getInstance();
	s3->printInfo();	

//	Singleton *s4 = new Singleton();

//	Singleton s5;


	/* 创建线程,在线程里也去调用Singleton::getInstance */
	pthread_t thread1ID;
	pthread_t thread2ID;

	pthread_create(&thread1ID, NULL, start_routine_thread1, NULL);
	pthread_create(&thread2ID, NULL, start_routine_thread2, NULL);

	sleep(3);

	return 0;
}
Пример #11
0
void* thread_routine(void* arg)
{
	std::cout << pthread_self() << std::endl;
	Singleton* pInstance = Singleton::GetInstance();
	pInstance->Print();
	// 多线程下无法释放内存,否则会导致程序宕掉,最终导致内存泄漏
	return NULL;
}
Пример #12
0
int main(void){
	Singleton *instance = Singleton::getInstance();
	instance->setValue(35);
	cout << instance->getValue() << endl;
	Singleton *object = Singleton::getInstance();
	cout << object->getValue() << endl; 

}
Пример #13
0
int main() {
    Singleton *s = Singleton::getInstance();
    s->pulse();
    cout << "main: global_ptr is " << GlobalClass::instance()->get_value() << '\n';
    foo();
    bar();
    return 0;
}
Пример #14
0
void		Game::_broadcastPacket(PacketContainer* p, bool tcp)
{
	Singleton<NetworkManager>	*network = NULL;

	for (auto it = this->_clients.begin(); it != this->_clients.end(); ++it)
	{
		network->getInstance()->sendPacket(p->getPacketSerialised(), (*it)->getConnexion(), tcp);
	}
}
Пример #15
0
void setExecutor(
    std::shared_ptr<Exe> executor,
    Singleton<std::weak_ptr<Exe>>& sExecutor,
    Singleton<RWSpinLock, LockTag>& sExecutorLock) {
  auto lock = sExecutorLock.try_get();
  RWSpinLock::WriteHolder guard(*lock);
  std::weak_ptr<Exe> executor_weak = executor;
  sExecutor.try_get().get()->swap(executor_weak);
}
Пример #16
0
void *start_routine_thread2(void *arg)
{
	cout<<"this is thread 2 ..."<<endl;

	Singleton *s = Singleton::getInstance();
	s->printInfo();	
	
	return NULL;
}
Пример #17
0
int main(){
	//Singleton * trysingleton = new Singleton(10);   //wrong
	Singleton * singleton = Singleton::createInstance(10);
	Singleton * singleton2 = Singleton::createInstance(12);
	singleton->print();		
	singleton2->print();
	singleton->deleteInstance();
	singleton2->deleteInstance();
	return 0;
}
Пример #18
0
static void changeLevelChooser(const void *self)
{
	Singleton<LevelLoader> gLevelLoader;
	
	const SpinEdit *spinedit = (const SpinEdit *) self;

	gLevelLoader->loadLevelByID(spinedit->value);
	
	sgLevel.lastPlayerIndex = MAX_SCORE_COLS;
}
 void run()
 {
     const int kCount = 2;
     for(int ix = 0; ix != kCount; ++ix)
     {
         Singleton * temp;
         temp = Singleton::getInstance();
         temp->print();
      
     }
 }
Пример #20
0
int
main() {
  Singleton *p = Singleton::CreateInstance();
  Singleton a(*p); // -- 복제 생성자 호출

  a.SetData(20);

  cout << "p->data = " << p->GetData() << endl; // -- p->data = 10
  cout << "a.data = " << a.GetData() << endl;   // -- a.data = 20

  return 0;
}
Пример #21
0
// myThreadCode ///////////////////////////////////////////////////////////////
void * myThreadCode (void * param) {
    
    Singleton * theInstance;
    
    theInstance = Singleton::Instance();
    
    
    sleep(1);
    theInstance->increaseShared();
    
    return NULL;
}
Пример #22
0
int main()
{
	show();
	Singleton * s = Singleton::Instance();
	show();
	s->Close();
	show();
	s->Close();
	show();
	system("pause");
	return 0;
}
Пример #23
0
IntIspratniciVnes::~IntIspratniciVnes()
{
    Singleton *s = Singleton::Instance();
    QStringList tempdetailVals = s->saveWidthList(colDetailWidth);
    s->Set_FakturaDetail_HeaderState(tempdetailVals);

    delete hlp;
    delete ui;
    delete b;
    delete bd;
    b = 0;
    bd = 0;
}
Пример #24
0
bool PovratniciKorekcija::procAddItem(){

    QList<PovratniciDetailT> data = resFakturaItems;
    PovratniciDetailT item;
    item.artikal_id = ui->sifra_artikal->text();
    item.artikal_naziv = ui->artikal->text();
    item.komintent_id = ui->sifra_komintent->text();
    item.dokument_id = resFaktura.dokument_id;
    item.dokument_tip = resFaktura.dokument_tip;
    item.kol = ui->kolicina->text();
    item.izl_cena_so_ddv_prod = ui->cena_so_ddv->text();

    bool isOk;
    float kolFloat = 0;
    float izl_cena_so_ddv_prod_float = 0;
    Singleton *s = Singleton::Instance();
    s->ConvertStringToFloat(item.kol, kolFloat, &isOk);
    if (!isOk){
        QMessageBox msgBox;
        msgBox.setWindowTitle("Warning");
        msgBox.setText("Nevalidna vrednost za kolicina");
        msgBox.setStandardButtons(QMessageBox::Ok);
        if(msgBox.exec() == QMessageBox::Ok){
            ui->kolicina->setFocus();
            return false;
        }
    }
    s->ConvertStringToFloat(item.izl_cena_so_ddv_prod, izl_cena_so_ddv_prod_float, &isOk);
    if (!isOk){
        QMessageBox msgBox;
        msgBox.setWindowTitle("Warning");
        msgBox.setText("Nevalidna vrednost za cena");
        msgBox.setStandardButtons(QMessageBox::Ok);
        if(msgBox.exec() == QMessageBox::Ok){
            ui->cena_so_ddv->setFocus();
            return false;
        }
    }
    item.izl_prod_iznos_so_ddv = QString::number(izl_cena_so_ddv_prod_float * kolFloat, 'f', 2);

    bd->AddItem(data, item);
    resFakturaItems = data;
    ui->sifra_artikal->setText("");
    ui->artikal->setText("");
    ui->kolicina->setText("");
    ui->cena_so_ddv->setText("");
    ui->rabat->setText("");
    ui->rok_za_plakanje_denovi->setText("");
    ui->zaliha->setText("");
    return true;
}
Пример #25
0
PovratniciKorekcija::~PovratniciKorekcija()
{
    Singleton *s = Singleton::Instance();
    QStringList tempdetailVals = s->saveWidthList(colDetailWidth);
    s->Set_FakturaDetail_HeaderState(tempdetailVals);

    delete ui;
    delete hlp;
    delete b;
    delete bd;
    delete comboboxD;
    b = 0;
    bd = 0;
}
Пример #26
0
bool IntIspratniciVnes::eventFilter(QObject *object, QEvent *event)
{
    Singleton *s = Singleton::Instance();
    if (event->type() == QEvent::FocusIn)
    {
        str_yellow = "background-color: lightyellow; font-size: "+QString::number(s->getGlobalFontSize())+"pt;";
        ((QWidget*)object)->setStyleSheet(str_yellow);
    }
    if (event->type() == QEvent::FocusOut)
    {
        str_none = "background-color: none; font-size: "+QString::number(s->getGlobalFontSize())+"pt;";
        ((QWidget*)object)->setStyleSheet(str_none);
    }
    return false;
}
Пример #27
0
int main(void)

{

    try
    {
        Singleton *Main = Singleton::GetInstance() ;
        Main->Run();

    }
    catch (const char * s)
    {
        std::cout<<s;
    }

}
Пример #28
0
PovratniciVnes::PovratniciVnes(BaseForm *parent) :
    BaseForm(parent),
    ui(new Ui::PovratniciVnes)
    ,hlp(0)

{
    ui->setupUi(this);
    ui->lineEdit_2->setFocus();
    Singleton *s = Singleton::Instance();
    QRect rMain = s->getMainRect();
    ui->gridLayout->setGeometry(rMain);
    setLayout(ui->gridLayout);
    setFixedSize(QSize(rMain.width()-10, rMain.height()-40));
    hlp = new QHelperC(this);
    connect(hlp, SIGNAL(signalResultInsertArticle(QStringList &)), this, SLOT(getResultEX(QStringList &)));
}
Пример #29
0
DWORD WINAPI Server::Accept(LPVOID)
{
	Singleton* log = Singleton::Instance();
	log->Add("Thread: Accept runing");
	
	while (f)
	{
		int size = sizeof(client);
		s = accept(serv,(struct sockaddr*)&client,&size);

		//create thread vs new SOCKET
		HANDLE hThread = CreateThread(NULL,NULL,ClientThread,(LPVOID)s,NULL,NULL);
		CloseHandle(hThread);
	}

	log->Add("Thread: Accept stoped");
	return 0;
}
Пример #30
0
IntIspratniciVnes::IntIspratniciVnes(BaseForm *parent) :
    BaseForm(parent),
    statusWait(false),
    hlp(0),
    statusOpenEditor(false),
    ui(new Ui::IntIspratniciVnes)
{
    ui->setupUi(this);
    hlp = new QHelperC(this);
    Singleton *s = Singleton::Instance();

    BaseInstallEventFilter(ui->gridLayout);


    QRect rMain = s->getMainRect();
    ui->gridLayout->setGeometry(rMain);
    setLayout(ui->gridLayout);
    setFixedSize(QSize(rMain.width()-10, rMain.height()-40));

    strDisabled = "color: blue; font-size: "+QString::number(s->getGlobalFontSize())+"pt;";
    ui->sifra_artikal->setStyleSheet(strDisabled);
    ui->sifra_komintent->setStyleSheet(strDisabled);

    model = new QStandardItemModel(0,0);
    header = new QHeaderView(Qt::Horizontal, 0);

    QStringList tempValsDetail = s->Get_FakturaDetail_HeaderState();
    colDetailWidth = s->loadWidthList(tempValsDetail, COL_DETAIL);

    b = new QBTemplate<IntIspratniciT>();
    bd = new QBTemplate<IntIspratniciDetailT>();

    ui->tableView->setModel(model);
    connect(header, SIGNAL(sectionResized(int, int, int)), this, SLOT(procSectionResized(int, int, int)));
    sm =ui->tableView->selectionModel();
    connect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(selectionChanged(QModelIndex,QModelIndex)));
    comboboxD = new QCBItemDelegate(Q_NULLPTR);
    connect(comboboxD, SIGNAL(updatePodatoci()), this , SLOT(updatePodatoci()));
    lineeditD = new QLEItemDelegate(Q_NULLPTR);
    connect(lineeditD, SIGNAL(updateCellLE(const QModelIndex &, QString &)), this , SLOT(updateStructCellLineEdit(const QModelIndex &, QString &)));
    updateFont();

    PressKeyTAB(this);
}