Example #1
0
void SBPinsInit(void(*inputTask1)(void), void(*inputTask2)(void), uint8_t inputPriority) {
    lInTask = inputTask1;
    rInTask = inputTask2;
    PBPriority = inputPriority;

    PCInit();
    portBInit();
}
Example #2
0
void WorkInit()
{
	/* Init logs */
	LogInit();
	
	if (payguide::working) 
		LogWrite(LOGMSG_WARNING, "Initializing payuguide server... ");
	else
		LogWrite(LOGMSG_WARNING, "Restarting payuguide server... ");
		
	/* Load config file */
	LogWrite(LOGMSG_SYSTEM, "Loading configuration file from /etc/payguide.cfg");
	if (ReloadConfigValues("/etc/payguide.cfg")!=0)
		LogWrite(LOGMSG_WARNING, "Can't load  /etc/payguide.cfg - using default values instead.");
	else
		LogWrite(LOGMSG_SYSTEM, "Configuration file /etc/payguide.cfg loaded.");
		
	
	if (pc_init_result==-1)
	{
		if (payguide::bind_interface!="all" && payguide::bind_interface!="ALL")
			pc_init_result=PCInit(payguide::pc_port, 100, payguide::bind_interface.c_str(), payguide::users_filename.c_str(), payguide::package_timeout);
		else pc_init_result=PCInit(payguide::pc_port, 100, NULL, payguide::users_filename.c_str(), payguide::package_timeout);
	}
	
	
	/* Loading pay modules from *.so  files */
	LogWrite(LOGMSG_SYSTEM, "Loading pay modules (*.so files)");
	payguide::modules_list = LoadModules(payguide::modules_path.c_str());
	LogWrite(LOGMSG_SYSTEM, "Pay modules loaded.");
	
	/* Loading default module  */
	payguide::null_pay_sys=GetPaySysBySoName("libnull.so");
	
	if (payguide::null_pay_sys==NULL)
	{
		LogWrite(LOGMSG_CRITICAL, "Critical error - can't load NULL pay system (libnull.so)");
//		std::cout << "Critical error - can't load NULL pay system (libnull.so)" << std::endl;
		payguide::quit=true;
		payguide::working=false;
		RemoveLockFile();
		exit(1);
	}
	
	
	/* Loading operators */
	LogWrite(LOGMSG_SYSTEM, "Loading operators...");
	payguide::operators_list = LoadOperators(payguide::operators_path.c_str());
	LogWrite(LOGMSG_SYSTEM, "Operators loaded.");
	
	
	/* Creating thread_min workers */
	{
		char logmsg[256]; snprintf(logmsg, 255, "Creating %i threads...",payguide::thread_min);LogWrite(LOGMSG_SYSTEM,logmsg);
	}
	sem_wait(&payguide::free_workers_lock);
	payguide::workers_list = CreateWorkers(payguide::thread_min);
	payguide::working_workers=0;
	
	LogWrite(LOGMSG_SYSTEM, "Threads created.");
	
	/* Free worker is a first worker in list */
	payguide::workers_list->ResetCursor();
	payguide::free_worker=payguide::workers_list->GetNext();
	sem_post(&payguide::free_workers_lock);	
	
	/* Init MySQL database */
	if (0==DBInit(&payguide::db_host, &payguide::db_name, &payguide::db_user, &payguide::db_password))
		LogWrite(LOGMSG_SYSTEM, "Connection to MySQL database established.");
	else
		LogWrite(LOGMSG_ERROR, "Connection to MySQL database failed.");
		
		
	LoadAllInitSO(payguide::modules_init_path.c_str());
	return;
}