/**

The CMsvSendExe::CallMtmL method
Attempts to send the messages in the operation selection

@internalAll
*/
void CMsvSendExe::CallMtmL()
	{
	__ASSERT_DEBUG(iOperations.Count(), gPanic(ENoMessagesInSelection));

	TInt count = iOperations.Count();

	while (count--)
		{
		CMsvSendExeActive& active = *iOperations[count];
		SCHSENDLOG(FLog(iFileName, _L("\tStarting operation for %d msgs (Mtm=%d CommandId=%d)"), active.MsgCount(), active.Mtm().iUid, active.Package().iCommandId));
		active.StartL();
		SCHSENDLOG(FLog(iFileName, _L("\tStarted (Mtm=%d CommandId=%d)"), active.Mtm().iUid, active.Package().iCommandId));
		}

	iStatus = KRequestPending;
	SetActive();
	}
void CMsvSendExe::AddTaskL(const TMsvSchedulePackage& aPackage)
	{
	CMsvEntry* cEntry = NULL;
	TRAPD(err, cEntry = iSession->GetEntryL(aPackage.iId));

	if (err != KErrNotFound)
		{
		User::LeaveIfError(err);
		CleanupStack::PushL(cEntry);

		TMsvEntry entry = cEntry->Entry();
		const TInt sendState = entry.SendingState();

		//Only send the message if sending state is Scheduled or Resend.
		if (entry.Scheduled() && (sendState == KMsvSendStateScheduled || sendState == KMsvSendStateResend))
			{
			entry.SetSendingState(KMsvSendStateWaiting);

			// Fix for DEF000924: Need to be able to send/cancel an sms while another is being sent
			if (entry.iServiceId == KMsvLocalServiceIndexEntryId && entry.iRelatedId != KMsvNullIndexEntryId)
				{
				SCHSENDLOG(  FLog(iFileName, _L("Changing service from %x to %x"), entry.iServiceId, entry.iRelatedId));
				entry.iServiceId = entry.iRelatedId;
				}
			else
				{
				SCHSENDLOG(  FLog(iFileName, _L("Not changing service from %x (related=%x)"), entry.iServiceId, entry.iRelatedId));
				}
			// End of fix

 			cEntry->ChangeL(entry);
			AddTaskL(aPackage, entry.iMtm);
			SCHSENDLOG(FLog(iFileName, _L("\t\tMsg=%d [Mtm=%d SendState=%d]"), aPackage.iId, entry.iMtm.iUid, entry.SendingState()));
			}
		else
			{
			SCHSENDLOG(FLog(iFileName, _L("\t\tIGNORING Msg=%d (Mtm=%d SendState=%d Scheduled=%d)"), aPackage.iId, entry.iMtm.iUid, sendState, entry.Scheduled()));
			}

		CleanupStack::PopAndDestroy(cEntry);
		}
	else
		{
		SCHSENDLOG(FLog(iFileName, _L("\t\tIGNORING Msg=%d: NOT FOUND"), aPackage.iId));
		}
	}
Exemple #3
0
void FEngine::initializeEngine(std::string windowName, unsigned short int width, unsigned short int height)
{
	FLog(FLog::INFO, "Initializing engine components...");

	//Create the resource manager
	_FResourceManagerPtr = new FResourceManager();
	//Create the timer manager
	_timerManagerPtr = new TimerManager();
	//Create the world manager
	_FWorldPtr = new FWorld();
	//Create the main render window.
	_mainRenderWindowPtr = new RenderWindow(windowName, width, height);
	//Create the Input Manager Singleton
	_inputManagerPtr = new FInputManager();

	FLog(FLog::INFO, "Engine components initialized");
}
Exemple #4
0
RenderWindow::RenderWindow(std::string windowName, unsigned short int width, unsigned short int height)
	:_windowName(windowName),
	_width(width),
	_height(height),
	_viewportDisplayed(NULL)
{
	FLog(FLog::INFO, "Initializing SDL and GL context. Creating main window");

	//Init SDL and GLEW
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		FLog(FLog::FAILURE, "Unable to initialize SDL");
	}

	//create the window
	_SDLWindow = SDL_CreateWindow(windowName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _width, _height, SDL_WINDOW_OPENGL);
	//create the opengl context
	_SDL_GL_Context = SDL_GL_CreateContext(_SDLWindow);

	// Set OPENGL attributes
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetSwapInterval(0); //Disable VSync

	glewExperimental = GL_TRUE;
	glewInit();

	//GET INFO
	const char* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
	const char* version = reinterpret_cast<const char*>(glGetString(GL_VERSION));
	const char* renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
	const char* glslVersion = reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION));
	std::cout << "OpenGL " << version << " initialized." << std::endl;
	std::cout << "(" << vendor << "; " << renderer << ")" << std::endl;
	std::cout << "GLSL version: " << glslVersion << std::endl;

	//Create the world renderer
	_rendererPtr = new FRenderer(_width, _height);
}
/**
Delete the schedules for the specified messages from the task scheduler. 

The messages themselves are not deleted.

@param aSelection 
Array of message IDs that need to be deleted from the task scheduler.

@leave Any error code
Unable to connect and register with the scheduler.

@leave Any error code but KErrLocked and KErrNotFound
The method overloading CMsvScheduledEntry::GetMessageL() left with an error,
i.e. the scheduling info of one of the messages from the selection could not
be retrieved from the message server.

@leave Any error code
Unable to reset the previous scheduling info for a message.
*/
EXPORT_C void CMsvScheduleSend::DeleteScheduleL(const CMsvEntrySelection& aSelection)
	{
	ConnectAndRegisterL();

	GetMessagesL(aSelection);

	TInt entryCount = iSchEntries->Count();
	SCHSENDLOG(FLog(_L8("Asked to delete schedule of %d msgs"), entryCount));

	while (entryCount--)
		{
		CMsvScheduledEntry* message = iSchEntries->At(entryCount);
		SCHSENDLOG(FLog(_L8("\tDelete schedule for msg %d (mtm %d, oldSendState %d, newSendState %d)"), message->Id(), message->Mtm().iUid, message->SendingState(), KMsvSendStateSuspended));
		message->SetSendingState(KMsvSendStateSuspended);
		DeleteScheduleForEntryL(*message);
		ResetScheduleInfoForEntryL(*message, ETrue);
		}
	}
/**

The CMsvSendExe::DoCancel method
Cancels all outstanding operations and stops the active scheduler.

@return			
@internalAll
*/
void CMsvSendExe::DoCancel()
	{
	SCHSENDLOG(FLog(iFileName, _L("\tOperations cancelled"), iStatus.Int()));

	TInt count = iOperations.Count();
	while (count--)
		iOperations[count]->Cancel();

	iActiveSchedulerWait.AsyncStop();
	}
/** 
Determines when the messages should be re-scheduled on the task scheduler, 
then schedules the messages at the new time(s).

Messages that are successfully re-scheduled are updated. The pending conditions
flag indicates whether the message has been schedule for a set of conditions 
being met (or a timeout occuring) or scheduled for a specified time/date.

NOTE - conditions scheduling is only supoprted from 8.1 onwards.

In the case of time-scheduling, the date field is the scheduled time/date. In 
the case of conditions-scheduling, the date field reflects the timeout value.

There are several cases when messages are not re-scheduled. If all recipients 
have been sent to - in this case the message's sending state set to 
KMsvSendStateSent. If, more commonly, the message's maximum number of re-tries
has been exceeded or the error action was ESendActionFail then the message is 
not changed.

@param aSelection 
Array of message IDs that need to be re-scheduled. This array cannot be empty. 
All the messages identified must belong to the same MTM. It is not a 
precondition that each message has already been scheduled on the task 
scheduler.

@param aPackage
Scheduling options.

@param aErrorAction
The specific action to take with the messages. If this argument is omitted, 
then ReScheduleL() uses the iError member of each TMsvEntry to find the 
related TMsvSendErrorAction in iErrorActions.

@panic ScheduleSend-DLL 0
The array of message IDs is empty.
Debug build only.
*/
EXPORT_C void CMsvScheduleSend::ReScheduleL(const CMsvEntrySelection& aSelection, const TMsvSchedulePackage& aPackage, const TMsvSendErrorAction* aErrorAction)
	{
	__ASSERT_DEBUG(aSelection.Count() > 0, gPanic(EMessageSelectionEmpty));
	iPackage = aPackage;
	GetMessagesL(aSelection);

	TInt entryCount = iSchEntries->Count();
	SCHSENDLOG(FLog(_L8("Asked to re-schedule %d msgs"), entryCount));

	if (entryCount)
		{
		TTime curTime;
		curTime.UniversalTime();
		curTime += iSettings->Latency();

		while (entryCount--)
			{
			CMsvScheduledEntry* message = iSchEntries->At(entryCount);
	
			SCHSENDLOG(FLog(_L8("\tAttempting to Re-Schedule msg %d"), message->Id()));

			if (!SetMessageStartTime(*message, curTime, aErrorAction))
				{
				SCHSENDLOG(FLog(_L8("\t\tCannot Re-Schedule msg %d (new sending state %d)"), message->Id(), message->SendingState()));
				DeleteScheduleForEntryL(*message);
				ResetScheduleInfoForEntryL(*message, ETrue);
				delete message;
				iSchEntries->Delete(entryCount);
				}
			}

		//Send the messages if there are any left to send
		if (iSchEntries->Count())
			{
			DoReScheduleL(*iSchEntries);
			}
		else
			{
			SCHSENDLOG(FLog(_L8("\tNo messages to Re-Schedule")));
			}
		}
	}
Exemple #8
0
// sent float value
void Shader::uniform(const std::string& uniformName, GLfloat value)
{
	GLuint id = glGetUniformLocation(_program, uniformName.c_str());
	if (id == -1)
	{
		#ifdef DEBUG_SHADERS
		FLog(FLog::WARNING, _name + " Couldn't get uniform location of " + uniformName);
		#endif
	}

	glUniform1fARB(id, value);
}
Exemple #9
0
void Shader::uniformMatrix(const std::string & uniformName, const Matrix4& value)
{
	GLuint id = glGetUniformLocation(_program, uniformName.c_str());
	if (id == -1)
	{
		#ifdef DEBUG_SHADERS
		FLog(FLog::WARNING, _name + " Couldn't get uniform location of " + uniformName);
		#endif
	}

	glUniformMatrix4fvARB(id, 1, false, value.getValuePtr());
}
void CMsvScheduleSend::CreateScheduleL(const TTime& aTime, const TTimeIntervalMinutes& aValidityPeriod, const CArrayFixFlat<TTaskSchedulerCondition>& aSchConditions, TBool aPendingConditions, TSchedulerItemRef& aRef)
	{
	if( aPendingConditions )
		{
		CreateScheduleL(iScheduler, aSchConditions, aTime, aRef);
	#ifndef _MSG_NO_LOGGING
		TBuf<32> bufDate;
		aTime.FormatL(bufDate, _L("%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%.%*C4%:3%+B"));
		SCHSENDLOG(FLog(_L("\tCreated Schedule %d for pending %d conditions or %S"), aRef.iHandle, aSchConditions.Count(), &bufDate));
	#endif		
		}
	else
		{		
		CreateScheduleL(iScheduler, *iSettings, aTime, aValidityPeriod, aRef);
	#ifndef _MSG_NO_LOGGING
		TBuf<32> bufDate;
		aTime.FormatL(bufDate, _L("%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%.%*C4%:3%+B"));
		SCHSENDLOG(FLog(_L("\tCreated Schedule %d for %S"), aRef.iHandle, &bufDate));
	#endif
		}
	}
void FCameraManager::addMovementToViewportCamera(const Vector3 &delta)
{
	if (_viewportCamera)
	{
		_viewportCamera->translate(_viewportCamera->getWorldRotationQuaternion() * Vector3(delta.x, delta.y, -delta.z));
	}
	else
	{
		FLog(FLog::FAILURE, "There is no Viewport Camera set");
		assert(0);
	}
}
Exemple #12
0
FUIFrame* FUIManager::getUIFrame(std::string frameName)
{
	auto it = _framesMap.find(frameName);
	if (it != _framesMap.end())
	{
		return it->second;
	}
	else
	{
		FLog(FLog::WARNING, "Can't return the FUIFrame, it doesn't exists: %s", frameName.c_str());
		return NULL;
	}
}
FCameraComponent* const FCameraManager::getViewportCamera() const
{
	if (_viewportCamera)
	{
		return _viewportCamera;
	}
	else
	{
		FLog(FLog::FAILURE, "There is no Viewport Camera set");
		assert(0);
		return NULL;
	}
}
Exemple #14
0
// sent texture value
void Shader::uniformTexture(const std::string& uniformName, GLint activeTextureSlot)
{
	//glActiveTexture(GL_TEXTURE0+slot);
	GLuint id = glGetUniformLocation(_program, uniformName.c_str());
	if (id == -1)
	{
		#ifdef DEBUG_SHADERS
		FLog(FLog::WARNING, _name + " Couldn't get uniform location of " + uniformName);
		#endif
	}


	glUniform1i(id, activeTextureSlot);
}
void CMsvSendExe::CompleteReschedule(RScheduler& aScheduler, const TSchedulerItemRef& aRef, TInt aCount)
	{
	if (aCount != 0)
		{
		aScheduler.EnableSchedule(aRef.iHandle);
		}
	else if (aRef.iHandle != KErrNotFound)
		{
		aScheduler.DeleteSchedule(aRef.iHandle);
		}
	aScheduler.Close();

	SCHSENDLOG(FLog(iFileName, _L("\tCompleteReschedule [Ref=%d OutCount=%d]"), aRef.iHandle, aCount));
	}
Exemple #16
0
void FUIManager::deleteUIFrame(std::string frameName)
{
	auto it = _framesMap.find(frameName);
	if (it == _framesMap.end())
	{
		FLog(FLog::FAILURE, "Can't delete the FUIFrame, it doesn't exists: %s", frameName.c_str());
		assert(0);
	}
	else
	{
		delete it->second;
		_framesMap.erase(it);
	}
}
Exemple #17
0
void FEngine::runEngine()
{
	//Start the frame timer (this will give the tick to the timermanager
	unsigned int frameStartTime = 0;
	int frames = 0;
	int elapsedTime = 0;
	int deltaTime = 0;

	//Main game loop
	while (_engineRunning)
	{
		//Poll Hardware input event each frame
		_inputManagerPtr->pollInputEvents();

		frameStartTime = _timerManagerPtr->getTotalExecutionTime();

		//Update timers
		_timerManagerPtr->tick(deltaTime);
		//Tick the world. This will tick all the Actors and components if activated
		_FWorldPtr->tick(deltaTime);

		//Render the world and Swap the buffers
		_mainRenderWindowPtr->swapBuffers();

		//Frames management
		deltaTime = _timerManagerPtr->getTotalExecutionTime() - frameStartTime;
		if (deltaTime < 1000 / 60.0f)
		{
			SDL_Delay(1000 / 60.0f - deltaTime);

			deltaTime = 1000 / 60.0f;
		}

		elapsedTime += deltaTime;
		frames++;

		if (elapsedTime >= 1000)
		{
			FLog(FLog::INFO, "Frames per second: %d", frames);

			elapsedTime = 0;
			frames = 0;
		}
	}
}
void CMsvSendExe::ProcessFileL()
/*
	ProcessFileL
*/
	{
	RetrievePackagesL();
	RetrieveMessagesL();

	if (iOperations.Count())
		{
		CallMtmL();
		iActiveSchedulerWait.Start();
		}
	else
		{
		SCHSENDLOG(FLog(iFileName, _L("\tNO msg to send!")));
		}
	}
Exemple #19
0
	void GAME_Startup(int argc, char **argv)
	{

		Properties = Config.ReadAll("Config.xml");
		Window_Setup();

		glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
		glutInitWindowPosition(100,100);

		glutInitWindowSize(Window.m_iHeight,Window.m_iWidth);
		Window.m_hHandle = glutCreateWindow(Properties.Getstr("Title"));

		// OpenGL init
		glEnable(GL_DEPTH_TEST);
		FLog("OpenGL Version: "+(string)((char*)glGetString(GL_VERSION)),true);
		glewInit();

	}
TBool CMsvScheduleSend::TaskAndMessageMatchL(const CMsvScheduledEntry& aMessage)
	{
	TMsvId id = 0;
	TRAPD(err, id = GetMessageIdForTaskL(aMessage.iData.iTaskId));

	SCHSENDLOG(FLog(_L8("\tGetMessageIdForTask [taskId=%d err=%d id=%d aMessage.Id=%d"), aMessage.iData.iTaskId, err, id, aMessage.Id()));
	TBool match = EFalse;
 
	if (err == KErrNone)
		{
		match = (id == aMessage.Id());
		}
	else if (err != KErrNotFound)
		{
		User::Leave(err);
		}
 
	return match;
	}
Exemple #21
0
void RenderWindow::swapBuffers()
{
	//Gl enables
	//glEnable(GL_SCISSOR_TEST);
	glEnable(GL_DEPTH_TEST);
	
	if (_viewportDisplayed)
	{
		_viewportDisplayed->updateViewport();
	}
	else
	{
		FLog(FLog::FAILURE, "No viewport available. You must create a viewport first");
		assert(0);
	}

	_rendererPtr->renderObjectsInTheWorld();

	SDL_GL_SwapWindow(_SDLWindow);
}
void CMsvSendExe::DoResheduleOnErrorL(RScheduler& aScheduler, const CMsvEntrySelection& aSelection, const TMsvSchedulePackage& aPackage, TInt aError, TSchedulerItemRef& aRef, TInt& aCount, TTime& aStartTime)
	{
	SCHSENDLOG(FLog(iFileName, _L("\tDoRescheduleOnError [aError=%d]"), aError));

	CMsvScheduleSettings* settings = CMsvScheduleSettings::NewL();
	CleanupStack::PushL(settings);

	TMsvSchedulePackage package(aPackage);
	TInt selCount = aSelection.Count();
	TTaskInfo info;
	TInt err = KErrNone;

	//Schedule each message
	while (selCount--)
		{
		const TMsvId id = aSelection[selCount];

		TBool scheduleMessage = ETrue;
		CMsvEntry* cEntry = NULL;
		TMsvEntry entry;

		if (iSession != NULL)
			TRAP(err, cEntry = iSession->GetEntryL(id));

		SCHSENDLOG(FLog(iFileName, _L("\t\tScheduling Task [Id=%d Err=%d iSession=0x%X cEntry=0x%X]..."), id, err, iSession, cEntry));

		if (cEntry != NULL)
			{
			CleanupStack::PushL(cEntry);
			entry = cEntry->Entry();
			switch (entry.SendingState())
				{
				case KMsvSendStateWaiting:
				case KMsvSendStateScheduled:
				case KMsvSendStateResend:

					scheduleMessage = ETrue;
					break;

				case KMsvSendStateFailed:
				case KMsvSendStateSent:
				case KMsvSendStateSuspended:
				default:

					scheduleMessage = EFalse;
					SCHSENDLOG(FLog(iFileName, _L("\t\tNot Scheduled Task [Id=%d State=%d Err=%d]"), id, entry.SendingState(), entry.iError));
					break;
				}
			} //end if

		if (scheduleMessage)
			{
			if (aRef.iHandle == KErrNotFound)
				{
				//Find or create the schedule
				if (cEntry != NULL)
					{
					TRAP(err, RestoreScheduleSettingsL(entry.iServiceId, entry.iMtm, *settings)); //use default if err != KErrNone
					SCHSENDLOG(FLog(iFileName, _L("\t\tRestoreScheduleSettings [Err=%d]"), err));
					}

				CMsvScheduleSend::ConnectAndRegisterL(aScheduler, *settings);
				
				if (FindorCreateScheduleL(aScheduler, aStartTime, *settings, aRef))
					aCount++;
				
				User::LeaveIfError(aScheduler.DisableSchedule(aRef.iHandle));
				}
			
			//Schedule the message
			package.iId = id;
			CMsvScheduleSend::ScheduleEntryL(aScheduler, aRef, package, info);
			SCHSENDLOG(FLog(iFileName, _L("\t\tScheduleEntryL [Id=%d Task=%d]"), id, info.iTaskId));

			if (cEntry != NULL)
				{
				//Update the message
				entry.iError = aError;
				TRAP(err, UpdateEntryL(*cEntry, entry, aRef, info, aStartTime));
				SCHSENDLOG(FLog(iFileName, _L("\t\tEntry updated [Err=%d]"), err));
				}

			aCount++;

			SCHSENDLOG(FLog(iFileName, _L("\t\tScheduled Task Complete [Id=%d Task=%d]"), id, info.iTaskId));
			}

		if (cEntry)
			CleanupStack::PopAndDestroy(cEntry);
		} //end while

	CleanupStack::PopAndDestroy(settings);
	}
void CMsvSendExe::RescheduleOnError(const CMsvSendExeActive& aActive, TInt aError)
	{
	SCHSENDLOG(FLog(iFileName, _L("\tRescheduleOnError (Mtm=%d CommandId=%d InCount=%d)"), aActive.Mtm().iUid, aActive.Package().iCommandId, aActive.Selection().Count()));
	RescheduleOnError(aActive.Selection(), aActive.Package(), aError);
	}
/**

The CMsvSendExe::RunL method
Called when all operations in iOperations have completed.
Stops the active scheduler.

@return			
@internalAll
*/
void CMsvSendExe::RunL()
	{
	SCHSENDLOG(FLog(iFileName, _L("All operations completed")));
	iActiveSchedulerWait.AsyncStop();
	}
/**
Does the actual scheduling of the supplied messages.

This function is called by ScheduleL() and DoReScheduleL(). The supplied messages
are assumed to have the values for the following data - MTM UID, off-peak flag,
schedule date and pending conditions flag. In debug mode, if these info is 
matching in all the messages then a panic will occur.

@param	aSchEntries
An array with the messages to be scheduled.

@param	aCommandId
The command id that must be used by the Send.Exe to eventually send the messages.

@param	aFinalState
The sending state to set to the messages to if the message is successfully 
scheduled.

@param	aTime
For conditions-scheduled messages this is the timeout, for time-scheduled messages
this is the scheduled time.

@param 	aPendingConditions
A flag indicating whether the schedule should be pending conditions.
*/
void CMsvScheduleSend::DoScheduleL(CMsvScheduledEntries& aSchEntries, const TInt aFinalState, const TTime& aTime, TBool aPendingConditions)
	{
	__ASSERT_DEBUG(aSchEntries.Count(), gPanic(EMessageSelectionEmpty));
	
#ifdef _DEBUG
	// Check that the mtm, time, off peak flag and pending conditions flag are 
	// the same for every message.
	TInt count = aSchEntries.Count();
	CMsvScheduledEntry* schEntry = aSchEntries[0];

	while (count--)
		{
		CMsvScheduledEntry* entry = aSchEntries[count];

		__ASSERT_DEBUG(entry->Mtm() == schEntry->Mtm(), gPanic(EMessagesNotSameMtm));
		__ASSERT_DEBUG((entry->OffPeak() && schEntry->OffPeak()) || (!entry->OffPeak() && !schEntry->OffPeak()), gPanic(EMessagesNotSameOffPeak));
		__ASSERT_DEBUG(entry->ScheduleDate() == schEntry->ScheduleDate(), gPanic(EMessagesNotSameTime));
		__ASSERT_DEBUG(entry->PendingConditions() == schEntry->PendingConditions(), gPanic(EMessagesNotSamePendingConditions));
		schEntry = entry;
		}
#endif

	// Connect and register with the task scheduler
	ConnectAndRegisterL();
	
	// Determine the start time and validity period
	TTime latencyTime;
	latencyTime.UniversalTime();
	latencyTime += iSettings->Latency();
	TTime startTime = latencyTime;

	if( aTime > startTime )
		{
		// The schedule time is in the future or there is no schedule time
		// (the messages are pending conditions) - update the start time.
		startTime = aTime;
		}

	TTimeIntervalMinutes valPeriod = iSettings->ValidityPeriod();
	CMsvScheduledEntry* firstMessage = aSchEntries[0];

	// Determine the start time and validity period of the new schedule - this
	// is not applicable if the messages are schedule for pending conditions.
	if( firstMessage->OffPeak() && !aPendingConditions )
		{
		GetOffPeakL(startTime, startTime, valPeriod);
		}

	CArrayFixFlat<TTaskSchedulerCondition>* schConditions = new (ELeave) CArrayFixFlat<TTaskSchedulerCondition>(KMsvSchsendArrayGrowth);
	CleanupStack::PushL(schConditions);
	if( aPendingConditions )
		PopulateScheduleConditionsL(*schConditions);

	// Create a schedule
	TSchedulerItemRef schItemRef;
	TBool schFound = EFalse;

	// Check to see if a schedule already exists for this particular schedule.
	// Need to consider both the start time and if the schedule is for pending
	// conditions met.
	// NOTE - if the schedule time is not in the future, then there is no need 
	// to search for an existing schedule.	
	if( startTime > latencyTime )
		{
		if( startTime != Time::MaxTTime() )
			RoundUpToMinute(startTime);
		
		TRAPD(err,FindScheduleL(startTime, *schConditions, aPendingConditions, schItemRef));
		if( err == KErrNone )
			{
			SCHSENDLOG(FLog(_L("\tFound schedule %d"), schItemRef.iHandle));
			schFound = ETrue;
			}
		// Else ignore the error and create and new schedule.
		}

	if( !schFound )
		{
		// The appropriate schedule.
		CreateScheduleL(startTime, valPeriod, *schConditions, aPendingConditions, schItemRef);
		}

	CleanupStack::PopAndDestroy(schConditions);
	
	// Disable the schedule so that it doesn't fire while scheduling
	User::LeaveIfError(iScheduler.DisableSchedule(schItemRef.iHandle));

	// Schedule the messages
	const TInt messageCount = aSchEntries.Count();
	TInt schErr = KErrNone;
	TInt curMsg;

	for( curMsg = 0; curMsg < messageCount; ++curMsg ) // must forward traverse the array
		{
		CMsvScheduledEntry* message = aSchEntries[curMsg];

		message->SetScheduleDate(startTime);
		TRAP(schErr, ScheduleEntryL(*message, aFinalState, startTime, schItemRef, aPendingConditions));

		if( schErr != KErrNone )
			break;
		}

	if( schErr != KErrNone && curMsg == 0 && !schFound )
		{
		iScheduler.DeleteSchedule(schItemRef.iHandle); // ignore error
		}
	else
		{
		User::LeaveIfError(iScheduler.EnableSchedule(schItemRef.iHandle));
		}
		
	User::LeaveIfError(schErr);
	}
/**
Verifies that the schedule information stored in specified messages is the 
same as that on the task scheduler.

@param aSelection 
Array of message IDs that need to be checked against the task scheduler.

@panic ScheduleSend-DLL 0
The array of message IDs is empty.
Debug build only.
*/
EXPORT_C void CMsvScheduleSend::CheckScheduleL(const CMsvEntrySelection& aSelection)
	{
	__ASSERT_DEBUG(aSelection.Count(), gPanic(EMessageSelectionEmpty));

	GetMessagesL(aSelection);	//Leaves with KErrNotFound if there are no messages returned in iSchEntries
	TInt entryCount = iSchEntries->Count();
	SCHSENDLOG(FLog(_L8("Asked to check schedule for %d msgs"), entryCount));
	
	ConnectAndRegisterL();

	while (entryCount--)
		{
		TBool found = EFalse;
		TTsTime schTime;

		CMsvScheduledEntry& sEntry = *iSchEntries->At(entryCount);

		if (!sEntry.iData.IsReset())
			{
			TSchedulerItemRef ref;
			TInt size = 0;
			TTaskInfo info;
			
			TInt err = iScheduler.GetTaskDataSize(sEntry.iData.iTaskId, size);

			if (!err)
				{
				HBufC* buf = HBufC::NewLC(size);
				TPtr ptr = buf->Des();

				User::LeaveIfError(iScheduler.GetTaskInfoL(sEntry.iData.iTaskId, info, ptr, ref, schTime));

				CleanupStack::PopAndDestroy(buf);
				found = ETrue;
				}
			else if (err != KErrNotFound)
				{
				User::Leave(err);
				} 
			} 
			
		if (iServerEntry.SetEntry(sEntry.Id()) == KErrNone)
			{
			TMsvEntry entry = iServerEntry.Entry();
			TInt sendingState = entry.SendingState();

			if (sendingState == KMsvSendStateScheduled || sendingState == KMsvSendStateResend || entry.Scheduled())
				{
				if (found)
					{
					entry.SetScheduled(ETrue);
					entry.iDate = schTime.GetUtcTime();
					User::LeaveIfError(iServerEntry.ChangeEntry(entry));
					}
				else
					{
					entry.SetScheduled(EFalse);
					entry.SetSendingState(KMsvSendStateUnknown);
					entry.iDate.UniversalTime();
					User::LeaveIfError(iServerEntry.ChangeEntry(entry));
					SendingCompleteL(sEntry, EFalse);
					} 
				} 
			} 
		} 
	}
Exemple #27
0
bool Shader::loadFromDisk(std::string filePath)
{
	std::ifstream file;
	std::stringstream strStreamBuffer; //string stream buffer

	//vertex-------------------------------------

	//load
	file.open(filePath + ".vert");

	std::string vertexShaderStr; 
	if (!file.is_open())
	{
		FLog(FLog::FAILURE, "Error loading VERTEX shader: " + filePath);
		return false;
	}
	else
	{
		strStreamBuffer << file.rdbuf(); //read the file
		vertexShaderStr = strStreamBuffer.str(); //copy to a string

		file.close();
	}


	//create the vertex shader source
	const GLchar* vertexShaderSource = vertexShaderStr.c_str();

	//Create and compile the shader
	GLuint vertexShader;
	vertexShader = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
	glCompileShader(vertexShader);

	// Check vertex shader
	GLint status;
	glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
	char buffer[512];
	glGetShaderInfoLog(vertexShader, 512, NULL, buffer);


	if (status == 0)
	{
		FLog(FLog::WARNING, buffer);
	}

	//fragment------------------------

	//load
	file.open(filePath + ".frag");

	std::string fragmentShaderStr;
	if (!file.is_open())
	{
		FLog(FLog::FAILURE, "Error loading FRAGMENT shader: " + filePath);
		return false;
	}
	else
	{
		//reset stream buffer
		strStreamBuffer.str("");
		strStreamBuffer.clear();

		strStreamBuffer << file.rdbuf();
		fragmentShaderStr = strStreamBuffer.str();

		file.close();
	}

	//Create the fragment shader
	const GLchar* fragmentShaderSource = fragmentShaderStr.c_str();

	GLuint fragmentShader;
	fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
	glCompileShader(fragmentShader);

	// Check fragment shader
	glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status);
	glGetShaderInfoLog(fragmentShader, 512, NULL, buffer);

	if (status == 0)
	{
		FLog(FLog::WARNING, buffer);
	}


	// Link the vertex and fragment shader into a shader program--------------------
	_program = glCreateProgram();
	glAttachShader(_program, vertexShader);
	glAttachShader(_program, fragmentShader);

	glLinkProgram(_program);

	//We have already linked the shaders so we can delete them now. To delete them efficently they must be detached before deleting it (https://www.opengl.org/sdk/docs/man/html/glDeleteShader.xhtml)
	glDetachShader(_program, vertexShader);
	glDetachShader(_program, fragmentShader);
	glDeleteShader(fragmentShader);
	glDeleteShader(vertexShader);

	return true;
}
/**
Determines the schedule time for a message.

The schedule time is determined by the error action. If no error action is
supplied, then the error action is obtained from the iErrorActions. This is a 
list of error codes associated with an error action. The error code with which
the message failed to be sent is used to determine the error action from this
list.

This function also increments the number of re-tries that the message has 
undergone.

A value of ETrue is returned if the message can be sent or a value of EFalse if
the message cannot be sent. 

If the message can be sent, then its schedule date and pending conditions flag 
are updated.

@see CMsvScheduleSend::ReScheduleL().

@param	aMessage
The message to be re-scheduled.

@param	aFromTime
The current time. Used to calculate the absolute schedule time once the interval
has been established.

@param	aErrorAction
The error action applied to the message. This can be NULL in which case the error
action is obtained from iErrorActions.

@return
A value of ETrue if the message should be sent or EFalse if it should not
*/
TBool CMsvScheduleSend::SetMessageStartTime(CMsvScheduledEntry& aMessage, const TTime& aFromTime, const TMsvSendErrorAction* aErrorAction)
	{
	TBool sendMsg = EFalse;
	TMsvSendErrorAction action;

	if( aErrorAction != NULL )
		{
		sendMsg = aMessage.CanSendToAnyRecipients(*aErrorAction);
		action = *aErrorAction;
		}
	else 
		{
		sendMsg = aMessage.CanSendToAnyRecipients(*iErrorActions, action);
		}

	SCHSENDLOG(FLog(_L8("\t\tCanSendToAnyRecipients() ret %d"), sendMsg));

	if( sendMsg )
		{
		// Increase the number of times this message has been retried.
		if( action.iRetries != ESendRetriesInfinite )
			{
			aMessage.iData.IncreaseRetries();
			aMessage.RecipientsIncreaseRetries();
			}
			
		TBool retryConditionMet = action.iAction == ESendActionRetryConditionMet;
		
		if( retryConditionMet && aMessage.PendingConditions() )
			{
			// There are two cases in which the message being re-scheduled has 
			// already been scheduled for pending conditions met and the error 
			// action is retry when conditions met.
			// 1.	The timeout has expired - current time exceeds the message's 
			//		schedule time (assuming that the message has a timeout).
			// 2.	The conditions were temporarily met and by the time the 
			//		waiting message tried to be sent the conditions were no 
			//		longer true.
			if( aMessage.ScheduleDate()!= Time::MaxTTime() && aFromTime > aMessage.ScheduleDate() )
				{
				// Case 1 - the message should not be re-scheduled (this marks
				// the message as failed).
				sendMsg = EFalse;
				}
			// NOTE - the else is case 2; the message should be re-scheduled,
			// but the timeout value should NOT be re-calculated -> do nothing.
			}
		else
			{
			TTimeIntervalSeconds interval;
			if( GetNextRetry(aMessage, action, interval) )
				{
				if( interval.Int() == 0 && retryConditionMet )
					{
					// The timeout was set to zero - set a schedule time of
					// Time::MaxTTime().
					aMessage.SetScheduleDate(Time::MaxTTime());
					}
				else
					{
					TTime schTime = aFromTime + interval;
					RoundUpToMinute(schTime);
					aMessage.SetScheduleDate(schTime);
					}
				aMessage.SetPendingConditions(retryConditionMet);
				}
			else
				{
				sendMsg = EFalse;
				}

			SCHSENDLOG(FLog(_L8("\t\tGetNextRetry() ret %d"), sendMsg));
			}
		}

	if( !sendMsg )
		{
		TBool failed = ETrue;
		TInt state	 = KMsvSendStateFailed;

		if( aMessage.RecipientsAllSent() )
			{
			failed	= EFalse;
			state	= KMsvSendStateSent;
			}
		else
			{
			aMessage.RecipientsSetFailed();
			}

		aMessage.SetFailed(failed);
		aMessage.SetSendingState(state);
		}

	return sendMsg;
	}
void CMsvScheduleSend::DeleteScheduleForEntryL(CMsvScheduledEntry& aMessage)
	{
	//Connect and register with the task scheduler
	//Delete the task from the task scheduler
	ConnectAndRegisterL();

	if (TaskAndMessageMatchL(aMessage))
		{
		TInt err = iScheduler.DeleteTask(aMessage.iData.iTaskId);

		SCHSENDLOG(FLog(_L8("\tDeleteTask Task=%d, Err=%d"), aMessage.iData.iTaskId, err));

		if (err != KErrNotFound)
			User::LeaveIfError(err);

		//Delete the schedule if there are no more tasks assigned to it

		//Declare variable to pass into GetScheduleL()
		TScheduleState2 schState;
		TTsTime schDueTime;

		// Get the schedule Type
		TScheduleType scheduleType;
		iScheduler.GetScheduleTypeL(aMessage.iData.iRef.iHandle, scheduleType);
		iSchTaskInfo->Reset();
		
		// Depends on the Schedule Type
		if (scheduleType == ETimeSchedule)
		    {
			//Get details of the existing time schedule
			err = iScheduler.GetScheduleL(aMessage.iData.iRef.iHandle, schState, *iSchEntryInfo, *iSchTaskInfo, schDueTime);

			SCHSENDLOG(FLog(_L8("\tGetScheduleL Sch=%d, Err=%d"), aMessage.iData.iRef.iHandle, err));
		    }

		else if (scheduleType == EConditionSchedule)
		    {
		    CArrayFixFlat<TTaskSchedulerCondition>* schConditions =
		        new (ELeave) CArrayFixFlat<TTaskSchedulerCondition>(KMsvSchsendArrayGrowth);

		    CleanupStack::PushL(schConditions);
			//Get details of the existing condition schedule
		    err = iScheduler.GetScheduleL(aMessage.iData.iRef.iHandle, schState, *schConditions, schDueTime, *iSchTaskInfo);

			SCHSENDLOG(FLog(_L8("\tGetScheduleL Sch=%d, Err=%d"), aMessage.iData.iRef.iHandle, err));

		    CleanupStack::PopAndDestroy(schConditions);

		    }
		else
		    {
		    User::Leave(KErrNotFound);
		    }
		    
		if (!err)
			{
			if (iSchTaskInfo->Count() == 0)
				{
				SCHSENDLOG(FLog(_L8("\tDeleting schedule %d"), aMessage.iData.iRef.iHandle));
				iScheduler.DeleteSchedule(aMessage.iData.iRef.iHandle); //ignore error
				}
			}
		else if (err != KErrNotFound)
			{
			User::Leave(err);
			}
		}
	}