コード例 #1
0
ファイル: FrontPanelManager.c プロジェクト: githubmc/APIRI
int main( int argc, char * argv[] )
{
	int i;
	int option_index = 0;
	char * filepath  = NULL;
	pthread_t viewport;

	signal( SIGHUP, alldone );
	signal( SIGUSR1, dumpvt );

	while( (i = getopt_long( argc, argv, "f:hv", options, &option_index)) >= 0 ) {
		switch( i ) {
			case 'f':
				if( optarg != NULL )
					filepath  = optarg;
				break;
			case 'h':
			case '?':
			case ':':
				usage( argv[0] );
				break;
			case 'v':
				version( argv[0] );
				break;
			default:
				break;
		}

	}

	if (optind < argc) {
		filepath  = argv[optind++];
	}

	if( (filepath == NULL) || (filepath[0] != '/') ) {
		fprintf( stderr, "%s: No device path specified\n", argv[0] );
		usage( argv[0] );
		exit( 98 );
	}

	if( (fd = open( "/dev/fpm", O_RDWR | O_EXCL )) < 0 ) {
	        perror( argv[0] );
		exit( 97 );
	}

	fprintf( stderr, "%s Ready serial port %s\n", argv[0], filepath );

	//daemon( 1, 1 );

	pthread_create( &viewport, NULL, viewport_listener, filepath );

	sleep( 0 );
	fprintf( stderr, "%s: calling routing()\n", argv[0] );
	routing( fd );

	pthread_join( viewport, NULL );
	fprintf( stderr, "%s: Exiting\n", argv[0] );
	exit( 0 );
}
コード例 #2
0
int RouteCompVC::output_port_cal(Flit flit, int type) {
	int out_state[N_ROUTER_PORTS];
	int out_credit[N_ROUTER_PORTS];
	int out = routing(flit.src_x, flit.src_y, local_x, local_y, flit.dst_x,
			flit.dst_y, out_state,
			out_credit, flit.packet_length);
	return out;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: Rodelbing/IntegratedProject
int main(int argc, char *argv[]) {
	encryptionInit();

	std::thread routing(start, &fwdTable);
	std::thread test(tcpreceive ,6969, std::ref(q), &fwdTable);

	GObject *window;
	GtkBuilder *builder;
	gtk_init (&argc, &argv);
	   //Construct a GtkBuilder instance and load our UI description
	builder = gtk_builder_new ();
	gtk_builder_add_from_file (builder, "builder.ui", NULL);

	window = gtk_builder_get_object (builder, "window");
	g_signal_connect (window, "destroy", G_CALLBACK (End), NULL);

	Button[0] = (GtkButton*) gtk_builder_get_object (builder, "button1");
	Button[1] = (GtkButton*) gtk_builder_get_object (builder, "button2");
	Button[2] = (GtkButton*) gtk_builder_get_object (builder, "button3");
	Button[3] = (GtkButton*) gtk_builder_get_object (builder, "button4");
	Button[4] = (GtkButton*) gtk_builder_get_object (builder, "button5");
	g_signal_connect (Button[0], "clicked", G_CALLBACK (ButtonClick), NULL);
	g_signal_connect (Button[1], "clicked", G_CALLBACK (ButtonClick), NULL);
	g_signal_connect (Button[2], "clicked", G_CALLBACK (ButtonClick), NULL);
	g_signal_connect (Button[3], "clicked", G_CALLBACK (ButtonClick), NULL);
	g_signal_connect (Button[4], "clicked", G_CALLBACK (ButtonClick), NULL);

	Buffer[0] = (GtkTextBuffer*) gtk_builder_get_object(builder, "AllText1");
	Buffer[1] = (GtkTextBuffer*) gtk_builder_get_object(builder, "AllText2");
	Buffer[2] = (GtkTextBuffer*) gtk_builder_get_object(builder, "AllText3");
	Buffer[3] = (GtkTextBuffer*) gtk_builder_get_object(builder, "AllText4");
	Buffer[4] = (GtkTextBuffer*) gtk_builder_get_object(builder, "AllText5");

	InputBar = (GtkEntry*) gtk_builder_get_object (builder, "TextInput");
	ChatText = (GtkTextView*) gtk_builder_get_object (builder, "ChatText");
	g_signal_connect (InputBar, "activate", G_CALLBACK (Printsend), NULL);

	//std::cout << "Destination IP" << std::endl;
	//std::cin >> DestinationIP;
	gtk_main ();
	std::cout << "Say something: " << std::endl;
	while(1){
		Message.clear();
		std::getline(std::cin, Message);
		if (Message.size()==0){
			Message = getIP() + " is connected to you.";
		}
		sendMessage(getIP(), DestinationIP, getNextHop(DestinationIP, fwdTable), encrypt(Message,getReceiverKey(DestinationIP, fwdTable)));
		//string Hoi = encrypt(Message,getPublicKey());
		//std:: cout << Hoi << ", " << decrypt(Hoi, getPublicKey()) << std::endl;
		//std::cout << getNextHop(DestinationIP) << std::endl;
	}

}
コード例 #4
0
ファイル: 1003_2.cpp プロジェクト: hphp/Algorithm
int main()
{
	int request;
	while(scanf("%d%d%d",&n,&m,&request)!=EOF)
	{
		int a,b,c;
		init();
		for(int i=0;i<m;i++)	
		{
			scanf("%d%d%d",&a,&b,&c);
			edge[tt].id=b;
			edge[tt].value=c;
			edge[tt].adj=node[a].adj;
			node[a].adj=&edge[tt];
			tt++;
			edge[tt].id=a;
			edge[tt].value=c;
			edge[tt].adj=node[b].adj;
			node[b].adj=&edge[tt];
			tt++;
		}
		for(int i=1;i<=n;i++)
		{
			if(belong[i]==-1)	
			{
		//		part++;
				root[part]=i;
				dfs(i,0);
				part++;
			}
		}
		for(int i=0;i<part;i++)
		//{
			LCA_deal(i);
			//for(int j=0;j<)
		/*for(int i=1;i<=n;i++)
			printf("%d ",belong[i]);
			printf("\n");*/
		for(int i=0;i<request;i++)
		{
			scanf("%d%d",&a,&b);
			if(belong[a]==belong[b])
			{
				int curlca = routing(a,b);
	//			printf(")
				int ans = tsroot[a]-tsroot[curlca]+tsroot[b]-tsroot[curlca];
				printf("%d\n",ans);
			}
			else printf("Not connected\n");
		}
	}
	return 0;
}
コード例 #5
0
TRouting TUrlRoute::findRouting(Tf::HttpMethod method, const QStringList &components) const
{
    if (_routes.isEmpty()) {
        return TRouting();
    }

    for (const auto &rt : _routes) {
        // Too long or short?
        if (rt.hasVariableParams) {
            if (components.length() < rt.componentList.length() - 1) {
                continue;
            }
        } else {
            if (components.length() != rt.componentList.length()) {
                continue;
            }
        }

        for (int idx : (const QList<int>&)rt.keywordIndexes) {
            if (components.value(idx) != rt.componentList[idx]) {
                goto continue_next;
            }
        }

        if (rt.method == TRoute::Match || rt.method == method) {
            // Generates parameters for action
            QStringList params = components;

            if (params.count() == 1 && params[0].isEmpty()) {  // means path="/"
                params.clear();
            } else {
                // Erases non-parameters
                QListIterator<int> it(rt.keywordIndexes);
                it.toBack();
                while (it.hasPrevious()) {
                    int idx = it.previous();
                    params.removeAt(idx);
                }
            }

            TRouting routing(rt.controller, rt.action, params);
            routing.exists = true;
            return routing;
        }
continue_next:
        continue;
    }

    return TRouting() /* Not found routing info */ ;
}
コード例 #6
0
ファイル: qfrontdesk.cpp プロジェクト: 5in4/QFrontDesk
void QFrontDesk::resolveRoute(QString route, Arguments *arg, QTcpSocket *s) {
    QTextStream os(s);
    os.setAutoDetectUnicode(true);
    //QDataStream os(s);
    QByteArray content;

    // sort out static files
    if(QDir(static_serve_path).exists() && route.split("/").at(1) == QString("static")) {
        QFile static_file(QString("%1/%2").arg(static_serve_path, route.split("/").at(2)));
        if(static_file.exists() && route.split("/").length() == 3) {

            QString mimetype;
            static_file.open(QIODevice::ReadOnly);
            QString file_name = static_file.fileName();
            QString file_suffix = file_name.split(".").last();
            if(file_suffix.isEmpty()) {
                mimetype = QString("text/plain");
            }

            mimetype = (file_suffix == "png") ? "image/png" : "";

            os << QString("HTTP/1.0 200 OK\r\n Content-Type: %1;\r\n\r\n").arg(mimetype);
            os.flush();
            s->write(static_file.readAll());

            static_file.close();

            s->close();
            return;
       }
    } else {
        content.append(routing(route, arg));
    }

   if(content.length() == 0) {
        os << "HTTP/1.0 404 Not Found\r\n Content-Type: text/html;"
              "charset=\"utf-8\"\r\n"
              "\r\n"
              "<!DOCTYPE html><html><h1>404 Not Found</h1><p>The requested URL was not found on this server.";
    } else {
       os << "HTTP/1.0 200 OK\r\n Content-Type: text/html; charset=\"utf-8\"\r\n\r\n";
       os << content;
    }
    s->close();
    return;


}
コード例 #7
0
status_t AudioALSAStreamIn::updateOutputDeviceInfoForInputStream(audio_devices_t output_devices)
{

    ALOGD("+%s(), output_devices: 0x%x => 0x%x", __FUNCTION__, mStreamAttributeTarget.output_devices, output_devices);

    status_t status = NO_ERROR;
    bool bBesRecUpdate = false;
    audio_devices_t inputdevice = mStreamAttributeTarget.input_device;

    if (output_devices != mStreamAttributeTarget.output_devices)
    {
        //only need to modify the input device under VoIP
        if (mStreamAttributeTarget.BesRecord_Info.besrecord_voip_enable == true)
        {
            if (output_devices == AUDIO_DEVICE_OUT_SPEAKER)
            {
                if (inputdevice == AUDIO_DEVICE_IN_BUILTIN_MIC)
                {
                    if (USE_REFMIC_IN_LOUDSPK == 1)
                    {
                        inputdevice = AUDIO_DEVICE_IN_BACK_MIC;
                        ALOGD("%s(), force using back mic", __FUNCTION__);
                    }
                }
            }
        }

        if (inputdevice != mStreamAttributeTarget.input_device)
        {
            //update output devices to input stream info
            ALOGD("%s(), input_device: 0x%x => 0x%x", __FUNCTION__, mStreamAttributeTarget.input_device, inputdevice);
            AudioAutoTimeoutLock _l(mLock);
            mStreamAttributeTarget.output_devices = output_devices;
            routing(inputdevice);
        }
        else    //if no input device update
        {
            //speaker/receiver(headphone) switch no input path change, but should use receiver params
            if (((output_devices == AUDIO_DEVICE_OUT_SPEAKER) && ((mStreamAttributeTarget.output_devices == AUDIO_DEVICE_OUT_EARPIECE) ||
                                                                  (mStreamAttributeTarget.output_devices == AUDIO_DEVICE_OUT_WIRED_HEADPHONE)))
                || (((output_devices == AUDIO_DEVICE_OUT_EARPIECE) || (output_devices == AUDIO_DEVICE_OUT_WIRED_HEADPHONE)) && (mStreamAttributeTarget.output_devices == AUDIO_DEVICE_OUT_SPEAKER)))
            {
                ALOGD("%s(), BesRecord parameters update", __FUNCTION__);
                bBesRecUpdate = true;
            }
            //update output devices to input stream info
            mStreamAttributeTarget.output_devices = output_devices;

            if (bBesRecUpdate)
            {
                //update VoIP parameters config, only streamin has VoIP process
                if ((mStreamAttributeTarget.BesRecord_Info.besrecord_enable == true) && (mStreamAttributeTarget.BesRecord_Info.besrecord_voip_enable == true))
                {
#if defined(NXP_SMARTPA_SUPPORT) && defined(EXTCODEC_ECHO_REFERENCE_SUPPORT)
                    ALOGD("%s(), going to check UpdateBesRecParam", __FUNCTION__);
                    AudioAutoTimeoutLock _l(mLock);
                    if (mStandby == false)
                    {
                        ASSERT(mStreamManager->isModeInPhoneCall() == false);
                        ALOGD("%s(), close handler and reopen it", __FUNCTION__);
                        status = close();
                    }
#else
                    ALOGD("%s(), going to UpdateBesRecParam", __FUNCTION__);
                    AudioAutoTimeoutLock _l(mLock);
                    if (mCaptureHandler != NULL)
                    {
                        mCaptureHandler->UpdateBesRecParam();
                    }
                    else
                    {
                        ALOGD("%s(), mCaptureHandler is destroyed, no need to update", __FUNCTION__);
                    }
#endif
                }
            }
        }

    }
    ALOGD("-%s()", __FUNCTION__);
    return status;

}
コード例 #8
0
ファイル: main.cpp プロジェクト: kotarot/nl-solver
int main(int argc, char *argv[]){
	// Options
	char *in_filename  = NULL; // 問題ファイル名
	char *out_filename = NULL; // 出力解答ファイル名
	char *fix_filename = NULL; // 固定セル情報ファイル名
	int outer_loops = O_LOOP;  // 外ループ回数
	bool fixed = false;        // 固定フラグ

	// Options 取得
	struct option longopts[] = {
		{"loop",     required_argument, NULL, 'l'},
		{"fixfile",  required_argument, NULL, 'x'},
		{"output",   required_argument, NULL, 'o'},
		{"fix-flag", no_argument,       NULL, 'f'},
		{"version",  no_argument,       NULL, 'v'},
		{"help",     no_argument,       NULL, 'h'},
		{0, 0, 0, 0}
	};
	int opt, optidx;
	while ((opt = getopt_long(argc, argv, "l:o:fvh", longopts, &optidx)) != -1) {
		switch (opt) {
			case 'l':
				outer_loops = atoi(optarg);
				break;
			case 'x':
				fix_filename = optarg;
				break;
			case 'o':
				out_filename = optarg;
				break;
			case 'f':
				fixed = true;
				break;
			case 'v':
				version();
			case 'h':
			case ':':
			case '?':
			default:
				usage();
		}
	}
	if (argc <= optind) {
		usage();
	}
	in_filename = argv[optind];
	assert(in_filename != NULL);

	clock_t start_time, finish_time;
	start_time = clock();

	initialize(in_filename); // 問題盤の生成
	printBoard(); // 問題盤の表示
	
	// 固定セルの生成 (機械学習の結果に基づく)
	if (fix_filename != NULL) {
		setFixFlagFromFile(fix_filename);
		printFixFlag();
	}
	// 固定フラグの生成
	else if (fixed) {
		generateFixFlag();
		printFixFlag();
	}
	
	// 乱数の初期化
	mt_init_genrand((unsigned long)time(NULL));
	// ペナルティの初期化
	penalty_T = 0;
	penalty_C = 0;
	
	// 初期ルーティング
	for(int i=1;i<=board->getLineNum();i++){
		// 数字が隣接する場合スキップ
		if(board->line(i)->getHasLine() == false) continue;
		
		if(!routing(i)){
			cerr << "Cannot solve!! (error: 1)" << endl;
			exit(1);
		}
	}
	for(int i=1;i<=board->getLineNum();i++){
		// 数字が隣接する場合スキップ
		if(board->line(i)->getHasLine() == false) continue;
		
		recording(i);
	}
	
	// 中間ポートを利用するか?
	// 利用している間,ライン不通過回数をカウントしない
	bool use_intermediate_port = false;
	// 中間ポートに設定するマスとそれを利用する数字
	int inter_x, inter_y, inter_line = -1;
	
	
	// 探索スタート!!
	for (int m = 2; m <= outer_loops + 1; m++) { // 外ループ
	
		if(!use_intermediate_port){ // 中間ポートを利用しない場合
			if ((m - 1) % 100 == 0) {
				cout << "loop " << (m-1) << endl;
			}
			if(m>INIT){ resetCandidate(); }
		}
		else{ // 中間ポートを利用する場合
			if ((m - 1) % 100 == 0) {
				cout << "loop " << (m-1) << "+" << endl;
			}
		}
		
		// 解導出フラグ
		bool complete = false;
		
		for (int n = 1; n <= I_LOOP; n++) { // 内ループ
			if (INIT < m && !use_intermediate_port){
				checkLineNonPassed();
			}

			// 問題のおいて数字が隣接していないラインを選択する
			int id;
			do {
				id = (int)mt_genrand_int32(1, board->getLineNum());
			} while (board->line(id)->getHasLine() == false);
			//cout << "(" << m << "," << n << ")Re-route Line" << id << endl;

			// 経路の削除
			deleting(id);
			
			// ペナルティの設定
			penalty_T = (int)(NT * (mt_genrand_int32(0, m - 1)));
			penalty_C = (int)(NC * (mt_genrand_int32(0, m - 1)));

			// 中間ポートを利用しない場合
			if ( !((board->line(id))->isIntermediateUsed()) ) {
				// 経路の探索
				if ( !routing(id) ) {
					cerr << "Cannot solve!! (error: 2)" << endl; // 失敗したらプログラム終了
					exit(2);
				}
				// 経路の記録
				recording(id);
			}

			// 中間ポートを利用する場合
			else {
				// 経路の探索 (INTTRY 回)
				bool success = false;
				for (int count = 0; count < INTTRY; count++) {
					if (routingSourceToI(id)) {
						success = routingIToSink(id);
						break;
					}
				}
				// 中間ポート利用に失敗した場合,通常経路探索した後に内ループ脱出
				if ( !success ) {
					if ( !routing(id) ) {
						cerr << "Cannot solve!! (error: 3)" << endl; // 失敗したらプログラム終了
						exit(3);
					}
					recording(id);
					break;
				}
				// 経路の記録
				recording(id);
			}

			// 終了判定(解導出できた場合,正解を出力)
			if(isFinished()){
				finish_time = clock();

				printSolution();
				if (out_filename != NULL) {
					printSolutionToFile(out_filename);
					cout << "--> Saved to " << out_filename << endl << endl;
				}

				cout << "SUMMARY" << endl;
				cout << "-------" << endl;
				cout << " - filename:   " << in_filename << endl;
				cout << " - size:       " << board->getSizeX() << " x " << board->getSizeY() << endl;
				cout << " - iterations: " << (m - 1) << endl;
				cout << " - CPU time:   "
				     << ((double)(finish_time - start_time) / (double)CLOCKS_PER_SEC)
				     << " sec" << endl;

				complete = true;
				break;
			}
		}
		if(complete) break; // 正解出力後は外ループも脱出
		
		// 中間ポートを使用した次のループでは,中間ポートを利用しない
		if(use_intermediate_port){
			use_intermediate_port = false;
			board->line(inter_line)->setIntermediateUnuse();
			continue;
		}
		
		// 不通過マスの調査->中間ポートを利用するか?
		int candidate_count = 0; // 候補数
		inter_x = -1;
		inter_y = -1;
		for(int y=0;y<board->getSizeY();y++){
			for(int x=0;x<board->getSizeX();x++){
				Box* trgt_box = board->box(x,y);
				if(trgt_box->isCandidate()){
					candidate_count++;
					//cout << "(" << x << "," << y << ")"; // 不通過マス
				}
			}
		}
		//cout << endl;
		if(candidate_count==0) continue; // 候補数0なら利用しない
		
		// 候補の中から中間ポートに設定するマスをランダムに選択
		int c_d = (int)mt_genrand_int32(0, candidate_count - 1); // 選択は候補の中で何番目か?
		int n_d = 0; // 何番目なのかをカウントする用の変数
		
		bool flag = false; // 二重ループのためフラグが必要
		for(int y=0;y<board->getSizeY();y++){
			for(int x=0;x<board->getSizeX();x++){
				Box* trgt_box = board->box(x,y);
				if(!trgt_box->isCandidate()){
					continue;
				}
				if(n_d==c_d){
					flag = true;
					inter_x = x; inter_y = y;
					break;
				}
				n_d++;
			}
			if(flag) break;
		}
		
		// 中間ポートの四方を見て,中間ポートを利用する数字をランダムに選択
		checkCandidateLine(inter_x,inter_y); // 候補となるラインを調査
		
		candidate_count = 0; // 候補数
		inter_line = -1;
		for(int i=1;i<=board->getLineNum();i++){
			Line* trgt_line = board->line(i);
			if(trgt_line->isCandidate()){
				candidate_count++;
				//if(candidate_count>1) cout << ", ";
				//cout << i;
			}
		}
		//cout << endl;
		if(candidate_count==0) continue; // 候補数0なら利用しない
		
		c_d = (int)mt_genrand_int32(0, candidate_count - 1); // 選択は候補の中で何番目か?
		n_d = 0; // 何番目なのかをカウントする用の変数
		
		for(int i=1;i<=board->getLineNum();i++){
			Line* trgt_line = board->line(i);
			if(!trgt_line->isCandidate()) continue;
			if(n_d==c_d){
				inter_line = i;
				break;
			}
			n_d++;
		}
		
		//cout << "Set (" << inter_x << "," << inter_y << ") InterPort of Line " << inter_line << endl;
		Line* line_i = board->line(inter_line);
		line_i->setIntermediateUse();
		line_i->setIntermediatePort(inter_x,inter_y);
		use_intermediate_port = true;
		// m--; // 使うかどうか思案中・・・
		
		
		// ペナルティ更新(旧)
		//penalty_T = (int)(NT * m);
		//penalty_C = (int)(NC * m);
	}
	
	
	// 解導出できなかった場合
	if(!isFinished()){
		for(int i=1;i<=board->getLineNum();i++){
			printLine(i);
		}
		cerr << "Cannot solve!! (error: 4)" << endl;
		exit(4);
	}
	
	//デバッグ用
	//for(int y=0;y<board->getSizeY();y++){
		//for(int x=0;x<board->getSizeX();x++){
			//cout << "(" << x << "," << y << ") ";
			//Box* trgt_box = board->box(x,y);
			//cout << " N:" << trgt_box->getNorthNum();
			//cout << " E:" << trgt_box->getEastNum();
			//cout << " S:" << trgt_box->getSouthNum();
			//cout << " W:" << trgt_box->getWestNum();
			//cout << endl;
		//}
	//}
	
	//for(int i=1;i<=board->getLineNum();i++){
	//	calcCost(i);
	//}
	
	delete board;
	return 0;
}