Esempio n. 1
0
int WikiManage::wiki_init()
{
	struct timeval now;

	if (LOG_INIT(LOG_MIN, BASE_DIR, "fastwiki.log") == -1)
		LOG_INIT(LOG_MIN, "/data/local/tmp", "fastwiki.log");

	gettimeofday(&now, NULL);
	srand(now.tv_sec | now.tv_usec);

	memset(&m_search_buf, 0, sizeof(m_search_buf));
	m_search_buf.page_idx = (int *)calloc(MAX_PAGE_IDX_TOTAL, sizeof(int));

	m_buf = (char *)malloc(_MAX_ONE_PAGE_SIZE + 1024);
	m_trans_buf = (char *)malloc(MAX_TRANS_BUF_SIZE);

	m_curr_content = (char *)malloc(_MAX_ONE_PAGE_SIZE + 1024);
	m_curr_page = (char *)malloc(_MAX_ONE_PAGE_SIZE + 1024);

	memset(&m_all_lang[0], 0, sizeof(struct one_lang));

	m_match_title = (wiki_title_t *)calloc(MAX_MATCH_TITLE_TOTAL + 1, sizeof(wiki_title_t));
	memset(m_match_title, 0, (MAX_MATCH_TITLE_TOTAL + 1) * sizeof(wiki_title_t));

	for (int i = 0; i < MAX_PTHREAD_TOTAL; i++) {
		m_math_data[i] = (char *)malloc(_MAX_MATH_SIZE + 1024);
	}

	m_wiki_config = new WikiConfig();
	m_wiki_config->wc_init();

	m_wiki_socket = new WikiSocket();
	m_wiki_socket->ws_init(NULL, _wiki_do_url, (void *)this);

	pthread_t id;
	pthread_create(&id, NULL, wiki_manage_start_socket_thread, m_wiki_socket);
	usleep(10000);

	m_wiki_history = new WikiHistory();
	m_wiki_history->wh_init();
	m_history = (struct tmp_history *)calloc(MAX_TMP_HISTORY_TOTAL + 10, sizeof(struct tmp_history));

	m_wiki_favorite = new WikiFavorite();
	m_wiki_favorite->wf_init();
	m_favorite = (struct tmp_favorite *)calloc(MAX_TMP_FAVORITE_TOTAL + 10, sizeof(struct tmp_favorite));

	m_wiki_audio = new WikiAudio();
	m_wiki_audio->wa_init(m_wiki_config->wc_get_audio_path());

	INIT_CURR_LANG();

	pthread_mutex_init(&m_mutex, NULL);

	if (wiki_lang_init() == -1)
		return -1;

	m_init_flag = 1;

	return 0;
}
Esempio n. 2
0
int RuleInit::init_su_rule(Connection_T conn)
{
    RulerManager::getInstance()->init_system_rule(SU_RULER);
    if(!system_if_initialized(conn , SU_RULER))
    {
        LOG_INIT("!!!SU IS NOT BEEN INITIALIZED!!!");
        return 0;
    }

    int bucket_num = get_bucket_number(conn , SU_RULER);
    int mod = get_mod_from_db(conn , SU_RULER);
    if((bucket_num < 0) || (mod < 0))
    {
        LOG_ERROR("RuleInit::get bucket number or get mod error when init su rule !");
        return -1;
    }
    
    std::cerr<<"SU bucket number : "<<bucket_num<<" and current mod : "<<mod<<std::endl;
    
    if((this->generate_all_rule(conn , SU_RULER , bucket_num) < 0) || 
        (this->generate_all_order(conn , SU_RULER) < 0))
    {
        LOG_ERROR("RuleInit::init su rule table or order table in memory error !");
        RulerManager::getInstance()->init_system_rule(SU_RULER);
        return -1;
    }
    return 0;
}
Esempio n. 3
0
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID FAR *ppv)
{
	LOG_INIT();
	LOG_APPEND("------ DllGetClassObject -----");
	CClassFactory *pClassFactory;
	const COCLASS_REGISTER *pCoClass;
	HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;

	// scan for the right one
	for (pCoClass = g_CoClasses; pCoClass->pClsid != NULL; pCoClass++)
	{
		if (*pCoClass->pClsid == rclsid)
		{
			pClassFactory = new CClassFactory(pCoClass);
			if (pClassFactory != NULL)
			{
				hr = pClassFactory->QueryInterface(riid, ppv);

				pClassFactory->Release();
				break;
			}
			else
			{
				hr = E_OUTOFMEMORY;
				break;
			}
		}
	}

	return hr;
}
Esempio n. 4
0
void emulator_init(int width, int height, void *user)
{
	LOG_INIT();
	video_init(width, height, user);
	mapper_init();
	emulator_last_tick = 0;
}
Esempio n. 5
0
int main(int argc, char **argv){
    #ifdef HAS_PARMETIS
    int size, rank, rc;
    char lfname[100];
    char efname[100];
    testcount = 0;
    rc = MPI_Init(&argc, &argv);
    if(rc != MPI_SUCCESS){
        FERROR("MPI Initialization error\n");
        MPI_Abort(MPI_COMM_WORLD, rc);
    }
    rank = 0;
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    sprintf(lfname, "parmetislog.%04d", rank);
    //0: debug, 5: critical
    LOG_INIT(lfname, NULL, 0);

    parmetis_with_amd();
    parmetis_only();
    parmetis_with_metmmd();

    MPI_Finalize();
    LOG_CLOSE();
    #else // ifdef HAS_PARMETIS
    cout << "Enable HAS_PARMETIS flag and recompile to test parmetis functions" << endl;
    #endif // HAS_PARMETIS
    return 0;
} // main
Esempio n. 6
0
int main(int argc, char *argv[]) {
	LOG_INIT("/tmp/delay_stat.log");
	
	main_loop();
	
	LOG_CLOSE();
}
Esempio n. 7
0
LR_CES_DEV *init_lrchip(void)
{
	int ret = 0;
	int i, ch;

	LR_SYS_CONFIG cfg;
	LR_CES_DEV *lrdev = malloc(sizeof(LR_CES_DEV));

	LOG_INIT("hardware-firware", LR_LOG_INFO, STDOUT);

	//init param
	cfg.BSPFunctions.readSPI = fpgaRead;
	cfg.BSPFunctions.writeSPI = fpgaWrite;

	ret = lrLoadDriver(&cfg, lrdev);

	printf("found device \n");
	printf("device ID = %x\n", lrdev->devId);
	printf("   E1 line Num = %d\n", lrdev->e1Num);
	printf("   chip version = %x\n", lrdev->version);
	printf("   chip release data = %x-%x\n", lrdev->year, lrdev->date);

	
	return lrdev;

}
Esempio n. 8
0
void init()
{
  open(DEV_CONSOLE, O_RDWR);
  printf("");

  LOG_INIT("Leaks", LOGSYS_COMM, 0xffffffff);
  LOG_PRINTF(("Leaks started"));
  LOG_PRINTF((""));
}
Esempio n. 9
0
void		*init(void *args)
{
  t_args_plug	*a;

  a = (t_args_plug *)args;
  LOG_INIT(a);
  INFO("Minc Converter init");
  return (NULL);
}
Esempio n. 10
0
int Updater::sMain(const std::vector<CL_String8>& args) {
    singleton_ = new Updater();
    singleton_->init();
    LOG_INIT(0);

    int ret = singleton_->main(args);

    LOG_CLOSE;
    delete singleton_;
    return ret;
}
Esempio n. 11
0
int main()
{
    char x[100];
    char xe[100];
    sprintf(x, "test.log");
    sprintf(xe, "test.err");
    LOG_INIT(x, xe, 1);
    DEBUG("This is testing debugging message from sample program \n");
    ERROR("Error message from sample program\n");
    LOG_CLOSE();
    return 0;
}
Esempio n. 12
0
int main(int argc, char *argv[])
{
	//initialize file logger
	LOG_INIT("zzz.log");

//	Q_INIT_RESOURCE(ABM_GUI);

    QApplication app(argc, argv);
    MainWindow mainWin;
    mainWin.show();

    return app.exec();
}
Esempio n. 13
0
int main(int argc, char* argv[])
{
    LOG_INIT("", true, true);
    IGame::Service service;
    IGame::Timer staticTimer(service);
    IGame::Timer memberTimer(service);
    Object obj;

    staticTimer.Set(1000, IGame::TimerEvent(&Func), &staticTimer);
    memberTimer.Set(2000, IGame::TimerEvent(&obj, &Object::Func), &memberTimer); 

    service.Run();
    exit(0);
}
Esempio n. 14
0
int main (int argc, char *argv[])
{
	LOG_INIT(LOG_ALL);
	LOG_GMT_ZONE;

	LOG_BEGIN;

	settings = bp_hashtab_new_ext(czstr_hash, czstr_equal,
				      free, free);

	if (!preload_settings()){
		LOG_END_RC(1);
		//return 1;
	}
	chain_set();
	LOG("chain-set");
	RAND_bytes((unsigned char *)&instance_nonce, sizeof(instance_nonce));

	unsigned int arg;
	for (arg = 1; arg < argc; arg++) {
		const char *argstr = argv[arg];
		if (!do_setting(argstr)){
			LOG_END_RC(1);
			//return 1;
		}
	}
	LOG("arguments processed");

	/*
	 * properly capture TERM and other signals
	 */
	signal(SIGHUP, SIG_IGN);
	signal(SIGPIPE, SIG_IGN);
	signal(SIGINT, term_signal);
	signal(SIGTERM, term_signal);

	LOG("signals set");

	init_daemon(&global_nci);
	run_daemon(&global_nci);

	fprintf(plog, "daemon exiting\n");

	shutdown_daemon(&global_nci);
	LOG_END_RC(0);
	//return 0;
}
Esempio n. 15
0
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved){
	DisableThreadLibraryCalls(hModule);
    if(dwReason == DLL_PROCESS_ATTACH){
    	int res;
		LOG_INIT("jt2");
		LOG_DEBUG_MF(L"main.cpp", 0, L"DLL", L"Attach", L"in process...");
		JungleTime::Core::singleton = new JungleTime::Core();
		res = JungleTime::Core::singleton->Init();
		LOG_VERBOSE_MF(L"main.cpp", 0, L"DLL", L"Attach", L"complete");
		return res;
    }
    else if(dwReason == DLL_PROCESS_DETACH){
    	LOG_DEBUG_MF(L"main.cpp", 0, L"DLL", L"Detach", L"in progress...");
		delete JungleTime::Core::singleton;
		LOG_VERBOSE_MF(L"main.cpp", 0, L"DLL", L"Detach", L"complete");
    }
    return TRUE;
}
Esempio n. 16
0
// the main routine makes the window, and then runs an even loop
// until the window is closed
int main(int argc, char *argv[])
{
	LOG_INIT( "log.txt" );

	srand(time(NULL));

	_wind = new Fl_Double_Window(6,MENUBAR_HEIGHT,WINDOW_WIDTH,WINDOW_HEIGHT+MENUBAR_HEIGHT,"Omnivision");
	
	/* 0 */ _gl_main = new MyGlWindow(0,MENUBAR_HEIGHT,WINDOW_WIDTH-CONTROLBAR_WIDTH,WINDOW_HEIGHT); // main window
	/* 1 */ _gl_main->_menu_bar = new Fl_Menu_Bar(0, 0, WINDOW_WIDTH-CONTROLBAR_WIDTH, MENUBAR_HEIGHT); // menu bar
	/* 2 */ _gl_control = new MyControlBarWindow(WINDOW_WIDTH-CONTROLBAR_WIDTH,MENUBAR_HEIGHT,CONTROLBAR_WIDTH,\
			CONTROLBAR_HEIGHT); // control bar

	_gl_main->_control_bar = _gl_control;

	initMainWindow(_gl_main,_gl_control);

		// init the state machine
	SM_Init( _gl_main, _gl_main->MAINTENANCE_MAX_CORRESPONDENCES, _gl_main->MAINTENANCE_HISTORY_SIZE );

	_wind->begin();	

	_tempo = 0.0;
	Fl::add_timeout(_tempo, callback);

	_wind->end();
	_wind->show();

	/*_wind->begin();
	glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
	glutInitWindowSize(WINDOW_WIDTH,WINDOW_HEIGHT);
	int ww = glutCreateWindow(argv[0]);
	LOG(LEVEL_INFO, "created window %d\n", ww);
	GLuint textures[10];
	glGenTextures( 10, textures );
	_wind->end();*/


	return Fl::run();
	//delete _gl_main;
	//delete _gl_control;

	//return 1;
}
Esempio n. 17
0
// 初始化SDK
ELTE_INT32 __SDK_CALL ELTE_SDK_Init()
{
	//打开日志
	LOG_RUN_ERROR("ELTE_SDK_Init start.");
	std::string strIniPath = eLTE_Tool::GetDllPath(ELTE_RM_SDK_DLL_NAME);
	strIniPath.append(LOG_INI_FILE_NAME);
	ELTE_UINT32 logLevel[LOG_CATEGORY];
	for (ELTE_UINT32 i = 0; i < LOG_CATEGORY; ++ i)
	{
		logLevel[i] = g_uiLogLevel;
	}
	ELTE_INT32 iRet = LOG_INIT(strIniPath.c_str(), logLevel, g_strLogPath.c_str());
	if(eLTE_SDK_ERR_SUCCESS != iRet)
	{
		return eLTE_SDK_ERR_LOG_INIT;		
	}
	LOG_INTERFACE_TRACE();
	if(NULL == g_pUserMgr)
	{
		g_pUserMgr = new CUserMgr();
		if(NULL == g_pUserMgr)
		{
			LOG_RUN_ERROR("New CUserMgr failed.");
			LOG_INTERFACE_INFO(eLTE_SDK_ERR_CREATE_OBJECT, "");
			//关闭日志
			LOG_EXIT();
			return eLTE_SDK_ERR_CREATE_OBJECT;			
		}
	}

	//初始化socket
	SSL_Socket& sslSocket = const_cast<SSL_Socket&>(g_pUserMgr->GetSSLSocket());
	iRet = sslSocket.Init_SSL_Socket();
	if(eLTE_SDK_ERR_SUCCESS != iRet)
	{
		LOG_RUN_ERROR("Init ssl socket failed.");
		return iRet;
	}

	LOG_INTERFACE_INFO(iRet, "");
	return iRet;
}
Esempio n. 18
0
//
//	ESciVis::InitPhysX
//
void ESciVis::InitPhysX( void )
{
	LOG_INIT("PhysX");
	
	// Create the physics SDK
    nx = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
    if (!nx)  return;

	// Set the physics parameters
	nx->setParameter(NX_SKIN_WIDTH, 0.01f);

	// Set the debug visualization parameters
	nx->setParameter(NX_VISUALIZATION_SCALE, 1);
	nx->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	nx->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);

    // Create the scene
    NxSceneDesc sceneDesc;
    sceneDesc.gravity               = NxVec3(0,0,0);
	sceneDesc.simType				= NX_SIMULATION_SW;
    nx_scene = nx->createScene(sceneDesc);	
	
	if(!nx_scene) { 
		sceneDesc.simType				= NX_SIMULATION_SW; 
		nx_scene = nx->createScene(sceneDesc);  
		if(!nx_scene) return;
	}
	
	//	coocking lib :
	nx_cook	=	NxGetCookingLib(NX_PHYSICS_SDK_VERSION);
	if (!nx_cook) {
		RUNTIME_ERROR("NxGetCookingLib() failed");
	}
	nx_cook->NxInitCooking();
	

	// Create the default material
	NxMaterial* defaultMaterial = nx_scene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);
}
Esempio n. 19
0
void time_init(void) {

  LOG_INIT();

  DDRD &= ~_BV(PD2);

  // internal pullup seems NOT to work 
  //  PORTD |= _BV(PD2);

  PORTD &= ~_BV(PD2);

  // The rising edge of INT0 generates an interrupt request.  
  // enable external interrupt 0

  MCUCR |= _BV(ISC01) | _BV(ISC00);
  GICR  |= _BV(INT0);                   

  newtime = 0;

  LOG_INIT_EXIT();
}
Esempio n. 20
0
int main(int argc, char *argv[])
{
    int res;
    char msg[1024];
    //initialize file logger
    LOG_INIT("scell_GUI.log");

    /*
    if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) )
    {
        sprintf(msg, "\nThe Control Handler is installed.\n" );
        LOG_MSG(msg);
//      printf( "\nThe Control Handler is installed.\n" );
//      printf( "\n -- Now try pressing Ctrl+C or Ctrl+Break, or" );
//      printf( "\n    try logging off or closing the console...\n" );
//      printf( "\n(...waiting in a loop for events...)\n\n" );

//      while( 1 ){ }
    }
    else
    {
      sprintf(msg, "\nERROR: Could not set control handler");
      LOG_MSG(msg);
      return 1;
    }
    */

    QApplication app(argc, argv);

    MainWindow mainWin;
    mainWin.show();

    res = app.exec();
    sprintf(msg,"Result code: %d",res);
    LOG_MSG(msg);
    return res;
}
Esempio n. 21
0
int main(int argc, char **argv)
{
	int i, j;
	Graph::VertexWeightedGraph *G;
	TDTree *T=NULL;
	DP_info info;
	list<int> optimal_solution;
    int rank, size;
    double stime, etime;

    int storage_nodes = 1;
    
    MPI_Group orig_group, new_group;

    double leaf_time;
    double nonleaf_time;
    long smem_hwm;
    long rmem_hwm;

    

    MPI_Init (&argc, &argv);
    MPI_Comm_rank (MPI_COMM_WORLD, &rank);
    MPI_Comm_size (MPI_COMM_WORLD, &size);

    // There is a seperate log file for each processor, strictly for
    // debugging and development purposes only.

    char lfname[100];
    char efname[100];
    sprintf (lfname, "parallel_wis-%d.log", rank);
    sprintf (efname, "parallel_wis-error.log", rank);
    //0: debug, 5: critical
    LOG_INIT(lfname, efname, 0);


     if (!(size > storage_nodes + 2))
     {
         FERROR ("No enough processors, please allocate more\n");
         FERROR ("Processor distribution: head_node: %d storage_nodes: %d compute_nodes: %d\n", 1, storage_nodes, size - (storage_nodes + 1));
         MPI_Finalize ();
         exit (0);
     }


	// Process command line options
	int help = info.process_DP_info(argc, argv);
	if(help == -1){
	  if(rank == 0)
	    {
	      usage(argv[0]);
	    } 
	  MPI_Finalize ();
	  exit (1);
	}
	
	// Create the graph for WIS
	create_WIS_graph(&info, G);
	// See if the MIP is to be written/solved
	if(info.write_mod)
	{
		write_ind_set_model(info.DIMACS_file, info.model_file, G);
		if(info.solve_mip)
		{
			// Use GLPSOL to run the MIP solver
			char command_string[100];
			sprintf(command_string,"%s -m %s",GLPSOL,info.model_file);
			fprintf(stderr,"Will use %s to solve MIP. Solution will be written to %s.MIP.WIS.sol",
                    GLPSOL,info.DIMACS_file);
			system(command_string);
		}
		return 1;		
	}
		
	
	// Create the tree decomposition using the options
	create_tree_decomposition(&info, G, &T);
	// Check to see if the DP is to be done
	if(info.decompose_only)
	{
		printf("%s: Treewidth %d\n", info.DIMACS_file, T->width);
		//delete G;
		//delete T;
		return 1;
	}


    T->head_node = 0;
    T->allnodes = new vector<int>(size, -1);
    //T->storage_nodes = new vector<int>(size, -1);
    //T->compute_nodes = new vector<int>(size, -1);

    (*T->allnodes)[0] = HEAD_NODE;
    for (i = 1; i < size; i++)
    {
        if ((storage_nodes > 0) && (i % 4 == 1))
        {
            T->storage_nodes.push_back(i);
            (*T->allnodes)[i] = STORAGE_NODE;
            storage_nodes --;
        }
        else
        {
            T->compute_nodes.push_back(i);
            (*T->allnodes)[i] = COMPUTE_NODE;
        }
    }

    if (MPI_SUCCESS != 
        MPI_Comm_group(MPI_COMM_WORLD, &orig_group))
    {
        FERROR ("MPI Test any failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
        MPI_Finalize();
    }

    if (MPI_SUCCESS != 
        MPI_Group_incl (orig_group, T->compute_nodes.size(), &T->compute_nodes.front(), &new_group))
    {
        FERROR ("MPI Test any failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
        MPI_Finalize();
    }

    MPI_Comm compute_nodes_comm;
    if (MPI_SUCCESS != 
        MPI_Comm_create (MPI_COMM_WORLD, new_group, &compute_nodes_comm))
    {
        FERROR ("MPI Test any failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
        MPI_Finalize();
    }

    T->compute_nodes_comm = &compute_nodes_comm;
    T->storage_nodes_size = T->storage_nodes.size();
    T->compute_nodes_size = T->compute_nodes.size();

    if ((*T->allnodes)[rank] == HEAD_NODE)
    {
        parallel_wis_head_init (T, size, rank);
        parallel_wis_head_start (T);
    }
    else if ((*T->allnodes)[rank] == COMPUTE_NODE)
    {
        parallel_wis_compute_init (T, size, rank);
    }
    else if ((*T->allnodes)[rank] == STORAGE_NODE)
    {
        parallel_wis_storage_init (T, size, rank);
        parallel_wis_storage_start (T);
    }


    if ((*T->allnodes)[T->rank] == COMPUTE_NODE)
    {
        DEBUG("post order walk\n");
        // Create the post_order walk
        vector<int> walk(T->num_tree_nodes,GD_UNDEFINED);
        T->post_order_walk(&walk);

        stime = MPI_Wtime();
        int j;
        DEBUG("starting loop\n");
        for(i = 0; i < T->num_tree_nodes; i++)
        {
            CRIT("processing node : ############# %d\n", walk[i]);
            DEBUG(" %d  more nodes left\n", (T->num_tree_nodes - i));
            T->compute_table(compute_weighted_ind_sets_parallel, walk[i]);
            MPI_Barrier (compute_nodes_comm);

            if(T->info->free_children)
            {
                for(j = 0; (j < T->storage_nodes_size) && (T->rank == T->compute_nodes[0]); j++)
                {
                    if (MPI_SUCCESS !=
                        MPI_Send ((void *)&walk[i], 1, MPI_INT, T->storage_nodes[j], MPI_CHILD_FREE_TAG, MPI_COMM_WORLD))
                    {
                        FERROR ("MPI Irecv failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
                        MPI_Finalize();
                    }
                }
            }
        }

        // Send termination signal to head node to nofity that
        // computation is over for the given tree
        if (MPI_SUCCESS != 
            MPI_Send (&T->rank, 1, MPI_INT, 0, MPI_COMP_TERM_TAG, MPI_COMM_WORLD))
        {
            FERROR ("MPI Send failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
            MPI_Finalize();
        }
        
        // Set flag_recv_done when all tree nodes have been finished then
        // receiving threads can exit.
        T->flag_recv_done = 1;
        
        etime = MPI_Wtime ();
        

        // Store and reset info's table stats 
        info.orig_total_pc_table_entries=info.total_pc_table_entries;
        info.orig_total_table_entries=info.total_table_entries;
        
        info.total_pc_table_entries=info.total_table_entries=0;
        
        
        // Compute some stats here in parent-child intersection to analyze 
        // why memory savings varies across different graphs
        // This is less than ideal, but you have to do it this way for something like make_nice
        // since there are "holes" in the tree_nodes[] array.  The above compute_table() loop
        // gets around this by using the post order walk that is filled with only valid tree node
        // indices!
        
        vector<int> intersection_sizes(T->tree_nodes.size(),-1);
        T->compute_parent_child_intersections(&intersection_sizes);
        info.avg_pc_proportion=0;
        int num_in_avg=0;
        for(i=0;i<(int)T->tree_nodes.size();i++)
        {
            if(T->tree_nodes[i])
            {
                num_in_avg++;
                info.avg_pc_proportion += ((double)intersection_sizes[i]/(double)T->tree_nodes[i]->bag.size());
            }
        }
        info.avg_pc_proportion = info.avg_pc_proportion/(double)num_in_avg;
    }

    smem_hwm = getHWmem();
    if ((*T->allnodes)[rank] == COMPUTE_NODE)
    {
    
        if (MPI_SUCCESS != 
            MPI_Reduce ((void *)&T->info->leaf_time, (void *)&leaf_time, 1, MPI_DOUBLE, MPI_MAX, 0, *T->compute_nodes_comm))
        {
            FERROR ("MPI Reduce failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
            MPI_Finalize();
        }
        T->info->leaf_time = leaf_time;
    
        if (MPI_SUCCESS != 
            MPI_Reduce ((void *)&T->info->nonleaf_time, (void *)&nonleaf_time, 1, MPI_DOUBLE, MPI_MAX, 0, *T->compute_nodes_comm))
        {
            FERROR ("MPI Reduce failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
            MPI_Finalize();
        }
        T->info->nonleaf_time = nonleaf_time;
    
        if (MPI_SUCCESS != 
            MPI_Reduce ((void *)&smem_hwm, (void *)&rmem_hwm, 1, MPI_LONG, MPI_MAX, 0, *T->compute_nodes_comm))
        {
            FERROR ("MPI Reduce failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
            MPI_Finalize();
        }
    
        if (T->rank == T->compute_nodes[0])
            fprintf (stderr, "Memory HWM for all compute nodes: %d\n", rmem_hwm);
    }
    
    if (MPI_SUCCESS != 
        MPI_Reduce ((void *)&smem_hwm, (void *)&rmem_hwm, 1, MPI_LONG, MPI_MAX, 0, MPI_COMM_WORLD))
    {
        FERROR ("MPI Reduce failed at processor : %d %s:%d\n", T->rank, __FILE__, __LINE__);
        MPI_Finalize();
    }

    if (T->rank == 0)
        fprintf (stderr, "Memory HWM for all  nodes: %d\n", rmem_hwm);


    
    if ((*T->allnodes)[rank] == HEAD_NODE)
    {
        parallel_wis_head_cleanup (T);
    }
    else if ((*T->allnodes)[rank] == COMPUTE_NODE)
    {
        parallel_wis_compute_cleanup (T);
    }
    else if ((*T->allnodes)[rank] == STORAGE_NODE)
    {
        parallel_wis_storage_cleanup (T);
    }

    LOG_CLOSE();
    MPI_Finalize();

    if (T->rank == T->compute_nodes[0] )
        print_WIS_results(stdout, T, &info);

  	//delete T;
    //delete &G;
 	return 1;
}
Esempio n. 22
0
int _tmain(int argc, char* argv[])//lint !e752 !e1768 !e1727
{
	//打开日志
	std::string strIniPath = eLTE_Tool::GetServicePath();
	strIniPath.append(LOG_INI_FILE_NAME);
	unsigned int logLevel[LOG_CATEGORY] = {INVALID_LOG_LEVEL,INVALID_LOG_LEVEL,INVALID_LOG_LEVEL};
	std::string strLogPath = eLTE_Tool::GetServicePath();
	strLogPath.append("log");
	int iRet = LOG_INIT(strIniPath.c_str(), logLevel, strLogPath.c_str());
	if(RET_SUCCESS != iRet)
	{
		return eLTE_SDK_ERR_LOG_INIT;
	}
	
	LOG_TRACE();

	if (INSTALL_AGRC == argc && NULL != argv)
	{
		if (0 == _stricmp(argv[1], "/install") || 0 == _stricmp(argv[1], "-install"))
		{
			InstallService();
		}
		else if (0 == _stricmp(argv[1], "/uninstall") || 0 == _stricmp(argv[1], "-uninstall"))
		{
			UninstallService();
		}
	}
	else
	{
		SERVICE_TABLE_ENTRY svcTable[2];
		svcTable[0].lpServiceName = MY_SERVICE_NAME;
		svcTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTIONA)ServiceMain;
		svcTable[1].lpServiceName = NULL;
		svcTable[1].lpServiceProc = NULL;

		if (!StartServiceCtrlDispatcher(svcTable))
		{
			LOG_RUN_ERROR("StartServiceCtrlDispatcher failed.");
		}
	}

	// 用于直接以普通应用程序的形式启动服务器,方便debug调试服务程序业务

	// 初始化SDK
	//int iRet = AppContextMgr::Instance().Init();
	//if (eLTE_SVC_ERR_SUCCESS != iRet)
	//{
	//	LOG_RUN_ERROR("Init elte sdk failed.(%d)", iRet);
	//}
	//else
	//{
	//	// 开启业务监听
	//	StartRun();

	//	// 退出SDK
	//	iRet = AppContextMgr::Instance().Exit();
	//	if (eLTE_SVC_ERR_SUCCESS != iRet)
	//	{
	//		LOG_RUN_ERROR("Exit elte sdk failed.(%d)", iRet);
	//	}
	//}

	LOG_EXIT();
	return 0;
}//lint !e818
Esempio n. 23
0
int main(int argc, char *argv[])
{
    int      option;
    int      ret;
    int      log_mode;
    int      log_level;
    char     buffer[OAM_STR_MAX];
    char     program[OAM_PROCNAME_MAX];
    oammmc_t *oammmc = NULL;
    mpipc_t *mpipc = NULL;
    mptmr_t *mptmr = NULL;

#if !defined(_SKIP_PRIVILEGES_CHECK)
    if (geteuid() == 0) {
        fprintf(stderr, "Shouldn't startup with root privileges\n");
        return 1;
    }
#endif

    while ((option = getopt(argc, argv, "v")) != EOF) {
        switch (option) {
            case 'v':
                fprintf(stdout, MODULE_VERSION"\n");
                return 0;
            default:
                fprintf(stdout,"Usage: %s [-v]\n", argv[0]);
                return 0;
        }
    }
    
    mpconf_get_int(NULL, MODULE_CONF, MODULE_NAME,
                   "log_mode", &log_mode, 1, 125);
    mpconf_get_int(NULL, MODULE_CONF, MODULE_NAME,
                   "log_level", &log_level, 1, LOG_LEVEL_SVC);
    strlcpy(buffer, argv[0], sizeof(buffer));
    mpconv_get_upperl(basename(buffer), program, sizeof(program));

    if ((ret = LOG_INIT(program, NULL, log_mode, log_level)) < 0) {
        fprintf(stderr, "unable to initialize log\n");
        goto _exit_failure;
    }

    MPGLOG_ERR("STARTUP_PROCESS[%d]: %s\n", (int)getpid(), MODULE_VERSION);

    mpsignal(SIGINT,  default_signal_handler);
    mpsignal(SIGTERM, default_signal_handler);
    mpsignal(SIGCHLD, child_exit_handler);
    mpsignal(SIGPIPE, SIG_IGN);

    if ((mpipc = xxx_ipc_init(program)) == NULL) {
        MPGLOG_ERR("%s:: xxx_ipc_init failed\n", __func__);
        goto _exit_failure;
    }

    if ((oammmc = xxx_mmc_init(program, mpipc)) == NULL) {
        MPGLOG_ERR("%s:: xxx_mmc_init failed\n", __func__);
        goto _exit_failure;
    }

#if 0 /* remove comment if it use stctl library */
    if ((ret = stgen_open(MODULE_NAME,
                          stctl_item_list, stctl_dtl_type_list)) < 0) {
        MPGLOG_ERR("%s:: stgen_open failed, ret=%d,%s\n",
                __func__, ret, stctl_strerror(ret));
        goto _exit_failure;
    }
#endif

    if ((mptmr = xxx_svc_init(mpipc, &service_flag)) == NULL) {
        MPGLOG_ERR("%s:: xxx_svc_init failed\n", __func__);
        goto _exit_failure;
    }

    while (service_flag == 1) {
        mpthr_sleep_msec(500);
    }
    
    xxx_svc_destroy(mptmr);
#if 0 /* remove comment if it use stctl library */
    stgen_close();
#endif
    xxx_mmc_destroy(oammmc);
    xxx_ipc_destroy(mpipc);

    MPGLOG_ERR("SHUTDOWN_PROCESS[%d]: EXIT_SUCCESS, SIGNAL=%d\n\n",
            (int)getpid(), received_signal );

    return 0;

_exit_failure:

    xxx_svc_destroy(mptmr);
#if 0 /* remove comment if it use stctl library */
    stgen_close();
#endif
    xxx_mmc_destroy(oammmc);
    xxx_ipc_destroy(mpipc);
    
    MPGLOG_ERR("SHUTDOWN_PROCESS[%d]: EXIT_FAILURE\n\n", (int)getpid());

    return 100;
}
Esempio n. 24
0
int main( int argc, char *argv[] )
{
    int pid;


    /* read the arguments */
    td.connect = 1;
    td.logfile = NULL;
	LOG_INIT(NULL);//"/tmp/vlhttp-debug.log");
    LOG_SET_LEVEL(LOG_LEVEL_DBG);
    char opt;
    while((opt = getopt(argc, argv, "p:i:m:r:A:S:f")) != -1) {
        switch(opt) {
            case 'A':
                encode_base64(optarg, strlen(optarg), (unsigned char**)(&proxy_auth));
                DBG("proxy_auth: %s", proxy_auth);
                break;
            case 'S':
                encode_base64(optarg, strlen(optarg), (unsigned char**)(&sys_auth));
                DBG("sys_auth: %s", sys_auth);
                break;
            case 'r':
                strncpy(proxy_realm, optarg, sizeof(proxy_realm));
                break;
            case 'p':
                proxy_port = atoi(optarg);
                break;
            case 'i':
                td.auth_ip = inet_addr(optarg);
                break;
            case 'm':
                td.netmask = inet_addr(optarg);
                break;
            case 'f':
                DBG("turn off daemon", 0);
                foreground_mode = 1;
                break;
        }
    }

    td.auth_ip &= td.netmask;
    td.client_ip = 0;

	DBG("========================================================================================================", 0);

    /* is inetd mode enabled ? */

    if( proxy_port == 0 )
    {
		int r;
        td.client_fd = 0; /* stdin */

		DBG("start",0);
		r = proxy_thread( &td );
		DBG("exit with %d code", r);

        return( r );
    }

    /* fork into background */
    if (!foreground_mode) {
        if ( (pid = fork() ) < 0 ) {
            ERR("fork() fail", 0);
            return -1;
        }
        if (pid) return ( 0 );
    }


    if (!init_proxy()) {
        return -1;
    }

    while( 1 )
    {
        int n = sizeof( client_addr );

        /* wait for inboud connections */

        if( ( td.client_fd = accept( proxy_fd,
                (struct sockaddr *) &client_addr, (socklen_t*)&n ) ) < 0 )
        {
            ERR("accept() fail", 0);
            return -1;
        }

        td.client_ip = client_addr.sin_addr.s_addr;

        /* verify that the client is authorized */
        if ( (td.client_ip & td.netmask) != td.auth_ip ) {
            close( td.client_fd );
            continue;
        }

        /* fork a child to handle the connection */
        if ( (pid = fork()) < 0 ) {
            close( td.client_fd );
            continue;
        }

        if (pid) {
            /* in father; wait for the child to terminate */

            close( td.client_fd );
            waitpid( pid, NULL, 0 );
            continue;
        }

        /* in child; fork & exit so that father becomes init */
        if ((pid = fork()) < 0 ) {
            ERR("fork() fail", 0);
            return -1;
        }

        if (pid)
            return 0;

        return( proxy_thread( &td ) );

    }

    /* not reached */
    return -1;
}
Esempio n. 25
0
int main (int argc, char *argv[])
{
    char cfg_file[256];
    char app_name[256];
    char* p;

    p = strrchr(argv[0], '/');
    snprintf(app_name, sizeof(app_name), "%s", p+1);

    /* -- get the config filename -- */
    switch (sys_getopt(argc, argv, "c:", cfg_file, sizeof(cfg_file))) {
        case 'c':
#ifdef __DEBUG__
            fprintf(stdout, "config file = [%s]\n", cfg_file);
#endif
            if (0 != Config::load(cfg_file)) {
                fprintf(stderr, "%s: Unable to load config file [%s]!!!\n", app_name, cfg_file);
                exit(-1);
            }
            break;
        default:
            usage(argv[0]);
            exit(0);
    }

    /* -- check if already running -- */
    if (0 != sys_bind(Config::getLockPort())) {
        fprintf(stderr, "%s: Unable to continue, make sure there's no other instance running!!!\n", app_name);
        exit(-1);
    }

    /* -- initialize log -- */
    LOG_INIT(Config::getLogFile(), Config::getLogLevel());

    /* -- check if logger is successfully initialized -- */
    if (0 != LOG_GET_STATUS()) {
        fprintf(stderr, "%s: Unable to initialize logger!\n", app_name);
        exit(-1);
    }

    /* -- initialize libsqlora8 -- */
    if (OraDB::init_lib(true) < 0) {
        LOG_CRITICAL("%s: Unable to initialize libsqlora8!", app_name);
        exit(-1);
    }

    /* -- load system messages from db -- */
    if (0 != Sysmsg::load(Config::getOraAuth(), Config::getBrand())) {
        LOG_CRITICAL("%s: Unable to load system messages from db (%s).", app_name, Config::getOraAuth());
        exit(-1);
    }

    /* -- load services from db -- */
    if (0 != Global::loadRC(Config::getOraAuth(), Config::getLibraryPath(), Config::getBrand())) {
        LOG_CRITICAL("%s: Unable to load services from db (%s).", app_name, Config::getOraAuth());
        exit(-1);
    }

    /* -- initialize request queue -- */
    if (0 != c2q_init(Global::getRequestQ())) {
        LOG_CRITICAL("%s: Unable to initialize request queue!", app_name);
        exit(-1);
    }

    /* -- initialize transaction queue -- */
    if (0 != c2q_init(Global::getTransactionQ())) {
        LOG_CRITICAL("%s: Unable to initialize transaction queue!", app_name);
        exit(-1);
    }

    /* -- initialize response queue -- */
    if (0 != c2q_init(Global::getResponseQ())) {
        LOG_CRITICAL("%s: Unable to initialize response queue!", app_name);
        exit(-1);
    }

    /* -- initialize notification queue -- */
    if (0 != c2q_init(Global::getNotificationQ())) {
        LOG_CRITICAL("%s: Unable to initialize notification queue!", app_name);
        exit(-1);
    }

    /* -- initialize queue -- */
    int rc_size = Global::getRCSize();
    LOG_DEBUG("%s: rc_size: %d", app_name, rc_size);
    if (Global::initTransactionQ(rc_size) < 0) {
        LOG_CRITICAL("%s: Unable to initialize transaction queue!", app_name);
        exit(-1);
    }
    int tran_size = Global::getTransactionQSize();
    LOG_DEBUG("%s: tran_size: %d", app_name, tran_size);
    for (int i=0; i<tran_size; ++i) {
        if (0 != c2q_init(Global::getTransactionQ(i))) {
            LOG_CRITICAL("%s: Unable to initialize transaction queue: %d!", app_name, i);
            exit(-1);
        }
    }

    /* -- initialize geoprobe queue -- */
    if (0 != c2q_init(Global::getGeoProbeQ())) {
        LOG_CRITICAL("%s: Unable to initialize geoprobe queue!", app_name);
        exit(-1);
    }

    /* -- initialize ods queue -- */
    if (0 != c2q_init(Global::getODSQ())) {
        LOG_CRITICAL("%s: Unable to initialize ods queue!", app_name);
        exit(-1);
    }

    /* -- initialize ccb queue -- */
    if (0 != c2q_init(Global::getCCBQ())) {
        LOG_CRITICAL("%s: Unable to initialize ccb queue!", app_name);
        exit(-1);
    }

    /* -- initialize conditioner queue -- */
    if (0 != c2q_init(Global::getConditionerQ())) {
        LOG_CRITICAL("%s: Unable to initialize conditioner queue!", app_name);
        exit(-1);
    }

    /* -- initialize voyager queue -- */
    if (0 != c2q_init(Global::getVoyagerQ())) {
        LOG_CRITICAL("%s: Unable to initialize voyager queue!", app_name);
        exit(-1);
    }


    /* -- run in background -- */
    sys_daemon();

    /* -- block all signals -- */
    sys_sigblock();

    // Thread attributes
    pthread_attr_t pthread_attr_norm;
    pthread_attr_init(&pthread_attr_norm);
    pthread_attr_setstacksize(&pthread_attr_norm, Global::thr_stack_size);

    std::vector<pthread_t> thrs;

    // Signal handler
    pthread_t signal_thr;
    if (0 != pthread_create(&signal_thr, &pthread_attr_norm, signal_handler, NULL)) {
        LOG_CRITICAL("%s: Unable to create signal_handler thread!!!", app_name);
        exit(-1);
    }
    thrs.push_back(signal_thr);

    // Response handler
    for (int i=0; i<Config::getThreadCount(); ++i) {
        pthread_t response_thr;
        if (0 != pthread_create(&response_thr, &pthread_attr_norm, response_handler, (void*)i)) {
            LOG_CRITICAL("%s: Unable to create response_handler thread (%d)!!!", app_name, i);
            abort();
        }
        thrs.push_back(response_thr);
    }

    // Notification handler
    for (int i=0; i<Config::getThreadCount(); ++i) {
        pthread_t notification_thr;
        if (0 != pthread_create(&notification_thr, &pthread_attr_norm, notification_handler, (void*)i)) {
            LOG_CRITICAL("%s: Unable to create notification_handler thread (%d)!!!", app_name, i);
            abort();
        }
        thrs.push_back(notification_thr);
    }

    // Transaction fetcher
    int proc_id = 0;
    int step_no = 0;
    rc_t* rc;
    while ((rc = Global::getNextRC(step_no))) {
        rc_proc_t* rc_proc = new(rc_proc_t);
        rc_proc->rc = rc;
        rc_proc->proc_id = proc_id;
        rc_proc->parent_id = -1;
        rc_proc->ppid = getpid();
        pthread_t tran_fetcher_thr;
        if (0 != pthread_create(&tran_fetcher_thr, &pthread_attr_norm, transaction_fetcher, (void*) rc_proc)) {
            LOG_CRITICAL("%s: Unable to create transaction_fetcher thread (%d)!!!", app_name, proc_id);
            abort();
        }
        thrs.push_back(tran_fetcher_thr);
        step_no = rc->step_no;
        proc_id++;
    }

    // Request handler
    for (int i=0; i<Config::getThreadCount(); ++i) {
        pthread_t request_thr;
        if (0 != pthread_create(&request_thr, &pthread_attr_norm, request_handler, (void*)i)) {
            LOG_CRITICAL("%s: Unable to create request_handler thread (%d)!!!", app_name, i);
            abort();
        }
        thrs.push_back(request_thr);
    }

    // Request fetcher
    pthread_t request_fetcher_thr;
    if (0 != pthread_create(&request_fetcher_thr, &pthread_attr_norm, request_fetcher, NULL)) {
        LOG_CRITICAL("%s: Unable to create request_fetcher thread!!!", app_name);
        abort();
    }
    thrs.push_back(request_fetcher_thr);

    // Raw handler
    for (int i=0; i<Config::getThreadCount(); ++i) {
        pthread_t raw_thr;
        if (0 != pthread_create(&raw_thr, &pthread_attr_norm, raw_handler, (void*)i)) {
            LOG_CRITICAL("%s: Unable to create raw_handler thread (%d)!!!", app_name, i);
            abort();
        }
        thrs.push_back(raw_thr);
    }

    // Raw fetcher
    pthread_t raw_fetcher_thr;
    if (0 != pthread_create(&raw_fetcher_thr, &pthread_attr_norm, raw_fetcher, NULL)) {
        LOG_CRITICAL("%s: Unable to create raw_fetcher thread!!!", app_name);
        abort();
    }
    thrs.push_back(raw_fetcher_thr);

    // Geoprobe handler
    for (int i=0; i<Config::getThreadCount(); ++i) {
        pthread_t geoprobe_thr;
        if (0 != pthread_create(&geoprobe_thr, &pthread_attr_norm, geoprobe_handler, (void*)i)) {
            LOG_CRITICAL("%s: Unable to create geoprobe_handler thread (%d)!!!", app_name, i);
            abort();
        }
        thrs.push_back(geoprobe_thr);
    }

    // Geoprobe fetcher
    pthread_t geoprobe_fetcher_thr;
    if (0 != pthread_create(&geoprobe_fetcher_thr, &pthread_attr_norm, geoprobe_fetcher, NULL)) {
        LOG_CRITICAL("%s: Unable to create geoprobe_fetcher thread!!!", app_name);
        abort();
    }
    thrs.push_back(geoprobe_fetcher_thr);

    // ODS handler
    for (int i=0; i<Config::getThreadCount(); ++i) {
        pthread_t ods_thr;
        if (0 != pthread_create(&ods_thr, &pthread_attr_norm, ods_handler, (void*)i)) {
            LOG_CRITICAL("%s: Unable to create ods_handler thread (%d)!!!", app_name, i);
            abort();
        }
        thrs.push_back(ods_thr);
    }

    // ODS fetcher
    pthread_t ods_fetcher_thr;
    if (0 != pthread_create(&ods_fetcher_thr, &pthread_attr_norm, ods_fetcher, NULL)) {
        LOG_CRITICAL("%s: Unable to create ods_fetcher thread!!!", app_name);
        abort();
    }
    thrs.push_back(ods_fetcher_thr);

    // CCB handler
    for (int i=0; i<Config::getThreadCount(); ++i) {
        pthread_t ccb_thr;
        if (0 != pthread_create(&ccb_thr, &pthread_attr_norm, ccb_handler, (void*)i)) {
            LOG_CRITICAL("%s: Unable to create ccb_handler thread (%d)!!!", app_name, i);
            abort();
        }
        thrs.push_back(ccb_thr);
    }

    if (! strncasecmp(Config::getBrand(), "PREPAID", 7)) {
        // conditioner fetcher
        pthread_t conditioner_fetcher_thr;
        if (0 != pthread_create(&conditioner_fetcher_thr, &pthread_attr_norm, conditioner_fetcher, NULL)) {
            LOG_CRITICAL("%s: Unable to create conditioner_fetcher thread!!!", app_name);
            abort();
        }
        thrs.push_back(conditioner_fetcher_thr);

        // conditioner handler
        for (int i=0; i<Config::getThreadCount(); ++i) {
            pthread_t conditioner_thr;
            if (0 != pthread_create(&conditioner_thr, &pthread_attr_norm, conditioner_handler, (void*)i)) {
                LOG_CRITICAL("%s: Unable to create conditioner_handler thread (%d)!!!", app_name, i);
                abort();
            }
            thrs.push_back(conditioner_thr);
        }

        // voyager fetcher
        pthread_t voyager_fetcher_thr;
        if (0 != pthread_create(&voyager_fetcher_thr, &pthread_attr_norm, voyager_fetcher, NULL)) {
            LOG_CRITICAL("%s: Unable to create voyager_fetcher thread!!!", app_name);
            abort();
        }
        thrs.push_back(voyager_fetcher_thr);

        // voyager handler
        for (int i=0; i<Config::getThreadCount(); ++i) {
            pthread_t voyager_thr;
            if (0 != pthread_create(&voyager_thr, &pthread_attr_norm, voyager_handler, (void*)i)) {
                LOG_CRITICAL("%s: Unable to create voyager_handler thread (%d)!!!", app_name, i);
                abort();
            }
            thrs.push_back(voyager_thr);
        }
    }

    LOG_INFO("%s: Started.", app_name);

    if (Config::bypassARDS()) {
        LOG_WARNING("%s: ARDS bypass is ENABLED!", app_name);
    }

    while (! IS_SHUTDOWN()) {
        sys_msleep(1000);
    }

#if 0
    for (int i=0; i<(int)thrs.size(); ++i) {
        pthread_join(thrs[i], NULL);
    }
#endif

    while (! thrs.empty()) {
        pthread_join(thrs.back(), NULL);
        thrs.pop_back();
    }

    LOG_INFO("%s: Terminated.", app_name);

    /* -- deinitialize queue -- */
    for (int i=0; i<Global::getTransactionQSize(); ++i) {
        c2q_deinit(Global::getTransactionQ(i));
    }
    Global::deinitTransactionQ();

    c2q_deinit(Global::getRequestQ());
    c2q_deinit(Global::getTransactionQ());
    c2q_deinit(Global::getResponseQ());
    c2q_deinit(Global::getGeoProbeQ());
    c2q_deinit(Global::getODSQ());
    c2q_deinit(Global::getCCBQ());
    c2q_deinit(Global::getConditionerQ());
    c2q_deinit(Global::getVoyagerQ());

    /* -- deinitialize log -- */
    LOG_DEINIT();

    return 0;
}
Esempio n. 26
0
int main(int argc, char** argv)
{
	int c;
	char *ubus_socket = UBUS_UNIX_SOCKET;

#ifdef LOG_LEVEL_DEFAULT
	LOG_INIT(APP_NAME, LOG_LEVEL_DEFAULT, STDOUT);
#else
	LOG_INIT(APP_NAME, LR_LOG_INFO, STDOUT);
#endif

	while((c = getopt(argc, argv, "dl:")) != -1)
	{
		switch (c)
		{
			case 'd':
				become_daemon = 0;
				break;
			case 'l':
				{
					char *end;
					long l;
					l = strtoul(optarg, &end, 0);
					if(*optarg == 0 || *end != 0 || l > 10)
					{
						ERROR(DEFAULT_GROUP,"Invalid loglevel %s", optarg);
						exit(1);
					}
					SET_LOG_LEVEL(l);
					break;
				}
			default:
				return -1;
		}
	}

	if(become_daemon){
		LOG_MODE(SYSLOG);
		openlog(APP_NAME, LOG_CONS | LOG_PID, LOG_LOCAL1);
		be_daemon();
	}

	lpd_setup_signals();

	pthread_create(&lpd_thread_id, NULL, (void *)loop_detect_run, NULL);

	if (loop_detect_ubus_init(ubus_socket) < 0) {
		ERROR(DEFAULT_GROUP, "failed to connect to ubus\n");
		return -1;
	}

	
	loop_detect_ubus_run();

	pthread_cancel(lpd_thread_id);
	pthread_join(lpd_thread_id, NULL);

	return 0;


}
Esempio n. 27
0
int main() {
    struct stat st;

    sys_spu_initialize(6, 1);
    cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
    cellSysmoduleLoadModule(CELL_SYSMODULE_IO);

    cellSysutilRegisterCallback(0, sysutil_exit_callback, NULL);
    LOG_INIT();
    LOG_DBG("LOG INIT\n");

    mode_switch = MODE_MENU;

    Graphics = new PS3Graphics();
    LOG_DBG("Graphics->Init()\n");
    Graphics->Init();

    CellInput = new CellInputFacade();
    LOG_DBG("CellInput->Init()\n");
    CellInput->Init();

    oskutil = new OSKUtil();

    // FIXME: Is this necessary?
    if (Graphics->InitCg() != CELL_OK)
    {
        LOG_DBG("Failed to InitCg: %d\n", __LINE__);
        exit(0);
    }

    LOG_DBG("Graphics->InitDbgFont()\n");
    Graphics->InitDbgFont();

    Emulator_ToggleSound();

    emulation_running = true;

    /*
    if (ini_parse("/dev_hdd0/game/GENP00001/USRDIR/GenesisConf.ini", handler, &Iniconfig) < 0)
    {
    	gl_dprintf(0.09f,0.05f,Emulator_GetFontSize(),"Could not load /dev_hdd0/game/GENP00001/GenesisConf.ini\n");
    	sys_timer_sleep(5);
    	gl_dprintf(0.09f,0.05f,Emulator_GetFontSize(),"Now exiting to XMB...\n");
    	sys_timer_sleep(5);
    	sys_process_exit(0);
    }
    */

    //REPLACEMENT
    if (load_settings)
    {
        Emulator_InitSettings();
        load_settings =  false;
    }


    /*
    //main path - Check if not present - create all folders and exit
    if(stat(Iniconfig.rompath,&st) != 0)
    {
    	gl_dprintf(0.09f,0.05f,Emulator_GetFontSize(),"Creating generic folder tree for Genesisplus...\n");
    	sys_timer_sleep(5);
    	CreateFolder(Iniconfig.rompath);
    	CreateFolder(Iniconfig.savpath);
    	CreateFolder(Iniconfig.cartpath);
    	CreateFolder(Iniconfig.sram_path);
    	CreateFolder(Iniconfig.biospath);
    	gl_dprintf(0.09f,0.05f,Emulator_GetFontSize(),"Generic folder tree done! Will now exit to XMB...\nPlease put all your ROMs inside %s\n",Iniconfig.rompath);
    	sys_timer_sleep(5);
    	sys_process_exit(0);
    }
    */

    ////Set Bios
    //sprintf(Iniconfig.biospath,"%s/bios.bin",Iniconfig.biospath);

    while(1)
    {
        switch(mode_switch)
        {
        case MODE_MENU:
            MenuMainLoop();
            break;
        case MODE_EMULATION:
            Emulator_Start();
            CellAudio->pause();
            break;
        case MODE_EXIT:
            Emulator_Shutdown();
        }
    }

    return 0;
}
Esempio n. 28
0
int main (int argc, char *argv[])
{
    char cfg_file[256];
    char app_name[256];
    char* p;

    p = strrchr(argv[0], '/');
    snprintf(app_name, sizeof(app_name), "%s", p+1);

    /* -- get the config filename -- */
    switch (sys_getopt(argc, argv, "c:", cfg_file, sizeof(cfg_file))) {
        case 'c':
#ifdef __DEBUG__
            fprintf(stdout, "config file = [%s]\n", cfg_file);
#endif
            if (0 != Config::load(cfg_file)) {
                fprintf(stderr, "%s: Unable to load config file [%s]!!!\n", app_name, cfg_file);
                exit(-1);
            }
            break;
        default:
            usage(argv[0]);
            exit(0);
    }

    /* -- check if already running -- */
    if (0 != sys_bind(Config::getLockPort())) {
        fprintf(stderr, "%s: Unable to continue, make sure there's no other instance running!!!\n", app_name);
        exit(-1);
    }

    /* -- initialize log -- */
    LOG_INIT(Config::getLogFile(), Config::getLogLevel());

    /* -- check if logger is successfully initialized -- */
    if (0 != LOG_GET_STATUS()) {
        fprintf(stderr, "%s: Unable to initialize logger!\n", app_name);
        exit(-1);
    }

    /* -- initialize libsqlora8 -- */
    if (OraDB::init_lib(true) < 0) {
        LOG_CRITICAL("%s: Unable to initialize libsqlora8!", app_name);
        exit(-1);
    }

    /* -- initialize queue -- */
    if (0 != c2q_init(Global::getNotificationQ())) {
        LOG_CRITICAL("%s: Unable to initialize notification queue!", app_name);
        exit(-1);
    }

    /* -- run in background -- */
    sys_daemon();

    /* -- block all signals -- */
    sys_sigblock();

    // Thread attributes
    pthread_attr_t pthread_attr_norm;
    pthread_attr_init(&pthread_attr_norm);
    pthread_attr_setstacksize(&pthread_attr_norm, Global::thr_stack_size);

    std::vector<pthread_t> thrs;

    // Signal handler
    pthread_t signal_thr;
    if (0 != pthread_create(&signal_thr, &pthread_attr_norm, signal_handler, NULL)) {
        LOG_CRITICAL("%s: Unable to create signal_handler thread!!!", app_name);
        exit(-1);
    }
    thrs.push_back(signal_thr);

    // Notification handler
    for (int i=0; i<Config::getThreadCount(); ++i) {
        pthread_t notification_thr;
        if (0 != pthread_create(&notification_thr, &pthread_attr_norm, notification_handler, (void*)i)) {
            LOG_CRITICAL("%s: Unable to create notification_handler thread (%d)!!!", app_name, i);
            abort();
        }
        thrs.push_back(notification_thr);
    }

    // Notification fetcher
    pthread_t notification_fetcher_thr;
    if (0 != pthread_create(&notification_fetcher_thr, &pthread_attr_norm, notification_fetcher, NULL)) {
        LOG_CRITICAL("%s: Unable to create notification_fetcher thread (%d)!!!", app_name);
        abort();
    }
    thrs.push_back(notification_fetcher_thr);

    LOG_INFO("%s: Started.", app_name);

    while (! IS_SHUTDOWN()) {
        sys_msleep(1000);
    }

#if 0
    for (int i=0; i<(int)thrs.size(); ++i) {
        pthread_join(thrs[i], NULL);
    }
#endif

    while (! thrs.empty()) {
        pthread_join(thrs.back(), NULL);
        thrs.pop_back();
    }

    LOG_INFO("%s: Terminated.", app_name);

    /* -- deinitialize queue -- */
    c2q_deinit(Global::getNotificationQ());

    /* -- deinitialize log -- */
    LOG_DEINIT();

    return 0;
}
Esempio n. 29
0
void commandline_init(void) {
  LOG_INIT();
  current_pos = &current_line[0];
  LOG_INIT_EXIT();
}
Esempio n. 30
0
int havok_convert_main(bx::CommandLine* cmdline)
{
#ifdef HAVOK_COMPILE
    uint32_t timeMS = GetTickCount();

    int err = kErrorSuccess;
    LOG_INIT("HavokConverterLog.html", "Havok Converter");
    MemoryConfig cfg;
    memset(&cfg, 0, sizeof(cfg));
    cfg.m_debugMemSize = SIZE_MB(2);
    cfg.m_initHavok = true;
    cfg.m_havokFrameMemSize = 0;
    cfg.m_havokMonitorMemSize = 0;
    g_memoryMgr.init(cfg);

#ifdef HC_DUMP_PROFILE
    g_profiler.init(64);
#endif

    register_engine_factories();

    g_hc_config = new HC_Config;
    g_hc_config->m_packNormal = cmdline->hasArg("packnormal");
    g_hc_config->m_packUV = cmdline->hasArg("packuv");
    g_hc_config->m_slient = cmdline->hasArg("slient");
    g_hc_config->m_verbose = cmdline->hasArg("verbose");
    g_hc_config->m_merge = !cmdline->hasArg('b');

    Actor_Config config;
    ActorConverter* converter = 0;
    const char* mode = cmdline->findOption('m');
    if(!mode)
        mode = "model";

    const char* class_name = cmdline->findOption('c');
    if(!class_name)
        class_name = "level_geometry";

    const char* input = cmdline->findOption('f');
    const char* output = cmdline->findOption('o');
    if(!input)
    {
        g_hc_config->m_error.add_error("havok convert must specific f args!");
        err = kErrorArg;
        goto error_exit;
    }

    config.m_exportMode = mode;
    config.m_input = input;
    config.m_exportName = getFileName(input);
    config.m_exportFolder = "";
    config.m_rootPath = "";
    config.m_exportClass = class_name;

    if(output)
    {
        std::string output_path = output;
        string_replace(output_path, "\\", "/");
        if (str_begin_with(output_path, "./"))
        {
            output_path = output_path.substr(2, output_path.length() - 2);
        }
        if(!str_begin_with(output_path, INTERMEDIATE_PATH))
            config.m_exportFolder = std::string(INTERMEDIATE_PATH) + output_path;
        else
            config.m_exportFolder = output_path;
        add_trailing_slash(config.m_exportFolder);
        std::string path = config.m_exportFolder;
        string_replace(path, INTERMEDIATE_PATH, "");
        config.m_rootPath = path;
        LOGD("export-folder=%s *********** root-folder=%s", config.m_exportFolder.c_str(), config.m_rootPath.c_str());
    }
    else
    {
        config.m_exportFolder = TEMP_PATH;
    }
    config.m_output = config.m_exportFolder + config.m_exportName + "." + std::string(EngineNames::ACTOR);

    config.m_loader = new hkLoader;
    hkRootLevelContainer* rlc = config.m_loader->load(config.m_input.c_str());
    if (!rlc)
    {
        g_hc_config->m_error.add_error("can not load input havok file %s", config.m_input.c_str());
        err = kErrorLoadHavok;
        goto error_exit;
    }

    config.m_rlc = rlc;
    create_folder(config.m_exportFolder);
    hkxEnvironment* env = LOAD_OBJECT(rlc, hkxEnvironment);
    if(env)
    {
        hkStringBuf env_str;
        env->convertToString(env_str);
        LOGI(env_str.cString());
        config.m_assetFolder = env->getVariableValue("assetFolder");
        config.m_assetPath = env->getVariableValue("assetPath");
    }

    hkaAnimationContainer* ac = LOAD_OBJECT(rlc, hkaAnimationContainer);
    hkxScene* scene = LOAD_OBJECT(rlc,hkxScene);
    hkpPhysicsData* data = LOAD_OBJECT(rlc, hkpPhysicsData);

    config.m_scene = scene;
    config.m_animation = ac;
    config.m_physics = data;

    if(config.m_exportMode == "model")
    {
        if(!scene || !scene->m_rootNode)
        {
            g_hc_config->m_error.add_error("hkx file do not has root scene node.");
            goto error_exit;
        }
        converter = new StaticModelConverter;
        converter->setClass(config.m_exportClass);
    }
    else if(config.m_exportMode == "skin")
    {
        converter = new CharacterConverter;
        converter->setClass("character");
    }
    else if(config.m_exportMode == "level")
    {
        converter = new LevelConverter;
        config.m_output = config.m_exportFolder + config.m_exportName + "." + std::string(EngineNames::LEVEL);
    }
    else if(config.m_exportMode == "animation")
    {
        converter = new AnimationConverter;
        config.m_output = config.m_exportFolder + config.m_exportName + "." + std::string(EngineNames::ANIMATION);
    }
    if(!converter)
    {
        g_hc_config->m_error.add_error("havok converter export mode error.");
        err = kErrorArg;
        goto error_exit;
    }

    converter->m_config = &config;
    converter->setName(config.m_exportName);
    if(config.m_exportMode == "skin")
    {
        converter->process(ac);
    }
    else if(config.m_exportMode == "animation")
    {
        converter->process(ac);
    }
    else
    {
        converter->process(scene);
    }
    converter->postProcess();
    converter->serializeToFile(config.m_output.c_str());

error_exit:
    SAFE_REMOVEREF(converter);
    SAFE_REMOVEREF(config.m_loader);
    if(!g_hc_config->m_slient)
        g_hc_config->m_error.show_error();
    SAFE_DELETE(g_hc_config);

#ifdef HC_DUMP_PROFILE
    g_profiler.dump_to_file("havokconverter_profile.txt", true, true);
    g_profiler.shutdown();
#endif

    g_memoryMgr.shutdown();

    timeMS = GetTickCount() - timeMS;
    LOGD("******************************************************");
    LOGD("******************************************************");
    LOGD("* TOTAL TIME COST = %d[MS]", timeMS);
    LOGD("******************************************************");
    LOGD("******************************************************");

    LOG_TERM();
#endif
	return kErrorSuccess;
}