int
SharedMemoryUtils::commitSM()
{

	//mark last msm: isLastNode=1
	boost::interprocess::windows_shared_memory * lastMsm = &(msmList.back());
	boost::interprocess::mapped_region region1(
			*lastMsm,
			boost::interprocess::read_write,
			SMUCONST_MSM_HEADER_ISLAST_OFFSET,
			SMUCONST_MSM_HEADER_ISLAST_SIZE
		);
	char* isLastNodePtr = static_cast<char*>(region1.get_address());
	*isLastNodePtr = '1';


	uint16_t recordNo = processCsmId - 1;

	//set status to (W)orking
	boost::interprocess::mapped_region region3(
		*csm,
		boost::interprocess::read_write,
		SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_STATUS_RECOFFSET,
		SMUCONST_CSM_RECORD_STATUS_SIZE
	);
	char* recordStatusPtr = static_cast<char*>(region3.get_address());
	*recordStatusPtr = 'W';

	return 0;
}
Ejemplo n.º 2
0
void draw(SkCanvas* canvas) {
    auto debugster = [](const char* label, SkRegion& region) -> void {
        auto r = region.getBounds();
        SkDebugf("%14s: {%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom);
    };
    SkRegion region1({1, 2, 3, 4});
    SkRegion region2;
    region1.swap(region2);
    debugster("region1 bounds", region1);
    debugster("region2 bounds", region2);
}
void
SharedMemoryUtils::refreshMsm_Edit(char type, uint64_t mirandaId, std::wstring& displayName)
{
	logger->log_p(L"SharedMemoryUtils.refreshMsm_Edit type=[%c], mirandaId=[%I64u]", type, mirandaId);

	boost::ptr_list<boost::interprocess::windows_shared_memory>::iterator msmListIter;
	for (msmListIter = msmList.begin(); msmListIter != msmList.end(); msmListIter++){

		for (int recordNo = 0; recordNo < SMUCONST_MSM_RECORDS_COUNT; recordNo++ ){

			boost::interprocess::mapped_region region1(
				*msmListIter,
				boost::interprocess::read_only,
				SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_TYPE_RECOFFSET,
				SMUCONST_MSM_RECORD_TYPE_SIZE
			);
			char* recordTypePtr = static_cast<char*>(region1.get_address());

			if (*recordTypePtr == type){

				boost::interprocess::mapped_region region2(
					*msmListIter,
					boost::interprocess::read_only,
					SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_HANDLE_RECOFFSET,
					SMUCONST_MSM_RECORD_HANDLE_SIZE
				);
				uint64_t* agcHandlePtr = static_cast<uint64_t*>(region2.get_address());

				if (*agcHandlePtr == mirandaId){

					boost::interprocess::mapped_region region3(
						*msmListIter,
						boost::interprocess::read_write,
						SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_DNAME_RECOFFSET,
						SMUCONST_MSM_RECORD_DNAME_SIZE
					);
					wchar_t* recordValuePtr = static_cast<wchar_t*>(region3.get_address());
					wcsncpy_s(recordValuePtr, SMUCONST_MSM_RECORD_DNAME_SIZEC, displayName.c_str(), _TRUNCATE);

					logger->log(L"SharedMemoryUtils::refreshMsm_Edit record found and edited");

					// unique record found and edited
					return;
				}

			}

		}

	}

	return;
}
void
SharedMemoryUtils::updateCsmTimestamp(boost::interprocess::windows_shared_memory& updateCsm, uint16_t processCsmId)
{
	uint16_t recordNo = processCsmId - 1;

	boost::interprocess::mapped_region region1(
			updateCsm,
			boost::interprocess::read_write,
			SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_KAT_RECOFFSET,
			SMUCONST_CSM_RECORD_KAT_SIZE
		);
	time_t* recordKatPtr = static_cast<time_t*>(region1.get_address());
	*recordKatPtr = mfGetCurrentTimestamp();

}
QList<Task*> CustomPatternAnnotationTask::onSubTaskFinished(Task* subTask) {
    QList<Task*> subTasks;

    if (!taskFeatureNames.contains(subTask)) {
        return subTasks;
    }

    SArrayBasedFindTask* task = static_cast<SArrayBasedFindTask*> (subTask);
    const QList<int>& results = task->getResults();
    PatternInfo info = taskFeatureNames.take(task);

    qint64 seqLen = dnaObj.getSequenceLength();

    foreach (int pos, results) {
        if (pos > dnaObj.getSequenceLength()) {
            continue;
        }

        int endPos = pos + task->getQuery().length() - 1;

        SharedAnnotationData data(new AnnotationData);
        data->name = info.name;
        U2Strand strand = info.forwardStrand ? U2Strand::Direct : U2Strand::Complementary;
        data->setStrand(strand);

        if (dnaObj.isCircular() && endPos > seqLen) {
            int outerLen = endPos - seqLen;
            int innerLen = task->getQuery().length() - outerLen;
            U2Region region1(pos - 1, innerLen);
            U2Region region2(0, outerLen);
            data->location->regions << region1 << region2;
            data->setLocationOperator(U2LocationOperator_Join);
        } else {
            U2Region region(pos - 1, task->getQuery().length());
            data->location->regions << region;
        }

        annotations.append(data);
    }

    if (taskFeatureNames.isEmpty() && annotations.size() > 0) {
        subTasks.append(new CreateAnnotationsTask(aTableObj, annotations, featureStore->getName()));
    }

    return subTasks;

}
bool
SharedMemoryUtils::isAnyMirandaCsmRecordAvailable(std::wstring& forThisProfileName)
{

	for (int recordNo = 0; recordNo < SMUCONST_CSM_RECORDS_COUNT; recordNo++ ){

		boost::interprocess::mapped_region region1(
			*csm,
			boost::interprocess::read_only,
			SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_STATUS_RECOFFSET,
			SMUCONST_CSM_RECORD_STATUS_SIZE
		);
		char* recordStatusPtr = static_cast<char*>(region1.get_address());

		if (*recordStatusPtr == 'W'){

			boost::interprocess::mapped_region region2(
				*csm,
				boost::interprocess::read_only,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_TYPE_RECOFFSET,
				SMUCONST_CSM_RECORD_TYPE_SIZE
			);
			char* recordTypePtr = static_cast<char*>(region2.get_address());

			if (*recordTypePtr == 'M'){

				boost::interprocess::mapped_region region3(
					*csm,
					boost::interprocess::read_only,
					SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_VISABLETO_RECOFFSET,
					SMUCONST_CSM_RECORD_VISABLETO_SIZE
				);
				wchar_t* recordVisabletoPtr = static_cast<wchar_t*>(region3.get_address());
				std::wstring visableTo = recordVisabletoPtr;

				if (isTokenOnList(forThisProfileName, visableTo)){
					return true;
				}

			}//end if M

		}//end if W

	}//end for

	return false;
}
void
SharedMemoryUtils::refreshMsm_Delete(char type, uint64_t mirandaId)
{
	logger->log_p(L"SharedMemoryUtils.refreshMsm_Delete type=[%c], mirandaId=[%I64u]", type, mirandaId);

	boost::ptr_list<boost::interprocess::windows_shared_memory>::iterator msmListIter;
	for (msmListIter = msmList.begin(); msmListIter != msmList.end(); msmListIter++){

		for (int recordNo = 0; recordNo < SMUCONST_MSM_RECORDS_COUNT; recordNo++ ){

			boost::interprocess::mapped_region region1(
				*msmListIter,
				boost::interprocess::read_write,
				SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_TYPE_RECOFFSET,
				SMUCONST_MSM_RECORD_TYPE_SIZE
			);
			char* recordTypePtr = static_cast<char*>(region1.get_address());

			if (*recordTypePtr == type){

				boost::interprocess::mapped_region region2(
					*msmListIter,
					boost::interprocess::read_only,
					SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_HANDLE_RECOFFSET,
					SMUCONST_MSM_RECORD_HANDLE_SIZE
				);
				uint64_t* agcHandlePtr = static_cast<uint64_t*>(region2.get_address());

				if (*agcHandlePtr == mirandaId){

					*recordTypePtr = 'D'; //[D] deleted - will not be read by other sm clients (even older)

					logger->log(L"SharedMemoryUtils::refreshMsm_Delete record found and deleted");

					// unique record found and edited
					return;
				}

			}

		}

	}

	return;
}
void
SharedMemoryUtils::checkAnotherCsm(boost::interprocess::windows_shared_memory& checkedCsm, uint16_t processCsmId){

	time_t currentTimestamp = mfGetCurrentTimestamp();

	for (uint16_t recordNo = 0; recordNo < SMUCONST_CSM_RECORDS_COUNT; recordNo++ ){

		if (recordNo == processCsmId - 1){ //do not check own record
			continue;
		}

		boost::interprocess::mapped_region region1(
				checkedCsm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_STATUS_RECOFFSET,
				SMUCONST_CSM_RECORD_STATUS_SIZE
			);
		char* recordStatusPtr = static_cast<char*>(region1.get_address());

		if (*recordStatusPtr == 'W'){
			//for every record in status (W) Working

			boost::interprocess::mapped_region region2(
					checkedCsm,
					boost::interprocess::read_write,
					SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_KAT_RECOFFSET,
					SMUCONST_CSM_RECORD_KAT_SIZE
				);
			time_t* recordKatPtr = static_cast<time_t*>(region2.get_address());

			double timeDiff = /*std::*/difftime(currentTimestamp, *recordKatPtr);
			logger->log_p(L"checkAnotherCsm: recordNo=%u (processCsmId=%u) status==W timeDiff=%f", recordNo, recordNo+1, timeDiff);


			if (timeDiff > CSMTHREAD_RECORD_MAXAGE){
				logger->log(L"checkAnotherCsm: free record in CSM");
				freeCsmRecord(checkedCsm, recordNo);
			}


		}//end if

	}//end for

}
Ejemplo n.º 9
0
Blob MomentCalculation2::getMomentsInaBlob(Mat boxImage, Mat cmaskImage, string blobId,string profileId){


	cvtColor(boxImage, boxImage, CV_BGR2HSV);
	//Average
	HumanProportions prop;

	int boxHeight = boxImage.rows;
	double ratio = (double)boxHeight / (double)prop.height;
	int region1Height = (int)(((double)prop.head) * ratio);
	int region2Height = (int)(((double)prop.gait) * ratio);
	int region3Height = (int)(((double)prop.leg)	* ratio);

	string placement = "Top";
	Region region1(placement, 0, 0, region1Height, boxImage.cols);
	MomentCalculation2 mcalc;
	MomentAverage momentAverage1 = mcalc.getAverageColourInConvexRegion(boxImage, cmaskImage, &region1);
	MomentStandardDeviation momentStandardDeviation1 = mcalc.getStandardDeviationInConvexRegion(boxImage, cmaskImage, &region1, &momentAverage1);
	MomentSkewness momentSkewness1 = mcalc.getSkewnessnInConvexRegion(boxImage, cmaskImage, &region1, &momentAverage1);
	region1.setMoments(&momentAverage1, &momentStandardDeviation1, &momentSkewness1);


	placement = "Middle";
	Region region2(placement, 0, 0, region2Height, boxImage.cols);
	MomentAverage momentAverage2 = mcalc.getAverageColourInConvexRegion(boxImage, cmaskImage, &region2);
	MomentStandardDeviation momentStandardDeviation2 = mcalc.getStandardDeviationInConvexRegion(boxImage, cmaskImage, &region2, &momentAverage2);
	MomentSkewness momentSkewness2 = mcalc.getSkewnessnInConvexRegion(boxImage, cmaskImage, &region2, &momentAverage2);
	region2.setMoments(&momentAverage2, &momentStandardDeviation2, &momentSkewness2);

	placement = "Bottum";
	Region region3(placement, 0, 0, region3Height, boxImage.cols);
	MomentAverage momentAverage3 = mcalc.getAverageColourInConvexRegion(boxImage, cmaskImage, &region3);
	MomentStandardDeviation momentStandardDeviation3 = mcalc.getStandardDeviationInConvexRegion(boxImage, cmaskImage, &region3, &momentAverage3);
	MomentSkewness momentSkewness3 = mcalc.getSkewnessnInConvexRegion(boxImage, cmaskImage, &region3, &momentAverage3);
	region3.setMoments(&momentAverage3, &momentStandardDeviation3, &momentSkewness3);


	Blob blob(blobId, boxImage.rows, boxImage.cols);
	blob.human_id_actual = profileId;
	blob.addRegion(&region1);
	blob.addRegion(&region2);
	blob.addRegion(&region3);

	return blob;
}
Ejemplo n.º 10
0
 double Evaluate(double *x) {
   if (x[0] <= p[16]){
     return region1(x[0],p);
   }
   else if (x[0]  <= p[17]){
     return region2(x[0]-p[16],p);
     }
   else if (x[0]  <= p[18]){
     return region3(x[0]-p[17],p);
     }
   else if (x[0]  <= p[19]){
     return region4(x[0]-p[18],p);
   }
   else {
     return region5(x[0]-p[19],p);
   }
   
 }
void
SharedMemoryUtils::initCsm(boost::interprocess::windows_shared_memory& csm)
{

	//save csm header version
	boost::interprocess::mapped_region region1(
			csm,
			boost::interprocess::read_write,
			SMUCONST_CSM_HEADER_VERSION_OFFSET,
			SMUCONST_CSM_HEADER_VERSION_SIZE
		);
	uint32_t* versionPtr = static_cast<uint32_t*>(region1.get_address());
	*versionPtr = SMUCONST_CSM_CURRENT_VERSION;


	//prepare records
	for (uint16_t recordNo = 0; recordNo < SMUCONST_CSM_RECORDS_COUNT; recordNo++ ){

		//save scm record id (=recordNo)
		boost::interprocess::mapped_region region2(
				csm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_RECID_RECOFFSET,
				SMUCONST_CSM_RECORD_RECID_SIZE
			);
		uint16_t* recordIdPtr = static_cast<uint16_t*>(region2.get_address());
		*recordIdPtr = recordNo + 1;

		//save scm record status (=E (Empty))
		boost::interprocess::mapped_region region3(
				csm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_STATUS_RECOFFSET,
				SMUCONST_CSM_RECORD_STATUS_SIZE
			);
		char* recordStatusPtr = static_cast<char*>(region3.get_address());
		*recordStatusPtr = 'E';

	}


}
int
SharedMemoryUtils::checkCsmRecord(boost::interprocess::windows_shared_memory& checkedCsm, uint16_t processCsmId, std::wstring& displayNameProfile)
{
	uint16_t recordNo = processCsmId - 1;

	boost::interprocess::mapped_region region1(
		checkedCsm,
		boost::interprocess::read_write,
		SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_STATUS_RECOFFSET,
		SMUCONST_CSM_RECORD_STATUS_SIZE
	);
	char* recordStatusPtr = static_cast<char*>(region1.get_address());

	if (*recordStatusPtr == 'W'){

		boost::interprocess::mapped_region region2(
			checkedCsm,
			boost::interprocess::read_only,
			SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_DNAME_RECOFFSET,
			SMUCONST_CSM_RECORD_DNAME_SIZE
		);
		wchar_t* displayNamePtr = static_cast<wchar_t*>(region2.get_address());
		std::wstring displayNameSM = displayNamePtr;
		
		if (displayNameSM.compare(displayNameProfile) == 0){
			return 0; //OK
		} else {
			logger->log_p(L"checkCsmRecord not ok for processCsmId = %u: displayNameProfile [%s] doesn't match displayNameSM [%s].", processCsmId, displayNameProfile.c_str(), displayNameSM.c_str());
			return 1; //csm record data corrupted - displayName not match 
		}
		
	} else {

		logger->log_p(L"checkCsmRecord not ok for processCsmId = %u: recordStatus is [%c] expected [W].", processCsmId, *recordStatusPtr);
		return 1; //csm record data corrupted - not in state W

	}

}
int
MessageQueueUtils::createMessageQueue(std::string mqName)
{

	try{

		//TODO access to mqMirSm is not synchronied, i think it's not neccessery
		mqMirSm = new boost::interprocess::windows_shared_memory(
				boost::interprocess::open_or_create,	//TODO what if sm exists
				mqName.c_str(),
				boost::interprocess::read_write,
				getMqMirSmTotalSize()
			);

		logger->log(L"MessageQueueUtils::createMessageQueue  created mq by sm");

	} catch (const boost::interprocess::interprocess_exception& ex) {
		logger->log_p(L"MessageQueueUtils::createMessageQueue interprocess_exception: [%S] native_error=[%d] error_code=[%d]", ex.what(), ex.get_native_error(), ex.get_error_code() );
		return 1; //error
	} catch (...){
		logger->log(L"MessageQueueUtils::createMessageQueue EXCEPTION: unknown");
		return 1; //error
	}

	//initialize
	boost::interprocess::mapped_region region1(
			*mqMirSm,
			boost::interprocess::read_write,
			MQCONST_MQMIRSM_STATUS_OFFSET,
			MQCONST_MQMIRSM_STATUS_SIZE
		);
	char* statusPtr = static_cast<char*>(region1.get_address());
	*statusPtr = 'E';


	return 0; //ok

}
void
MessageQueueUtils::sendMessage(int clientRecordId, char menuItemType, char userActionType, char userButton, uint64_t targetHandle, std::wstring userActionSelection)
{

	logger->log(L"MessageQueueUtils::sendMessage");

	//if text to send is too long
	if (userActionSelection.size() > MQCONST_MQSM_TEXT_SIZEC){
		userActionSelection.resize(MQCONST_MQSM_TEXT_SIZEC - 3);
		userActionSelection.append(TEXT("..."));
	}

	try{

		boost::interprocess::windows_shared_memory* sm = new boost::interprocess::windows_shared_memory(
				boost::interprocess::open_only,
				getMqName(clientRecordId).c_str(),
				boost::interprocess::read_write);

		if (sm == NULL){
			logger->log(L"MessageQueueUtils::sendMessage (sm mode) sm == NULL");
			return; //error
		}


		int counter = 0;
		const int MQ_WAIT_TIME = 200;			//[ms]
		const int MAX_MQ_WAIT_COUNTER = 10;		//10 * 200ms = 2s
		bool sentSuccess = false;

		do {

			counter++;

			WaitForSingleObject(smMutex, INFINITE);


			boost::interprocess::mapped_region region1(
					*sm,
					boost::interprocess::read_write,
					MQCONST_MQMIRSM_STATUS_OFFSET,
					MQCONST_MQMIRSM_STATUS_SIZE
				);
			char* mqmirsmStatusPtr = static_cast<char*>(region1.get_address());

			if (*mqmirsmStatusPtr == 'E'){

				boost::interprocess::mapped_region region2(
						*sm,
						boost::interprocess::read_write,
						MQCONST_MQMIRSM_MENUITEMTYPE_OFFSET,
						MQCONST_MQMIRSM_MENUITEMTYPE_SIZE
					);
				char* menuItemTypePtr = static_cast<char*>(region2.get_address());
				*menuItemTypePtr = menuItemType;


				boost::interprocess::mapped_region region3(
						*sm,
						boost::interprocess::read_write,
						MQCONST_MQMIRSM_USERACTIONTYPE_OFFSET,
						MQCONST_MQMIRSM_USERACTIONTYPE_SIZE
					);
				char* userActionTypePtr = static_cast<char*>(region3.get_address());
				*userActionTypePtr = userActionType;


				boost::interprocess::mapped_region region4(
						*sm,
						boost::interprocess::read_write,
						MQCONST_MQMIRSM_USERBUTTON_OFFSET,
						MQCONST_MQMIRSM_USERBUTTON_SIZE
					);
				char* userButtonPtr = static_cast<char*>(region4.get_address());
				*userButtonPtr = userButton;


				boost::interprocess::mapped_region region5(
						*sm,
						boost::interprocess::read_write,
						MQCONST_MQMIRSM_TARGETHANDLE_OFFSET,
						MQCONST_MQMIRSM_TARGETHANDLE_SIZE
					);
				uint64_t* targetHandlePtr = static_cast<uint64_t*>(region5.get_address());
				*targetHandlePtr = targetHandle;


				boost::interprocess::mapped_region region6(
						*sm,
						boost::interprocess::read_write,
						MQCONST_MQMIRSM_TEXTARRAY_OFFSET,
						MQCONST_MQMIRSM_TEXTARRAY_SIZE
					);
				wchar_t* userActionSelectionPtr = static_cast<wchar_t*>(region6.get_address());
				memset(userActionSelectionPtr, 0, MQCONST_MQMIRSM_TEXTARRAY_SIZE);
				memcpy(userActionSelectionPtr, userActionSelection.c_str(), userActionSelection.length() * sizeof(wchar_t));

				//update shared memory status to Message
				*mqmirsmStatusPtr = 'M';

				sentSuccess = true;

			}
			// else wait and repeat try

			ReleaseMutex(smMutex);

			if (!sentSuccess){
				SleepEx(MQ_WAIT_TIME, TRUE);
			}

		} while (sentSuccess == false && counter <= MAX_MQ_WAIT_COUNTER);

		if (!sentSuccess){
			logger->log(L"MessageQueueUtils::sendMessage (sm mode) - MAX_MQ_WAIT_COUNTER exceeded but still sentSuccess == false");
		}

		delete sm;

	} catch (const boost::interprocess::interprocess_exception& ex) {
		logger->log_p(L"MessageQueueUtils::sendMessage (sm mode) interprocess_exception: [%S] native_error=[%d] error_code=[%d]", ex.what(), ex.get_native_error(), ex.get_error_code() );
		return; //error
	} catch (...){
		logger->log(L"MessageQueueUtils::sendMessage (sm mode) EXCEPTION: unknown");
		return; //error
	}

}
Ejemplo n.º 15
0
int main()
{
    srand(time(NULL));

    int WIDTH(750), HEIGHT(750);
    sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "RTest");
    window.setFramerateLimit(60);

    RegionMap world(100, 80);

    Region *region1(nullptr), *region2(nullptr);
    std::vector<Region*> path;

    double offsetX = 0;
    sf::Vector2i clicPos;

    sf::Transform slide, loopSlide;

    while (window.isOpen())
    {
        sf::Vector2i localPosition = sf::Mouse::getPosition(window);

        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
            else if (event.type == sf::Event::MouseButtonPressed)
            {
                clicPos = localPosition;
            }
        }

        if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            region1 = world.getRegionAt(localPosition.x, localPosition.y);

            int move = localPosition.x-clicPos.x;
            offsetX += move;
            slide.translate(sf::Vector2f(move, 0));

            if (offsetX > 0)
                loopSlide.translate(sf::Vector2f(move-WIDTH, 0));
            else
                loopSlide.translate(sf::Vector2f(move+WIDTH, 0));

            clicPos = localPosition;
        }

        Region* newRegion2 = world.getRegionAt(localPosition.x, localPosition.y);
        if (newRegion2 != region2 && newRegion2)
        {
            region2 = newRegion2;
            path = world.getRoute(region1, region2);
        }

        sf::VertexArray routes(sf::Lines, 0);
        if (path.size())
        {
            for (unsigned int i(0); i<path.size()-1; ++i)
            {
                unsigned int x = path[i]->capital()._x;
                unsigned int y = path[i]->capital()._y;

                sf::Vertex routePoint;
                routePoint.position = sf::Vector2f(x, y);
                routePoint.color    = sf::Color::Red;

                routes.append(routePoint);

                routePoint.position = sf::Vector2f(path[i+1]->capital()._x, path[i+1]->capital()._y);
                routePoint.color    = sf::Color::Red;

                routes.append(routePoint);
            }
        }


        window.clear(sf::Color::White);

        world.render(&window, slide);

        window.draw(routes, slide);
        window.draw(routes, loopSlide);

        window.display();
    }

    return 0;
}
int
SharedMemoryUtils::addRecordToMsm(char type, uint64_t agcHandle, uint64_t accountHandle, uint64_t groupHandle, char status, std::wstring& value)
{

	logger->log_p(L"addRecordToMsm: type=[%c], agcHandle=[%I64u], accountHandle=[%I64u], groupHandle=[%I64u], status=[%c], value=[%s], agcHandle=[%I64u]",
			type, agcHandle, accountHandle, groupHandle, status==NULL?'-':status , value.c_str(), agcHandle);


	//if there is not enought space in current msm - create new one
	if (freeMsmRecordsCount == 0){

		std::size_t msmTotalSize = getMsmTotalSize();
		std::string msmName = getMsmName(processCsmId, nextMsmNumber);

		logger->log_p(L"create new MSM msmName=[%S] " SCNuPTR L" Bytes (schould be 32768 B)",	msmName.c_str(), msmTotalSize);

		boost::interprocess::windows_shared_memory* msm;
		msm = new boost::interprocess::windows_shared_memory(
			boost::interprocess::open_or_create,
			msmName.c_str(),
			boost::interprocess::read_write,
			msmTotalSize
		); //TODO exception handling //TODO delete msm

		//zero shared memory (neccessery if sm was opened(it is old wrong msm from deleted miranda msm record so it contains old bad data))
		boost::interprocess::mapped_region regionToDel(
				*msm,
				boost::interprocess::read_write,
				0,
				msmTotalSize
			);
		memset(regionToDel.get_address(), 0, msmTotalSize);

		//set isLastNodePtr initial value to 0 , will be update at commitCSM()
		boost::interprocess::mapped_region region1(
				*msm,
				boost::interprocess::read_write,
				SMUCONST_MSM_HEADER_ISLAST_OFFSET,
				SMUCONST_MSM_HEADER_ISLAST_SIZE
			);
		char* isLastNodePtr = static_cast<char*>(region1.get_address());
		*isLastNodePtr = '0';

		//TODO - set all records to type 'E'Empty

		msmList.push_back(msm);

		nextMsmNumber++;
		freeMsmRecordsCount = SMUCONST_MSM_RECORDS_COUNT;

	}

	boost::interprocess::windows_shared_memory * currentMsm = &(msmList.back());

	//save data to record
	int actualRecordOffset = SMUCONST_MSM_RECORDS_OFFSET + ((SMUCONST_MSM_RECORDS_COUNT - freeMsmRecordsCount) * SMUCONST_MSM_RECORD_SIZE);

	//char type
	boost::interprocess::mapped_region region1(
		*currentMsm,
		boost::interprocess::read_write,
		actualRecordOffset + SMUCONST_MSM_RECORD_TYPE_RECOFFSET,
		SMUCONST_MSM_RECORD_TYPE_SIZE
	);
	char* recordTypePtr = static_cast<char*>(region1.get_address());
	*recordTypePtr = type;

	//HANDLE agcHandle
	boost::interprocess::mapped_region region2(
		*currentMsm,
		boost::interprocess::read_write,
		actualRecordOffset + SMUCONST_MSM_RECORD_HANDLE_RECOFFSET,
		SMUCONST_MSM_RECORD_HANDLE_SIZE
	);
	uint64_t* agcHandlePtr  = static_cast<uint64_t*>(region2.get_address());
	*agcHandlePtr = agcHandle;

	//HANDLE accountHandle
	boost::interprocess::mapped_region region3(
		*currentMsm,
		boost::interprocess::read_write,
		actualRecordOffset + SMUCONST_MSM_RECORD_ACCOUNTH_RECOFFSET,
		SMUCONST_MSM_RECORD_ACCOUNTH_SIZE
	);
	uint64_t* accountHandlePtr = static_cast<uint64_t*>(region3.get_address());
	*accountHandlePtr = accountHandle;

	//HANDLE groupHandle
	boost::interprocess::mapped_region region4(
		*currentMsm,
		boost::interprocess::read_write,
		actualRecordOffset + SMUCONST_MSM_RECORD_GROUPH_RECOFFSET,
		SMUCONST_MSM_RECORD_GROUPH_SIZE
	);
	uint64_t* groupHandlePtr = static_cast<uint64_t*>(region4.get_address());
	*groupHandlePtr = groupHandle;

	//char status
	boost::interprocess::mapped_region region5(
		*currentMsm,
		boost::interprocess::read_write,
		actualRecordOffset + SMUCONST_MSM_RECORD_STATUS_RECOFFSET,
		SMUCONST_MSM_RECORD_STATUS_SIZE
	);
	char* recordStatusPtr = static_cast<char*>(region5.get_address());
	*recordStatusPtr = status;

	//std::wstring& value
	boost::interprocess::mapped_region region6(
		*currentMsm,
		boost::interprocess::read_write,
		actualRecordOffset + SMUCONST_MSM_RECORD_DNAME_RECOFFSET,
		SMUCONST_MSM_RECORD_DNAME_SIZE
	);
	wchar_t* recordValuePtr = static_cast<wchar_t*>(region6.get_address());
	wcsncpy_s(recordValuePtr, SMUCONST_MSM_RECORD_DNAME_SIZEC, value.c_str(), _TRUNCATE);

	freeMsmRecordsCount --;

	return 0;
}
/**
 * return true if message was received and variables are available
 */
bool
MessageQueueUtils::tryReceiveMessage(char& menuItemType, char& userActionType, char& userButton, uint64_t& targetHandle, wchar_t*& userActionSelection, size_t uasBuffCSize)
{

	try{

		WaitForSingleObject(smMutex, 100000);


		boost::interprocess::mapped_region region1(
				*mqMirSm,
				boost::interprocess::read_write,
				MQCONST_MQMIRSM_STATUS_OFFSET,
				MQCONST_MQMIRSM_STATUS_SIZE
			);
		char* mqmirsmStatusPtr = static_cast<char*>(region1.get_address());

		if (*mqmirsmStatusPtr != 'M'){
			ReleaseMutex(smMutex);
			return false;
		}


		//there is a new message in the queue (sm mode) *mqmirsmStatusPtr=='M'
		//transfer data from shared memory to variables

		boost::interprocess::mapped_region region2(
				*mqMirSm,
				boost::interprocess::read_only,
				MQCONST_MQMIRSM_MENUITEMTYPE_OFFSET,
				MQCONST_MQMIRSM_MENUITEMTYPE_SIZE
			);
		menuItemType = *(static_cast<char*>(region2.get_address()));

		boost::interprocess::mapped_region region3(
				*mqMirSm,
				boost::interprocess::read_only,
				MQCONST_MQMIRSM_USERACTIONTYPE_OFFSET,
				MQCONST_MQMIRSM_USERACTIONTYPE_SIZE
			);
		userActionType = *(static_cast<char*>(region3.get_address()));

		boost::interprocess::mapped_region region4(
				*mqMirSm,
				boost::interprocess::read_only,
				MQCONST_MQMIRSM_USERBUTTON_OFFSET,
				MQCONST_MQMIRSM_USERBUTTON_SIZE
			);
		userButton = *(static_cast<char*>(region4.get_address()));

		boost::interprocess::mapped_region region5(
				*mqMirSm,
				boost::interprocess::read_only,
				MQCONST_MQMIRSM_TARGETHANDLE_OFFSET,
				MQCONST_MQMIRSM_TARGETHANDLE_SIZE
			);
		targetHandle = *(static_cast<uint64_t*>(region5.get_address()));

		boost::interprocess::mapped_region region6(
				*mqMirSm,
				boost::interprocess::read_only,
				MQCONST_MQMIRSM_TEXTARRAY_OFFSET,
				MQCONST_MQMIRSM_TEXTARRAY_SIZE
			);
		wchar_t* userActionSelectionPtr = static_cast<wchar_t*>(region6.get_address());
		wcsncpy_s(userActionSelection, uasBuffCSize, userActionSelectionPtr, MQCONST_MQMIRSM_TEXTARRAY_SIZEC);


		//update shared memory status to Empty
		*mqmirsmStatusPtr = 'E';
		ReleaseMutex(smMutex);

	} catch (const boost::interprocess::interprocess_exception& ex) {
		logger->log_p(L"MessageQueueUtils::tryReceiveMessage interprocess_exception: [%S] native_error=[%d] error_code=[%d]", ex.what(), ex.get_native_error(), ex.get_error_code() );
		return false;
	} catch (...){
		logger->log(L"MessageQueueUtils::tryReceiveMessage EXCEPTION: unknown");
		return false;
	}

	logger->log_p(L"MessageQueueUtils::tryReceiveMessage (mq mode)  RECEIVED DATA:  menuItemType = [%c] userActionType = [%c] userButton = [%c] targetHandle = [%I64u]",
			menuItemType, userActionType, userButton, targetHandle);

	return true;
}
int
SharedMemoryUtils::getClientInstances(boost::ptr_list<ClientInstanceClass> * clientInstancesListPtr, std::wstring& forThisProfileName)
{

	if (clientInstancesListPtr==NULL){
		logger->log(L"SharedMemoryUtils::getClientInstances clientInstancesListPtr==NULL");
		return -1;
	}

	int count = 0;

	for (int recordNo = 0; recordNo < SMUCONST_CSM_RECORDS_COUNT; recordNo++ ){

		boost::interprocess::mapped_region region1(
			*csm,
			boost::interprocess::read_only,
			SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_STATUS_RECOFFSET,
			SMUCONST_CSM_RECORD_STATUS_SIZE
		);
		char* recordStatusPtr = static_cast<char*>(region1.get_address());

		if (*recordStatusPtr == 'W'){

			boost::interprocess::mapped_region region2(
				*csm,
				boost::interprocess::read_only,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_TYPE_RECOFFSET,
				SMUCONST_CSM_RECORD_TYPE_SIZE
			);
			char* recordTypePtr = static_cast<char*>(region2.get_address());

			if (*recordTypePtr == 'M'){

				boost::interprocess::mapped_region region3(
					*csm,
					boost::interprocess::read_only,
					SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_VISABLETO_RECOFFSET,
					SMUCONST_CSM_RECORD_VISABLETO_SIZE
				);
				wchar_t* recordVisabletoPtr = static_cast<wchar_t*>(region3.get_address());
				std::wstring visableTo = recordVisabletoPtr;

				if (isTokenOnList(forThisProfileName, visableTo)){

					//this instance match all conditions
					//get its name and id (recordNo)
					ClientInstanceClass* clientInstance = new ClientInstanceClass();

					boost::interprocess::mapped_region region4(
						*csm,
						boost::interprocess::read_write,
						SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_RECID_RECOFFSET,
						SMUCONST_CSM_RECORD_RECID_SIZE
					);
					uint16_t* recordIdPtr = static_cast<uint16_t*>(region4.get_address());
					clientInstance->recordId = *recordIdPtr;

					boost::interprocess::mapped_region region5(
						*csm,
						boost::interprocess::read_only,
						SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_DNAME_RECOFFSET,
						SMUCONST_CSM_RECORD_DNAME_SIZE
					);
					wchar_t* displayNamePtr = static_cast<wchar_t*>(region5.get_address());
					clientInstance->displayName = displayNamePtr;


					clientInstancesListPtr->push_back(clientInstance);
					count++;

				}

			}//end if M

		}//end if W

	}//end for

	logger->log_p(L"SharedMemoryUtils::getClientInstances return count = %d", count);
	return count;
}
int
SharedMemoryUtils::getAccounts(boost::ptr_list<AccountClass> * accountsListPtr, unsigned short clientRecordNo)
{

	if (accountsListPtr==NULL){
		logger->log(L"SharedMemoryUtils::getAccounts contactsListPtr==NULL");
		return -1;
	}

	bool isMsmAvailable = true;
	int msmNumber = 1;
	std::string msmName;
	boost::interprocess::windows_shared_memory* msm;

	int foundAccountsCount = 0;


	do {

		//get MSM to seek accounts
		msmName = getMsmName(clientRecordNo, msmNumber);
		msmNumber++;

		try {

			msm = new boost::interprocess::windows_shared_memory(
					boost::interprocess::open_only,
					msmName.c_str(),
					boost::interprocess::read_only);

		} catch (const boost::interprocess::interprocess_exception& ex) {
			isMsmAvailable = false;
			logger->log_p(L"SharedMemoryUtils::getAccounts (isMsmAvailable = false) interprocess_exception: [%S] native_error=[%d] error_code=[%d]", ex.what(), ex.get_native_error(), ex.get_error_code() );
		} catch (...){
			isMsmAvailable = false;
			logger->log(L"SharedMemoryUtils::getAccounts (isMsmAvailable = false) EXCEPTION: unknown");
		}
		//TODO problems with this catch


		if(isMsmAvailable){

			for (int recordNo = 0; recordNo < SMUCONST_MSM_RECORDS_COUNT; recordNo++ ){

				boost::interprocess::mapped_region region1(
					*msm,
					boost::interprocess::read_only,
					SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_TYPE_RECOFFSET,
					SMUCONST_MSM_RECORD_TYPE_SIZE
				);
				char* recordTypePtr = static_cast<char*>(region1.get_address());

				if (*recordTypePtr == 'A'){  //Account

					AccountClass* accountInstance = new AccountClass();

					boost::interprocess::mapped_region region2(
						*msm,
						boost::interprocess::read_only,
						SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_DNAME_RECOFFSET,
						SMUCONST_MSM_RECORD_DNAME_SIZE
					);
					wchar_t* displayNamePtr = static_cast<wchar_t*>(region2.get_address());
					accountInstance->displayName = displayNamePtr;

					boost::interprocess::mapped_region region3(
						*msm,
						boost::interprocess::read_only,
						SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_HANDLE_RECOFFSET,
						SMUCONST_MSM_RECORD_HANDLE_SIZE
					);
					uint64_t* agcHandlePtr = static_cast<uint64_t*>(region3.get_address());
					accountInstance->handle = *agcHandlePtr;

					accountsListPtr->push_back(accountInstance);
					foundAccountsCount++;

				}


				//TODO - set all records to type 'E'Empty - if E break for



			} //end for


			//check SMUCONST_MSM_HEADER_ISLAST_OFFSET
			boost::interprocess::mapped_region region4(
				*msm,
				boost::interprocess::read_only,
				SMUCONST_MSM_HEADER_ISLAST_OFFSET,
				SMUCONST_MSM_HEADER_ISLAST_SIZE
			);
			char* isLastNodePtr = static_cast<char*>(region4.get_address());
			if (*isLastNodePtr == '1'){
				isMsmAvailable = false;
				logger->log(L"SharedMemoryUtils::getAccounts - isLastNodePtr - isMsmAvailable = false");
			}


		}// end if

	} while (isMsmAvailable);

	logger->log_p(L"SharedMemoryUtils::getAccounts return foundAccountsCount = %d", foundAccountsCount);

	return foundAccountsCount;
}
Ejemplo n.º 20
0
int GeometryClipmaps::updateLevel( GeometryClipmapLevel& level, 
                                   GeometryClipmapLevel* parentLevel, 
                                   const Pnt2i& newOrigin )
{
    //todo: move this into the GeometryClipmapLevel class??
    // how much samples do we have to update?
    const Pnt2i oldOrigin = level.sampleOrigin;
    const Pnt2i updateSampleCount = newOrigin - oldOrigin;
    
    const bool forceFullUpdate = level.isSampleDataDirty;
    
    if( !forceFullUpdate && oldOrigin == newOrigin )
    {
        // nothing to do:
        return 0;
    }
    
    //SLOG << "Level " << level.index << " moved by " << updateSampleCount << " oldOrigin = " << oldOrigin << " newOrigin = " << newOrigin << "\n";
    
    // whatever we need to do: the origin is now here:
    level.sampleOrigin = newOrigin;
    
    const int levelSampleCount = level.heightmap.size;
    const int levelSampleSpacing = level.sampleSpacing;
    
    const bool fullBlockUpdate = ( abs( updateSampleCount[ 0 ] ) >= levelSampleCount ) || 
        ( abs( updateSampleCount[ 1 ] ) >= levelSampleCount );
    
    int updatedSampleCount = 0;
    
    if( fullBlockUpdate || forceFullUpdate )
    {
        // full block update:
        // reset the block origin:
        level.blockOrigin.setValues( 0, 0 );
        updatedSampleCount += updateLevelBlock( level, 
                                                parentLevel, 
                                                Rectangle2i( 0, 0, levelSampleCount, levelSampleCount ) );
    }
    else if( updateSampleCount[ 0 ] != 0 || updateSampleCount[ 1 ] != 0 )
    {
        Pnt2i levelSampleCount2d( levelSampleCount, levelSampleCount );
        
        // adjust adressing..
        Pnt2i blockDelta = componentDivide( updateSampleCount, levelSampleSpacing );
        
        Pnt2i oldBlockOrigin( level.blockOrigin[ 0 ], level.blockOrigin[ 1 ] );
        
        // update block origin:
        Pnt2i newBlockOrigin = componentModulo( componentAdd( componentAdd( oldBlockOrigin, blockDelta ), levelSampleCount2d ), levelSampleCount2d );
        
        assert( newBlockOrigin[ 0 ] >= 0 );
        assert( newBlockOrigin[ 1 ] >= 0 );
        assert( newBlockOrigin[ 0 ] < levelSampleCount );
        assert( newBlockOrigin[ 1 ] < levelSampleCount );
        
        level.blockOrigin = newBlockOrigin;
        
        // update the dirty Rects:
        // in general the update region is ? shaped: (we do 1 or 2 rectangular updates)
        Rectangle2i region1( 0, 0, levelSampleCount, levelSampleCount );
        Rectangle2i region2( 0, 0, levelSampleCount, levelSampleCount );
        Rectangle2i region3( 0, 0, levelSampleCount, levelSampleCount );
        
        if( blockDelta[ 0 ] > 0 )
        {
            region1._x0 = oldBlockOrigin[ 0 ];
            region1._x1 = region1._x0 + blockDelta[ 0 ];
        }
        else if( blockDelta[ 0 ] < 0 )
        {
            region1._x0 = newBlockOrigin[ 0 ];
            region1._x1 = region1._x0 - blockDelta[ 0 ];
        }
        else
        {
            // region 1 is empty:
            region1.setValues( 0, 0, 0, 0 );
        }
        if( blockDelta[ 1 ] > 0 )
        {
            region2._y0 = oldBlockOrigin[ 1 ];
            region2._y1 = region2._y0 + blockDelta[ 1 ];
        }
        else if( blockDelta[ 1 ] < 0 )
        {
            region2._y0 = newBlockOrigin[ 1 ];
            region2._y1 = region2._y0 - blockDelta[ 1 ];
        }
        else
        {
            // region 1 is empty:
            region2.setValues( 0, 0, 0, 0 );
        }
        
        updatedSampleCount += updateBigLevelBlock( level, parentLevel, region1 );
        updatedSampleCount += updateBigLevelBlock( level, parentLevel, region2 );
    }
    
    // for debugging:
    //checkLevelBlock( level, Rectangle2i( 0, 0, levelSampleCount, levelSampleCount ) );
    
    cpuRenderer_.rebuildIndices( level );       
    
    if( parentLevel )
    {
        // todo: is this really needed every frame?
        cpuRenderer_.rebuildIndices( *parentLevel );
    }
    
    // determine min/max sample:
    level.heightmap.updateMinMaxSamples();
    
    // activate this level:
    level.isActive = true;
    
    // we just updated the data:
    level.isSampleDataDirty = false;
    
    // todo: make this work:
    return updatedSampleCount;
    //return 0;
}
//recordNo === processCsmId -1
void
SharedMemoryUtils::freeCsmRecord(boost::interprocess::windows_shared_memory& csm, uint16_t recordNo)
{

	logger->log_p(L"freeCsmRecord: recordNo = %u processCsmId = %u", recordNo, recordNo+1);

	//zero type
	boost::interprocess::mapped_region region1(
		csm,
		boost::interprocess::read_write,
		SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_TYPE_RECOFFSET,
		SMUCONST_CSM_RECORD_TYPE_SIZE
	);
	char* recordTypePtr = static_cast<char*>(region1.get_address());
	*recordTypePtr = (char)0;

	//zero keepalive timestamp
	boost::interprocess::mapped_region region2(
		csm,
		boost::interprocess::read_write,
		SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_KAT_RECOFFSET,
		SMUCONST_CSM_RECORD_KAT_SIZE
	);
	time_t* recordKatPtr = static_cast<time_t*>(region2.get_address());
	*recordKatPtr = (time_t)0;

	//zero msm timestamp
	boost::interprocess::mapped_region region3(
		csm,
		boost::interprocess::read_write,
		SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_MSMT_RECOFFSET,
		SMUCONST_CSM_RECORD_MSMT_SIZE
	);
	time_t* recordMsmtPtr = static_cast<time_t*>(region3.get_address());
	*recordMsmtPtr = (time_t)0;

	//zero displayname
	boost::interprocess::mapped_region region4(
		csm,
		boost::interprocess::read_write,
		SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_DNAME_RECOFFSET,
		SMUCONST_CSM_RECORD_DNAME_SIZE
	);
	memset(region4.get_address(), 0, SMUCONST_CSM_RECORD_DNAME_SIZE);

	//zero visableto
	boost::interprocess::mapped_region region5(
		csm,
		boost::interprocess::read_write,
		SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_VISABLETO_RECOFFSET,
		SMUCONST_CSM_RECORD_VISABLETO_SIZE
	);
	memset(region5.get_address(), 0, SMUCONST_CSM_RECORD_VISABLETO_SIZE);

	//status = E
	boost::interprocess::mapped_region region6(
		csm,
		boost::interprocess::read_write,
		SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_STATUS_RECOFFSET,
		SMUCONST_CSM_RECORD_STATUS_SIZE
	);
	char* recordStatusPtr = static_cast<char*>(region6.get_address());
	*recordStatusPtr = 'E';
}
/**
 *
 * return
 * >0 - id of assigned record
 * -1 - no empty record found
 */
uint16_t
SharedMemoryUtils::allocateRecordInCsm(boost::interprocess::windows_shared_memory& csm, char type, std::wstring& displayName, std::wstring& visableTo, bool doCommitSM)
{

	//try to find first record with status E (Empty) in CSM
	for (unsigned short recordNo = 0; recordNo < SMUCONST_CSM_RECORDS_COUNT; recordNo++ ){
	
		boost::interprocess::mapped_region region1(
			csm,
			boost::interprocess::read_write,
			SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_STATUS_RECOFFSET,
			SMUCONST_CSM_RECORD_STATUS_SIZE
		);
		char* recordStatusPtr = static_cast<char*>(region1.get_address());
		
		if (*recordStatusPtr == 'E'){

			//save new status 'N' (New)
			*recordStatusPtr = 'N';
		
			//save type
			boost::interprocess::mapped_region region2(
				csm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_TYPE_RECOFFSET,
				SMUCONST_CSM_RECORD_TYPE_SIZE
			);
			char* recordTypePtr = static_cast<char*>(region2.get_address());
			*recordTypePtr = type;
			
			//save first keep alive timestamp
			boost::interprocess::mapped_region region3(
				csm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_KAT_RECOFFSET,
				SMUCONST_CSM_RECORD_KAT_SIZE
			);
			time_t* recordKatPtr = static_cast<time_t*>(region3.get_address());
			*recordKatPtr = mfGetCurrentTimestamp();

			//save version
			boost::interprocess::mapped_region region4(
				csm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_VERSION_RECOFFSET,
				SMUCONST_CSM_RECORD_VERSION_SIZE
			);
			uint16_t* recordVersionPtr = static_cast<uint16_t*>(region4.get_address());
			*recordVersionPtr = SMUCONST_CSM_CURRENT_RECORDVERSION;

			//save display name
			boost::interprocess::mapped_region region5(
				csm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_DNAME_RECOFFSET,
				SMUCONST_CSM_RECORD_DNAME_SIZE
			);
			wchar_t* recordDnamePtr = static_cast<wchar_t*>(region5.get_address());
			wcsncpy_s(recordDnamePtr, SMUCONST_CSM_RECORD_DNAME_SIZEC, displayName.c_str(), _TRUNCATE);

			//save visableTo
			boost::interprocess::mapped_region region6(
				csm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_VISABLETO_RECOFFSET,
				SMUCONST_CSM_RECORD_VISABLETO_SIZE
			);
			wchar_t* recordVisabletoPtr = static_cast<wchar_t*>(region6.get_address());
			wcsncpy_s(recordVisabletoPtr, SMUCONST_CSM_RECORD_VISABLETO_SIZEC, visableTo.c_str(), _TRUNCATE);
		
			//get id
			boost::interprocess::mapped_region region7(
				csm,
				boost::interprocess::read_write,
				SMUCONST_CSM_HEADER_SIZE + (recordNo * SMUCONST_CSM_RECORD_SIZE) + SMUCONST_CSM_RECORD_RECID_RECOFFSET,
				SMUCONST_CSM_RECORD_RECID_SIZE
			);
			uint16_t* recordIdPtr = static_cast<uint16_t*>(region7.get_address());
			

			if (doCommitSM){
				*recordStatusPtr = 'W';
			}

			logger->log_p(L"allocateRecordInCsm: allocated record with id (processCsmId): %u", *recordIdPtr);
			
			return *recordIdPtr;
		
		}//end if
	
	}//end for
	
	logger->log(L"allocateRecordInCsm: no empty records in CSM. return -1");
	return -2;
	
}
Ejemplo n.º 23
0
 double region2(double x, double *p){
   return (p[5]*(x) + p[6]*x*x + region1(p[16],p) );
 }
TEST_F(TestConcurrentCompositeStateNoArgs,MultipleRegions)
{
    typedef TestConcurrentCompositeStateNoArgsMock
            < TestStateMachineNoEventArgsMock
            > ConcurrentCompositeStateMockType;
    ::testing::NiceMock<TestStateMachineNoEventArgsMock> stateMachine;
    ::testing::NiceMock
        < ConcurrentCompositeStateMockType
        > compositeState(&stateMachine);
    ::testing::NiceMock
        < TestRegionNoArgsMock<ConcurrentCompositeStateMockType>
        > region1(&compositeState);
    ::testing::NiceMock
        < TestRegionNoArgsMock<ConcurrentCompositeStateMockType>
        > region2(&compositeState);

    stateMachine.autoFinalize(false);
    compositeState.setRegion(0,&region1);
    compositeState.setRegion(1,&region2);
    stateMachine.initialState(&compositeState);

    // Setup mock call expectations
    //----------------------------------------------------------------------------
    EXPECT_CALL(compositeState,entryImpl(&stateMachine))
        .Times(1);
    EXPECT_CALL(compositeState,startDoImpl(&stateMachine))
        .Times(1);
    EXPECT_CALL(compositeState,endDoImpl(&stateMachine))
        .Times(1);
    EXPECT_CALL(compositeState,exitImpl(&stateMachine))
        .Times(1);

    // Check region calls
    EXPECT_CALL(region1,enterRegionImpl(&compositeState))
        .Times(1);
    EXPECT_CALL(region1,startingRegionThread())
        .Times(1);
    EXPECT_CALL(region1,initializeImpl(_))
        .Times(1);
    EXPECT_CALL(region1,handleEvent1(&compositeState,&region1))
        .Times(1);
    EXPECT_CALL(region1,handleEvent2(&compositeState,&region1))
        .Times(1);
    EXPECT_CALL(region1,handleEvent3(&compositeState,&region1))
        .Times(1);
    EXPECT_CALL(region1,handleEvent4(&compositeState,&region1))
        .Times(1);
    EXPECT_CALL(region1,finalizeImpl(_))
        .Times(1);
    EXPECT_CALL(region1,endingRegionThread())
        .Times(1);
    EXPECT_CALL(region1,exitRegionImpl(&compositeState))
        .Times(1);

    EXPECT_CALL(region2,enterRegionImpl(&compositeState))
        .Times(1);
    EXPECT_CALL(region2,startingRegionThread())
        .Times(1);
    EXPECT_CALL(region2,initializeImpl(_))
        .Times(1);
    EXPECT_CALL(region2,handleEvent1(&compositeState,&region2))
        .Times(1);
    EXPECT_CALL(region2,handleEvent2(&compositeState,&region2))
        .Times(1);
    EXPECT_CALL(region2,handleEvent3(&compositeState,&region2))
        .Times(1);
    EXPECT_CALL(region2,handleEvent4(&compositeState,&region2))
        .Times(1);
    EXPECT_CALL(region2,finalizeImpl(_))
        .Times(1);
    EXPECT_CALL(region2,endingRegionThread())
        .Times(1);
    EXPECT_CALL(region2,exitRegionImpl(&compositeState))
        .Times(1);

    // Run the state machine
    //----------------------------------------------------------------------------

//    STTCL_TEST_LOG_ALL();

//    compositeState.enableLogging(true);
//    innerState.enableLogging(true);

    stateMachine.initialize();
    // Give the region thread(s) a chance to run
    sttcl::internal::SttclThread<>::sleep(sttcl::TimeDuration<>(0,0,0,100));
    stateMachine.triggerEvent1();
    // Give the region thread(s) a chance to run
    sttcl::internal::SttclThread<>::sleep(sttcl::TimeDuration<>(0,0,0,100));
    stateMachine.triggerEvent2();
    // Give the region thread(s) a chance to run
    sttcl::internal::SttclThread<>::sleep(sttcl::TimeDuration<>(0,0,0,100));
    stateMachine.triggerEvent3();
    // Give the region thread(s) a chance to run
    sttcl::internal::SttclThread<>::sleep(sttcl::TimeDuration<>(0,0,0,100));
    stateMachine.triggerEvent4();
    // Give the region thread(s) a chance to run
    sttcl::internal::SttclThread<>::sleep(sttcl::TimeDuration<>(0,0,0,100));
    stateMachine.finalize();
    // Give the region thread(s) a chance to run
    sttcl::internal::SttclThread<>::sleep(sttcl::TimeDuration<>(0,0,0,100));

    EXPECT_TRUE(region1.waitForDoActionExited(sttcl::TimeDuration<>(0,0,0,100),10));

//    STTCL_TEST_LOG_END();
}
Ejemplo n.º 25
0
void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h )
{
    const Position *pPos = getPosition();
    if( !pPos )
        return;

    int width = pPos->getWidth();
    int height = pPos->getHeight();
    if( width <= 0 || height <= 0 )
        return;

    rect region( pPos->getLeft(), pPos->getTop(),
                 pPos->getWidth(), pPos->getHeight() );
    rect clip( xDest, yDest, w, h );
    rect inter;
    if( !rect::intersect( region, clip, &inter ) )
        return;

    if( m_resizeMethod == kScale )
    {
        // Use scaling method
        if( width != m_pImage->getWidth() ||
            height != m_pImage->getHeight() )
        {
            OSFactory *pOsFactory = OSFactory::instance( getIntf() );
            // Rescale the image with the actual size of the control
            ScaledBitmap bmp( getIntf(), *m_pBitmap, width, height );
            delete m_pImage;
            m_pImage = pOsFactory->createOSGraphics( width, height );
            m_pImage->drawBitmap( bmp, 0, 0 );
        }
        rImage.drawGraphics( *m_pImage,
                             inter.x - pPos->getLeft(),
                             inter.y - pPos->getTop(),
                             inter.x, inter.y,
                             inter.width, inter.height );
    }
    else if( m_resizeMethod == kMosaic )
    {
        int xDest0 = pPos->getLeft();
        int yDest0 = pPos->getTop();

        // Use mosaic method
        while( width > 0 )
        {
            int curWidth = __MIN( width, m_pImage->getWidth() );
            height = pPos->getHeight();
            int curYDest = yDest0;
            while( height > 0 )
            {
                int curHeight = __MIN( height, m_pImage->getHeight() );
                rect region1( xDest0, curYDest, curWidth, curHeight );
                rect inter1;
                if( rect::intersect( region1, clip, &inter1 ) )
                {
                    rImage.drawGraphics( *m_pImage,
                                   inter1.x - region1.x,
                                   inter1.y - region1.y,
                                   inter1.x, inter1.y,
                                   inter1.width, inter1.height );
                }
                curYDest += curHeight;
                height -= m_pImage->getHeight();
            }
            xDest0 += curWidth;
            width -= m_pImage->getWidth();
        }
    }
    else if( m_resizeMethod == kScaleAndRatioPreserved )
    {
        int w0 = m_pBitmap->getWidth();
        int h0 = m_pBitmap->getHeight();

        int scaled_height = width * h0 / w0;
        int scaled_width  = height * w0 / h0;

        // new image scaled with aspect ratio preserved
        // and centered inside the control boundaries
        int w, h;
        if( scaled_height > height )
        {
            w = scaled_width;
            h = height;
            m_x = ( width - w ) / 2;
            m_y = 0;
        }
        else
        {
            w = width;
            h = scaled_height;
            m_x = 0;
            m_y = ( height - h ) / 2;
        }

        // rescale the image if size changed
        if( w != m_pImage->getWidth() ||
            h != m_pImage->getHeight() )
        {
            OSFactory *pOsFactory = OSFactory::instance( getIntf() );
            ScaledBitmap bmp( getIntf(), *m_pBitmap, w, h );
            delete m_pImage;
            m_pImage = pOsFactory->createOSGraphics( w, h );
            m_pImage->drawBitmap( bmp, 0, 0 );
        }

        // draw the scaled image at offset (m_x, m_y) from control origin
        rect region1( pPos->getLeft() + m_x, pPos->getTop() + m_y, w, h );
        rect inter1;
        if( rect::intersect( region1, inter, &inter1 ) )
        {
            rImage.drawGraphics( *m_pImage,
                                 inter1.x - pPos->getLeft() - m_x,
                                 inter1.y - pPos->getTop() - m_y,
                                 inter1.x, inter1.y,
                                 inter1.width, inter1.height );
        }
    }
}
Ejemplo n.º 26
0
MVOID HalSensorList::querySensorDrvInfo()
{

    MUINT i = 0, ret = 0;
    MINT sensorDev;

    SensorDrv *const pSensorDrv = SensorDrv::get();

#ifdef MTK_MAIN2_IMGSENSOR
    for (sensorDev = SENSOR_MAIN; sensorDev <= SENSOR_MAIN_2; sensorDev <<= 1) {
#else
#ifdef MTK_SUB_IMGSENSOR
    for (sensorDev = SENSOR_MAIN; sensorDev <= SENSOR_SUB; sensorDev <<= 1) {
#else
    for (sensorDev = SENSOR_MAIN; sensorDev < SENSOR_SUB; sensorDev <<= 1) {
#endif
#endif

        pSensorDrv->init((SENSOR_DEV_ENUM)sensorDev);

        pSensorDrv->getInfo2((SENSOR_DEV_ENUM)sensorDev,&sensorDrvInfo[i]);

        ret = getRawInfo((SENSOR_DEV_ENUM)sensorDev, &sensorRawInfo[i]);

        i++;
        pSensorDrv->uninit();
    }
    querySensorInfo();//to remap data


}


MUINT HalSensorList::getRawInfo(SENSOR_DEV_ENUM sensorDevId, SENSOR_HAL_RAW_INFO_STRUCT *pInfo)
{
    MUINT32 ret = 0;

    SensorDrv *const pSensorDrv = SensorDrv::get();

    switch(sensorDevId) {
    case SENSOR_MAIN:
        pInfo->u1Order = sensorDrvInfo[0].SensorOutputDataFormat;
        break;
    case SENSOR_SUB:
        pInfo->u1Order = sensorDrvInfo[1].SensorOutputDataFormat;
        break;
    case SENSOR_MAIN_2:
        pInfo->u1Order = sensorDrvInfo[2].SensorOutputDataFormat;
        break;
    default:
        break;
    }

    /* Modify getSensorType from getInfo Ioctl to directly compute sensorType from pInfo->u1Order
    //sensorType = pSensorDrv->getCurrentSensorType(sensorDevId);
    */

    // Compute sensorType from SensorOutputDataFormat
    if (pInfo->u1Order >= SENSOR_OUTPUT_FORMAT_RAW_B &&
            pInfo->u1Order <= SENSOR_OUTPUT_FORMAT_RAW_R) {
        pInfo->sensorType = IMAGE_SENSOR_TYPE_RAW;
    }
    else if (pInfo->u1Order >= SENSOR_OUTPUT_FORMAT_RAW8_B &&
             pInfo->u1Order <= SENSOR_OUTPUT_FORMAT_RAW8_R) {
        pInfo->sensorType = IMAGE_SENSOR_TYPE_RAW8;
    }
    else if (pInfo->u1Order >= SENSOR_OUTPUT_FORMAT_UYVY &&
             pInfo->u1Order <= SENSOR_OUTPUT_FORMAT_YVYU) {
        pInfo->sensorType = IMAGE_SENSOR_TYPE_YUV;
    }
    else if (pInfo->u1Order >= SENSOR_OUTPUT_FORMAT_CbYCrY &&
             pInfo->u1Order <= SENSOR_OUTPUT_FORMAT_YCrYCb) {
        pInfo->sensorType = IMAGE_SENSOR_TYPE_YCBCR;
    }
    else {
        MY_LOGE("Unsupport SensorOutputDataFormat \n");
    }

    MY_LOGD("SensorOutputDataFormat: %d, ImageSensor Type: %d\n", pInfo->u1Order, pInfo->sensorType);


    switch (pInfo->sensorType) {
    case IMAGE_SENSOR_TYPE_RAW:
        pInfo->u4BitDepth = 10;
        pInfo->u4IsPacked = 1;
        break;
    case IMAGE_SENSOR_TYPE_RAW8:
        pInfo->u4BitDepth = 8;
        pInfo->u4IsPacked = 1;
        break;
    case IMAGE_SENSOR_TYPE_RAW12:
        pInfo->u4BitDepth = 12;
        pInfo->u4IsPacked = 1;
        break;
    case IMAGE_SENSOR_TYPE_RAW14:
        pInfo->u4BitDepth = 14;
        pInfo->u4IsPacked = 1;
        break;

    case IMAGE_SENSOR_TYPE_YUV:
    case IMAGE_SENSOR_TYPE_YCBCR:
        pInfo->u4BitDepth = 8;
        pInfo->u4IsPacked = 0;
        break;
    case IMAGE_SENSOR_TYPE_RGB565:
        pInfo->u4BitDepth = 8;
        pInfo->u4IsPacked = 0;
        break;
    default:
        MY_LOGE("Unsupport Sensor Type \n");
        break;
    }


    return ret;

}



MVOID HalSensorList::querySensorInfo()
{
    MUINT idx;
    //MUINT32 data1,data2;
    MUINTPTR data1,data2;

    SensorDrv *const pSensorDrv = SensorDrv::get();

#ifdef MTK_MAIN2_IMGSENSOR
    for(idx=0; idx<3; idx++) {
#else
#ifdef MTK_SUB_IMGSENSOR
    for(idx=0; idx<2; idx++) {
#else
    for(idx=0; idx<1; idx++) {
#endif
#endif
        switch (idx) {
        case 0:
            pSensorDrv->init(SENSOR_MAIN);
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_MCLK_CONNECTION, (MUINTPTR)&data1);
            sensorPara[idx].mclkSrc = data1;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_MIPI_SENSOR_PORT, (MUINTPTR)&data1);
            sensorPara[idx].mipiPad = data1;

            sensorStaticInfo[idx].sensorDevID = pSensorDrv->getMainSensorID();
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_SENSOR_ORIENTATION_ANGLE, (MUINTPTR)&data1);
            sensorStaticInfo[idx].orientationAngle = data1;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_SENSOR_FACING_DIRECTION, (MUINTPTR)&data1);
            sensorStaticInfo[idx].facingDirection = data1;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_FAKE_ORIENTATION, (MUINTPTR)&data1);
            sensorStaticInfo[idx].fakeOrientation = data1;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_SENSOR_VIEWANGLE, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].horizontalViewAngle =data1;
            sensorStaticInfo[idx].verticalViewAngle = data2;

            data1 = SENSOR_SCENARIO_ID_NORMAL_PREVIEW;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].previewFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_NORMAL_CAPTURE;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].captureFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_NORMAL_VIDEO;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].videoFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_SLIM_VIDEO1;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video1FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_SLIM_VIDEO2;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM1;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM2;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM3;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM4;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM5;
            pSensorDrv->sendCommand(SENSOR_MAIN, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            pSensorDrv->uninit();
            break;
        case 1:
            pSensorDrv->init(SENSOR_SUB);
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_MCLK_CONNECTION, (MUINTPTR)&data1);
            sensorPara[idx].mclkSrc = data1;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_MIPI_SENSOR_PORT, (MUINTPTR)&data1);
            sensorPara[idx].mipiPad = data1;

            sensorStaticInfo[idx].sensorDevID = pSensorDrv->getSubSensorID();
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_SENSOR_ORIENTATION_ANGLE, (MUINTPTR)&data1);
            sensorStaticInfo[idx].orientationAngle = data1;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_SENSOR_FACING_DIRECTION, (MUINTPTR)&data1);
            sensorStaticInfo[idx].facingDirection = data1;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_FAKE_ORIENTATION, (MUINTPTR)&data1);
            sensorStaticInfo[idx].fakeOrientation = data1;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_SENSOR_VIEWANGLE, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].horizontalViewAngle =data1;
            sensorStaticInfo[idx].verticalViewAngle = data2;

            data1 = SENSOR_SCENARIO_ID_NORMAL_PREVIEW;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].previewFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_NORMAL_CAPTURE;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].captureFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_NORMAL_VIDEO;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].videoFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_SLIM_VIDEO1;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video1FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_SLIM_VIDEO2;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM1;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM2;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM3;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM4;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM5;
            pSensorDrv->sendCommand(SENSOR_SUB, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            pSensorDrv->uninit();
            break;
        case 2:
            pSensorDrv->init(SENSOR_MAIN_2);
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_MCLK_CONNECTION, (MUINTPTR)&data1);
            sensorPara[idx].mclkSrc = data1;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_MIPI_SENSOR_PORT, (MUINTPTR)&data1);
            sensorPara[idx].mipiPad = data1;

            sensorStaticInfo[idx].sensorDevID = pSensorDrv->getMain2SensorID();
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_SENSOR_ORIENTATION_ANGLE, (MUINTPTR)&data1);
            sensorStaticInfo[idx].orientationAngle = data1;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_SENSOR_FACING_DIRECTION, (MUINTPTR)&data1);
            sensorStaticInfo[idx].facingDirection = data1;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_FAKE_ORIENTATION, (MUINTPTR)&data1);
            sensorStaticInfo[idx].fakeOrientation = data1;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_SENSOR_VIEWANGLE, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].horizontalViewAngle =data1;
            sensorStaticInfo[idx].verticalViewAngle = data2;

            data1 = SENSOR_SCENARIO_ID_NORMAL_PREVIEW;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].previewFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_NORMAL_CAPTURE;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].captureFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_NORMAL_VIDEO;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].videoFrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_SLIM_VIDEO1;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video1FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_SLIM_VIDEO2;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM1;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM2;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM3;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM4;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;
            data1 = SENSOR_SCENARIO_ID_CUSTOM5;
            pSensorDrv->sendCommand(SENSOR_MAIN_2, CMD_SENSOR_GET_DEFAULT_FRAME_RATE_BY_SCENARIO, (MUINTPTR)&data1, (MUINTPTR)&data2);
            sensorStaticInfo[idx].video2FrameRate = data2;

            pSensorDrv->uninit();
            break;
        default:
            break;
        }

        switch (sensorRawInfo[idx].sensorType) {
        case IMAGE_SENSOR_TYPE_RAW:
            sensorStaticInfo[idx].sensorType = SENSOR_TYPE_RAW;
            sensorStaticInfo[idx].rawSensorBit = RAW_SENSOR_10BIT;
            break;
        case IMAGE_SENSOR_TYPE_RAW8:
            sensorStaticInfo[idx].sensorType = SENSOR_TYPE_RAW;
            sensorStaticInfo[idx].rawSensorBit = RAW_SENSOR_8BIT;
            break;

        case IMAGE_SENSOR_TYPE_RAW12:
            sensorStaticInfo[idx].sensorType = SENSOR_TYPE_RAW;
            sensorStaticInfo[idx].rawSensorBit = RAW_SENSOR_12BIT;
            break;

        case IMAGE_SENSOR_TYPE_RAW14:
            sensorStaticInfo[idx].sensorType = SENSOR_TYPE_RAW;
            sensorStaticInfo[idx].rawSensorBit = RAW_SENSOR_14BIT;
            break;
        case IMAGE_SENSOR_TYPE_YUV:
        case IMAGE_SENSOR_TYPE_YCBCR:
            sensorStaticInfo[idx].sensorType = SENSOR_TYPE_YUV;
            sensorStaticInfo[idx].rawSensorBit = RAW_SENSOR_ERROR;
            break;
        case IMAGE_SENSOR_TYPE_RGB565:
            sensorStaticInfo[idx].sensorType = SENSOR_TYPE_RGB;
            sensorStaticInfo[idx].rawSensorBit = RAW_SENSOR_ERROR;
            break;
        case IMAGE_SENSOR_TYPE_JPEG:
            sensorStaticInfo[idx].sensorType = SENSOR_TYPE_JPEG;
            sensorStaticInfo[idx].rawSensorBit = RAW_SENSOR_ERROR;
            break;
        default:
            sensorStaticInfo[idx].sensorType = SENSOR_TYPE_UNKNOWN;
            sensorStaticInfo[idx].rawSensorBit = RAW_SENSOR_ERROR;
            break;
        }

        switch (sensorRawInfo[idx].u1Order) {
        case SENSOR_OUTPUT_FORMAT_RAW_B:
        case SENSOR_OUTPUT_FORMAT_RAW8_B:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_RAW_B;
            break;
        case SENSOR_OUTPUT_FORMAT_RAW_Gb:
        case SENSOR_OUTPUT_FORMAT_RAW8_Gb:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_RAW_Gb;
            break;
        case SENSOR_OUTPUT_FORMAT_RAW_Gr:
        case SENSOR_OUTPUT_FORMAT_RAW8_Gr:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_RAW_Gr;
            break;
        case SENSOR_OUTPUT_FORMAT_RAW_R:
        case SENSOR_OUTPUT_FORMAT_RAW8_R:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_RAW_R;
            break;
        case SENSOR_OUTPUT_FORMAT_UYVY:
        case SENSOR_OUTPUT_FORMAT_CbYCrY:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_UYVY;
            break;
        case SENSOR_OUTPUT_FORMAT_VYUY:
        case SENSOR_OUTPUT_FORMAT_CrYCbY:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_VYUY;
            break;
        case SENSOR_OUTPUT_FORMAT_YUYV:
        case SENSOR_OUTPUT_FORMAT_YCbYCr:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_YUYV;
            break;
        case SENSOR_OUTPUT_FORMAT_YVYU:
        case SENSOR_OUTPUT_FORMAT_YCrYCb:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_YVYU;
            break;
        default:
            sensorStaticInfo[idx].sensorFormatOrder = SENSOR_FORMAT_ORDER_NONE;
            break;

        }



        sensorStaticInfo[idx].iHDRSupport = sensorDrvInfo[idx].iHDRSupport;
        sensorStaticInfo[idx].PDAF_Support = sensorDrvInfo[idx].PDAF_Support;
        sensorStaticInfo[idx].previewWidth = sensorDrvInfo[idx].SensorPreviewWidth;
        sensorStaticInfo[idx].previewHeight = sensorDrvInfo[idx].SensorPreviewHeight;
        sensorStaticInfo[idx].captureWidth = sensorDrvInfo[idx].SensorCapWidth;
        sensorStaticInfo[idx].captureHeight = sensorDrvInfo[idx].SensorCapHeight;
        sensorStaticInfo[idx].videoWidth = sensorDrvInfo[idx].SensorVideoWidth;
        sensorStaticInfo[idx].videoHeight = sensorDrvInfo[idx].SensorVideoHeight;
        sensorStaticInfo[idx].video1Width = sensorDrvInfo[idx].SensorVideo1Width;
        sensorStaticInfo[idx].video1Height = sensorDrvInfo[idx].SensorVideo1Height;
        sensorStaticInfo[idx].video2Width = sensorDrvInfo[idx].SensorVideo2Width;
        sensorStaticInfo[idx].video2Height = sensorDrvInfo[idx].SensorVideo2Height;
        sensorStaticInfo[idx].SensorCustom1Width = sensorDrvInfo[idx].SensorCustom1Width;
        sensorStaticInfo[idx].SensorCustom1Height = sensorDrvInfo[idx].SensorCustom1Height;
        sensorStaticInfo[idx].SensorCustom2Width = sensorDrvInfo[idx].SensorCustom2Width;
        sensorStaticInfo[idx].SensorCustom2Height = sensorDrvInfo[idx].SensorCustom2Height;
        sensorStaticInfo[idx].SensorCustom3Width = sensorDrvInfo[idx].SensorCustom3Width;
        sensorStaticInfo[idx].SensorCustom3Height = sensorDrvInfo[idx].SensorCustom3Height;
        sensorStaticInfo[idx].SensorCustom4Width = sensorDrvInfo[idx].SensorCustom4Width;
        sensorStaticInfo[idx].SensorCustom4Height = sensorDrvInfo[idx].SensorCustom4Height;
        sensorStaticInfo[idx].SensorCustom5Width = sensorDrvInfo[idx].SensorCustom5Width;
        sensorStaticInfo[idx].SensorCustom5Height = sensorDrvInfo[idx].SensorCustom5Height;
        sensorStaticInfo[idx].previewDelayFrame = sensorDrvInfo[idx].PreviewDelayFrame;
        sensorStaticInfo[idx].captureDelayFrame = sensorDrvInfo[idx].CaptureDelayFrame;
        sensorStaticInfo[idx].videoDelayFrame = sensorDrvInfo[idx].VideoDelayFrame;
        sensorStaticInfo[idx].video1DelayFrame = sensorDrvInfo[idx].HighSpeedVideoDelayFrame;
        sensorStaticInfo[idx].video2DelayFrame = sensorDrvInfo[idx].SlimVideoDelayFrame;
        sensorStaticInfo[idx].Custom1DelayFrame = sensorDrvInfo[idx].Custom1DelayFrame;
        sensorStaticInfo[idx].Custom2DelayFrame = sensorDrvInfo[idx].Custom2DelayFrame;
        sensorStaticInfo[idx].Custom3DelayFrame = sensorDrvInfo[idx].Custom3DelayFrame;
        sensorStaticInfo[idx].Custom4DelayFrame = sensorDrvInfo[idx].Custom4DelayFrame;
        sensorStaticInfo[idx].Custom5DelayFrame = sensorDrvInfo[idx].Custom5DelayFrame;
        sensorStaticInfo[idx].aeShutDelayFrame = sensorDrvInfo[idx].AEShutDelayFrame;
        sensorStaticInfo[idx].aeSensorGainDelayFrame = sensorDrvInfo[idx].AESensorGainDelayFrame;
        sensorStaticInfo[idx].aeISPGainDelayFrame = sensorDrvInfo[idx].AEISPGainDelayFrame;


        sensorStaticInfo[idx].previewActiveWidth = sensorDrvInfo[idx].SensorEffectivePreviewWidth;//3d use onlyl?
        sensorStaticInfo[idx].previewActiveHeight = sensorDrvInfo[idx].SensorEffectivePreviewHeight;//3d use onlyl?
        sensorStaticInfo[idx].captureActiveWidth = sensorDrvInfo[idx].SensorEffectiveCapWidth;//3d use onlyl?
        sensorStaticInfo[idx].captureActiveHeight = sensorDrvInfo[idx].SensorEffectiveCapHeight;//3d use onlyl?
        sensorStaticInfo[idx].videoActiveWidth = sensorDrvInfo[idx].SensorEffectiveVideoWidth;//3d use onlyl?
        sensorStaticInfo[idx].videowActiveHeight = sensorDrvInfo[idx].SensorEffectiveVideoHeight;//3d use onlyl?
        sensorStaticInfo[idx].previewHoizontalOutputOffset = sensorDrvInfo[idx].SensorPreviewWidthOffset;//3d use onlyl?
        sensorStaticInfo[idx].previewVerticalOutputOffset = sensorDrvInfo[idx].SensorPreviewHeightOffset; //3d use onlyl?
        sensorStaticInfo[idx].captureHoizontalOutputOffset = sensorDrvInfo[idx].SensorCapWidthOffset;//3d use onlyl?
        sensorStaticInfo[idx].captureVerticalOutputOffset = sensorDrvInfo[idx].SensorCapHeightOffset; //3d use onlyl?
        sensorStaticInfo[idx].videoHoizontalOutputOffset = sensorDrvInfo[idx].SensorVideoWidthOffset;//3d use onlyl?
        sensorStaticInfo[idx].videoVerticalOutputOffset = sensorDrvInfo[idx].SensorVideoHeightOffset; //3d use onlyl?
        sensorStaticInfo[idx].virtualChannelSupport = sensorDrvInfo[idx].virtualChannelSupport;
        sensorStaticInfo[idx].iHDR_First_IS_LE = sensorDrvInfo[idx].iHDR_First_IS_LE;
        sensorStaticInfo[idx].SensorModeNum = sensorDrvInfo[idx].SensorModeNum;
    }
    MY_LOGD("MCLK Source: Main = %d, Sub = %d, Main_2 =%d\n",sensorPara[0].mclkSrc,sensorPara[1].mclkSrc,sensorPara[2].mclkSrc);
    MY_LOGD("MIPI pad: Main = %d, Sub = %d, Main_2 =%d\n",sensorPara[0].mipiPad,sensorPara[1].mipiPad,sensorPara[2].mipiPad);
}



MVOID HalSensorList::buildSensorMetadata()
{
    MINT idx;
    MINT64 exposureTime1 = 0x4000;
    MINT64 exposureTime2 = 0x4000;
    MUINT8 u8Para = 0;
    MINT32 s32Para = 0;

    MY_LOGD("impBuildSensorInfo start!\n");

#ifdef MTK_MAIN2_IMGSENSOR
    for(idx=0; idx<3; idx++) {
#else
#ifdef MTK_SUB_IMGSENSOR
    for(idx=0; idx<2; idx++) {
#else
    for(idx=0; idx<1; idx++) {
#endif
#endif

        IMetadata& metadataA = gSensorMetadata[idx];

        {
            IMetadata::IEntry entryA(MTK_SENSOR_EXPOSURE_TIME);
            entryA.push_back(exposureTime1, Type2Type<MINT64>());
            entryA.push_back(exposureTime2, Type2Type<MINT64>());
            metadataA.update(MTK_SENSOR_EXPOSURE_TIME, entryA);
        }


        {   //using full size?
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_ACTIVE_ARRAY_REGION);
            MRect region1(MPoint(sensorStaticInfo[idx].captureHoizontalOutputOffset,sensorStaticInfo[idx].captureVerticalOutputOffset), MSize(sensorStaticInfo[idx].captureWidth,sensorStaticInfo[idx].captureHeight));
            entryA.push_back(region1, Type2Type<MRect>());
            metadataA.update(MTK_SENSOR_INFO_ACTIVE_ARRAY_REGION, entryA);
        }

        {
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT);
            switch(sensorStaticInfo[idx].sensorFormatOrder) {
            case SENSOR_FORMAT_ORDER_RAW_B:
                u8Para = 0x3;//BGGR
                break;
            case SENSOR_FORMAT_ORDER_RAW_Gb:
                u8Para = 0x2;//GBRG
                break;
            case SENSOR_FORMAT_ORDER_RAW_Gr:
                u8Para = 0x1;//GRBG
                break;
            case SENSOR_FORMAT_ORDER_RAW_R:
                u8Para = 0x0;//RGGB
                break;
            default:
                u8Para = 0x4;//BGR not bayer
                break;
            }
            entryA.push_back(u8Para, Type2Type<MUINT8>());
            metadataA.update(MTK_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, entryA);
        }

        {   //need to add query from kernel
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_EXPOSURE_TIME_RANGE);
            entryA.push_back(3000, Type2Type<MINT64>());
            entryA.push_back(3000000000, Type2Type<MINT64>());
            metadataA.update(MTK_SENSOR_INFO_EXPOSURE_TIME_RANGE, entryA);
        }

        {   //need to add query from kernel
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_MAX_FRAME_DURATION);
            entryA.push_back(50000000000, Type2Type<MINT64>());
            metadataA.update(MTK_SENSOR_INFO_MAX_FRAME_DURATION, entryA);
        }

        {   //need to add query from kernel
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_PHYSICAL_SIZE);
            entryA.push_back(5.82, Type2Type<MFLOAT>());
            entryA.push_back(4.76, Type2Type<MFLOAT>());
            metadataA.update(MTK_SENSOR_INFO_PHYSICAL_SIZE, entryA);
        }

        {   //need to add query from kernel
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_PIXEL_ARRAY_SIZE);
            MSize Size1(4000,3000);
            entryA.push_back(Size1, Type2Type<MSize>());
            metadataA.update(MTK_SENSOR_INFO_PIXEL_ARRAY_SIZE, entryA);
        }

        {   //need to add query from kernel
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_WHITE_LEVEL);
            switch (sensorStaticInfo[idx].rawSensorBit) {
            case RAW_SENSOR_8BIT:
                s32Para = 256;
                break;
            case RAW_SENSOR_10BIT:
                s32Para = 1024;
                break;
            case RAW_SENSOR_12BIT:
                s32Para = 4096;
                break;
            case RAW_SENSOR_14BIT:
                s32Para = 16384;
                break;
            default:
                s32Para = 256;
                break;
            }
            entryA.push_back(s32Para, Type2Type<MINT32>());
            metadataA.update(MTK_SENSOR_INFO_WHITE_LEVEL, entryA);
        }

        {
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_ORIENTATION);
            entryA.push_back((MINT32)sensorStaticInfo[idx].orientationAngle, Type2Type<MINT32>());
            metadataA.update(MTK_SENSOR_INFO_ORIENTATION, entryA);
        }

        {
            IMetadata::IEntry entryA(MTK_SENSOR_INFO_PACKAGE);
            {
                IMetadata metadataB;
                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_SCENARIO_ID);
                    entryB.push_back((MINT32)SENSOR_SCENARIO_ID_NORMAL_PREVIEW,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_SCENARIO_ID, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_FRAME_RATE);
                    entryB.push_back((MINT32)sensorStaticInfo[idx].previewFrameRate,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_FRAME_RATE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE);
                    MSize size1(sensorStaticInfo[idx].previewWidth,sensorStaticInfo[idx].previewHeight);
                    entryB.push_back(size1,Type2Type<MSize>());
                    metadataB.update(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY);
                    MRect region1(MPoint(0,0), MSize(sensorStaticInfo[idx].previewWidth,sensorStaticInfo[idx].previewHeight));
                    entryB.push_back(region1,Type2Type<MRect>());
                    metadataB.update(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY, entryB);
                }

                entryA.push_back(metadataB,Type2Type<IMetadata>());
            }

            {
                IMetadata metadataB;
                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_SCENARIO_ID);
                    entryB.push_back((MINT32)SENSOR_SCENARIO_ID_NORMAL_CAPTURE,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_SCENARIO_ID, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_FRAME_RATE);
                    entryB.push_back((MINT32)sensorStaticInfo[idx].captureFrameRate,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_FRAME_RATE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE);
                    MSize size1(sensorStaticInfo[idx].captureWidth,sensorStaticInfo[idx].captureHeight);
                    entryB.push_back(size1,Type2Type<MSize>());
                    metadataB.update(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY);
                    MRect region1(MPoint(0,0), MSize(sensorStaticInfo[idx].captureWidth,sensorStaticInfo[idx].captureHeight));
                    entryB.push_back(region1,Type2Type<MRect>());
                    metadataB.update(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY, entryB);
                }

                entryA.push_back(metadataB,Type2Type<IMetadata>());
            }

            {
                IMetadata metadataB;
                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_SCENARIO_ID);
                    entryB.push_back((MINT32)SENSOR_SCENARIO_ID_NORMAL_VIDEO,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_SCENARIO_ID, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_FRAME_RATE);
                    entryB.push_back((MINT32)sensorStaticInfo[idx].videoFrameRate,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_FRAME_RATE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE);
                    MSize size1(sensorStaticInfo[idx].videoWidth,sensorStaticInfo[idx].videoHeight);
                    entryB.push_back(size1,Type2Type<MSize>());
                    metadataB.update(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY);
                    MRect region1(MPoint(0,0), MSize(sensorStaticInfo[idx].videoWidth,sensorStaticInfo[idx].videoHeight));
                    entryB.push_back(region1,Type2Type<MRect>());
                    metadataB.update(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY, entryB);
                }

                entryA.push_back(metadataB,Type2Type<IMetadata>());
            }

            {
                IMetadata metadataB;
                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_SCENARIO_ID);
                    entryB.push_back((MINT32)SENSOR_SCENARIO_ID_SLIM_VIDEO1,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_SCENARIO_ID, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_FRAME_RATE);
                    entryB.push_back((MINT32)sensorStaticInfo[idx].video1FrameRate,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_FRAME_RATE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE);
                    MSize size1(sensorStaticInfo[idx].video1Width,sensorStaticInfo[idx].video1Height);
                    entryB.push_back(size1,Type2Type<MSize>());
                    metadataB.update(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY);
                    MRect region1(MPoint(0,0), MSize(sensorStaticInfo[idx].video1Width,sensorStaticInfo[idx].video1Height));
                    entryB.push_back(region1,Type2Type<MRect>());
                    metadataB.update(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY, entryB);
                }

                entryA.push_back(metadataB,Type2Type<IMetadata>());
            }

            {
                IMetadata metadataB;
                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_SCENARIO_ID);
                    entryB.push_back((MINT32)SENSOR_SCENARIO_ID_SLIM_VIDEO2,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_SCENARIO_ID, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_FRAME_RATE);
                    entryB.push_back((MINT32)sensorStaticInfo[idx].video2FrameRate,Type2Type<MINT32>());
                    metadataB.update(MTK_SENSOR_INFO_FRAME_RATE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE);
                    MSize size1(sensorStaticInfo[idx].video2Width,sensorStaticInfo[idx].video2Height);
                    entryB.push_back(size1,Type2Type<MSize>());
                    metadataB.update(MTK_SENSOR_INFO_REAL_OUTPUT_SIZE, entryB);
                }

                {
                    IMetadata::IEntry entryB(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY);
                    MRect region1(MPoint(0,0), MSize(sensorStaticInfo[idx].video2Width,sensorStaticInfo[idx].video2Height));
                    entryB.push_back(region1,Type2Type<MRect>());
                    metadataB.update(MTK_SENSOR_INFO_OUTPUT_REGION_ON_ACTIVE_ARRAY, entryB);
                }

                entryA.push_back(metadataB,Type2Type<IMetadata>());
            }
            metadataA.update(MTK_SENSOR_INFO_PACKAGE, entryA);
        }
        metadataA.sort();

    }

    MY_LOGD("impBuildSensorInfo end!\n");


}