Example #1
0
void CWebServerEng::DoCancel()
{
	// Now we shutdown all connections.
	iStatusText.Format(_L("Number of lost connections: %d\n"),iCurrentNumberConnections);
	NotifyStatus();
	
	iStatusText.Format(_L("Number of connections: %d\n"),iTotalNumberConnections);
	NotifyStatus();

	// Deleting all the connections.
	TSglQueIter<CWebServerCon> ConIter(iConList);
	CWebServerCon* Connection;
	ConIter.SetToFirst();
	while ((Connection = ConIter++) != NULL)
	{
		Connection->Cancel();
		delete Connection;
	}

	// Actualize the lits of connections.
	iConList.Reset(); // This line was missing before, I think this was the reason of Marku's Panic.
	

	// Cancel the Accpet in the listen socket.
	iSocket.CancelAccept();


	// Delete the next conenction.
	// Note: As a collateral effect the iConnection is deleted when iCon is deleted !!
	// I don't like too much this (:() but I leave it because it works.
	delete iCon;
	iCon = 0;


	iSocket.Close();

#if EPOC_SDK >= 0x07010000
	iRConnection.Close();
#elif EPOC_SDK >= 0x06010000
	iGenericAgent.Close();
#else
	iNetdial.Stop();
	iNetdial.Close();
#endif
	iSocketServer.Close();

	iWebServerState = ENotStarted;
	iStatusText=_L("Closing WebServer.\n");
	NotifyStatus();
}
void CNetRender::SetClient(QString address, int portNo)
{
	DeleteServer();
	deviceType = netRender_CLIENT;
	status = netRender_NEW;
	this->address = address;
	this->portNo = portNo;
	ResetMessage(&msgFromServer);
	clientSocket = new QTcpSocket(this);

	reconnectTimer = new QTimer;
	reconnectTimer->setInterval(1000);
	connect(reconnectTimer, SIGNAL(timeout()), this, SLOT(TryServerConnect()));
	connect(clientSocket, SIGNAL(disconnected()), this, SLOT(ServerDisconnected()));
	connect(clientSocket, SIGNAL(readyRead()), this, SLOT(ReceiveFromServer()));

	reconnectTimer->start();
	WriteLog("NetRender - Client Setup, link to server: " + address + ", port: " + QString::number(portNo));
	emit NotifyStatus();

	if(systemData.noGui)
	{
		QTextStream out(stdout);
		out << "NetRender - Client Setup, link to server: " + address + ", port: " + QString::number(portNo) + "\n";
	}
}
Example #3
0
void TreeView::MouseMoved (BPoint point, uint32 status, const BMessage *dragMessage)
{
	/* Handle the mouse when its moving */
	if (Window()->IsActive() == false)
		return;

	BPoint pt;
	uint32 buttons;
	GetMouse (&pt, &buttons, false);
	
	/* Exit function if no mouse button is held down */
	if (!(buttons != 0))
		return;
	
	if (status == B_ENTERED_VIEW)
		isMidWay = true;
	else if (status == B_EXITED_VIEW)
		isMidWay = false;
	
	if (status == B_EXITED_VIEW || status == B_ENTERED_VIEW)
	{
		Invalidate (Bounds());
		NotifyStatus();
	}
	
	BView::MouseMoved (point, status, dragMessage);
}
Example #4
0
void TreeView::MouseDown (BPoint point)
{
	isMidWay = true;
	Invalidate (Bounds());
	
	NotifyStatus();
	BView::MouseDown (point);
}
Example #5
0
void TreeView::MouseUp (BPoint point)
{
	isExpanded = !isExpanded;
	isMidWay = false;
	Invalidate (Bounds());
	NotifyStatus();
	
	BView::MouseUp (point);
}
// ---------------------------------------------------------------------------
// Adds the given message as a haptics status observer.
// ---------------------------------------------------------------------------
//
void CHWRMHapticsCommonData::AddStatusObserver( 
                                        const RMessage2& aStatusObserverMsg )
    {
    // find the index of the client
    TInt index = FindClient( aStatusObserverMsg.Session() );
    
    if ( index != KErrNotFound )
        {
        // set new observer message
        iClientArray[index]->iStatusObserver = aStatusObserverMsg;
        
        // read and set request types value
        THWRMHapticsStatusTypes reqTypes = 
            static_cast<THWRMHapticsStatusTypes>( aStatusObserverMsg.Int0() );

        iClientArray[index]->iStatusTypes = reqTypes;
        
        // send notification of the current status, if it is needed
        // for this client
        if ( iClientArray[index]->iNotificationRequired )
            {
            NotifyStatus( iClientArray[index]->iStatus, 
                          aStatusObserverMsg.Session() );

            iClientArray[index]->iNotificationRequired = EFalse;
            }
        else if ( iClientArray[index]->iRequiredActuators.Count() )
            {
            // there are unsent actuator event notifications, 
            // send immediately
            THWRMLogicalActuators actuator = 
                iClientArray[index]->iRequiredActuators[0];
            
            // search for the event
            TInt eventIndex = FindActuatorEvent( actuator );
            
            // send notification, if event found
            if ( eventIndex != KErrNotFound )
                {
                NotifyActuatorEventToClient( 
                                index, 
                                iActuatorEvents[eventIndex].iActuatorEvent, 
                                iActuatorEvents[eventIndex].iActuator );
                }
            
            // remove the actuator from required event notification array
            iClientArray[index]->iRequiredActuators.Remove( 0 );
            }
        }
    }
void CNetRender::DeleteClient()
{
	if (deviceType != netRender_CLIENT) return;
	deviceType = netRender_UNKNOWN;
	WriteLog("NetRender - Delete Client");
	if(reconnectTimer->isActive()) reconnectTimer->stop();
	if(clientSocket)
	{
		clientSocket->close();
		delete clientSocket;
		clientSocket = NULL;
	}
	status = netRender_DISABLED;
	emit NotifyStatus();
}
void CNetRender::ServerDisconnected()
{
	status = netRender_ERROR;
	emit NotifyStatus();

	gMainInterface->stopRequest = true;

	reconnectTimer->start();

	if(systemData.noGui)
	{
		QTextStream out(stdout);
		out << QString("Connection lost") + "\n";
		out.flush();
	}
	else
	{
		cErrorMessage::showMessage(QString("Connection lost"), cErrorMessage::errorMessage);
	}
}
void CNetRender::TryServerConnect()
{
	if(clientSocket)
	{
		if(clientSocket->state() == QAbstractSocket::ConnectedState)
		{
			reconnectTimer->stop();
		}
		else if(clientSocket->state() == QAbstractSocket::ConnectingState)
		{
			return; // wait for result
		}
		else
		{
			status = netRender_CONNECTING;
			emit NotifyStatus();
			clientSocket->close();
			clientSocket->connectToHost(address, portNo);
		}
	}
}
Example #10
0
void CExampleShellContainer::NotifyGraphicExampleFinished()
	{
	NotifyStatus(KTxtFinished);
	}
Example #11
0
void
FieldView::GeneratePaths()
{
	mAnimation = mShow->NewAnimation(NotifyStatus(), NotifyErrorList());
}
Example #12
0
void CNetRender::ProcessData(QTcpSocket *socket, sMessage *inMsg)
{
	// beware: payload points to char, first cast to target type pointer, then dereference
	// *(qint32*)msg->payload

	//------------------------- CLIENT ------------------------
	if(IsClient())
	{
		switch ((netCommand)inMsg->command)
		{
		case netRender_VERSION:
		{
			sMessage outMsg;
			if(*(qint32*)inMsg->payload.data() == version)
			{
				WriteLog("NetRender - version matches (" + QString::number(version) + "), connection established");

				if(systemData.noGui)
				{
					QTextStream out(stdout);
					out << "NetRender - version matches (" + QString::number(version) + "), connection established\n";
				}

				// server version matches, send worker count
				outMsg.command = netRender_WORKER;
				QDataStream stream(&outMsg.payload, QIODevice::WriteOnly);
				stream << workerCount;
				QString machineName = QHostInfo::localHostName();
				stream << (qint32)machineName.toUtf8().size();
				stream.writeRawData(machineName.toUtf8().data(), machineName.toUtf8().size());
				status = netRender_READY;
				emit NewStatusClient();
			}
			else
			{
				qWarning() << "CNetRender - version mismatch! client version: " << version << ", server: " << *(qint32*)inMsg->payload.data();
				outMsg.command = netRender_BAD;
			}
			SendData(clientSocket, outMsg);
			break;
			}
			case netRender_STOP:
			{
				status = netRender_READY;
				gMainInterface->stopRequest = true;
				emit NotifyStatus();
				WriteLog("CNetRender - STOP");
				break;
			}
			case netRender_STATUS:
			{
				emit NotifyStatus();
				break;
			}
			case netRender_JOB:
			{
				if (inMsg->id == actualId)
				{
					WriteLog("NetRender - received new job");
					QDataStream stream(&inMsg->payload, QIODevice::ReadOnly);
					QByteArray buffer;
					qint32 size;
					status = netRender_WORKING;
					emit NotifyStatus();

					// read settings
					stream >> size;
					buffer.resize(size);
					stream.readRawData(buffer.data(), size);
					settingsText = QString::fromUtf8(buffer.data(), buffer.size());

					// read textures
					for (int i = 0; i < textures.textureList.size(); i++)
					{
						stream >> size;
						if (size > 0)
						{
							buffer.resize(size);
							stream.readRawData(buffer.data(), size);
							textures.textureList[i]->FromQByteArray(buffer);
						}
					}

					cSettings parSettings(cSettings::formatCondensedText);
					parSettings.BeQuiet(true);
					parSettings.LoadFromString(settingsText);
					parSettings.Decode(gPar, gParFractal);

					if(!systemData.noGui)
					{
						gMainInterface->SynchronizeInterface(gPar, gParFractal, cInterface::write);
						gMainInterface->StartRender(true);
					}
					else
					{
						//in noGui mode it must be started as separate thread to be able to process event loop
						gMainInterface->headless = new cHeadless;

						QThread *thread = new QThread; //deleted by deleteLater()
						gMainInterface->headless->moveToThread(thread);
						QObject::connect(thread, SIGNAL(started()), gMainInterface->headless, SLOT(slotNetRender()));
						thread->setObjectName("RenderJob");
						thread->start();

						QObject::connect(gMainInterface->headless, SIGNAL(finished()), gMainInterface->headless, SLOT(deleteLater()));
						QObject::connect(gMainInterface->headless, SIGNAL(finished()), thread, SLOT(quit()));
						QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
					}
				}
				else
				{
					WriteLog("NetRender - received JOB message with wrong id");
				}
				break;
			}
			case netRender_RENDER:
			{
				if (inMsg->id == actualId)
				{
					QDataStream stream(&inMsg->payload, QIODevice::ReadOnly);
					qint32 doneSize;
					stream >> doneSize;
					QList<int> done;
					for (int i = 0; i < doneSize; i++)
					{
						qint32 line;
						stream >> line;
						done.append(line);
					}

					emit ToDoListArrived(done);
				}
				else
				{
Example #13
0
void CWebServerEng::RunL()
{
	if (iStatus==KErrNone)
	{
			switch(iWebServerState)
			{
			case EWaitingForConnections:
				ASSERT(iCon != NULL);

				iCon->SetObserver(iObserver);
				if (iCurrentNumberConnections > MAX_NUMBER_CONNECTIONS) // This must be dynamic.(E.g: Only 10% memory free then WebserverBusy)
				{
					iCon->WebServerBusyL();
				}
				else
				{
					iCon->StartConnection();
				}
				iConList.AddLast(*iCon);
				iCurrentNumberConnections++;
				iTotalNumberConnections++;
				iObserver->UpdateNumberConL();
	

				TRAPD(err, CreateSocketAndConnectionL());
				if (err >= KErrNone)
				{
					ASSERT(iConnection != NULL);
					iWebServerState = EWaitingForConnections;		
					iSocket.Accept(*iConnection,iStatus);
					SetActive();
				}
				else
				{
					iCon = 0;
					delete iConnection;
					iConnection = 0;
					iWebServerState = EErrorRecovery;
				}
				break;
			case EShuttingDownServer:
				delete this;
				break;
			case EErrorRecovery:
				User::Panic(_L("BAD STATE IN THE STATE MACHINE"),2);
				break;
			default: //Something is going VERY, VERY wrong
				User::Panic(_L("UnKnown State in the WebServer."),2);
				break;
			}
		
	}
	else if (iStatus == KErrWouldBlock)
	{
		ASSERT(iConnection != NULL);
		iStatusText.Format(_L("\r\nRECOVERING ACCEPT !!!!!\r\n"),iCurrentNumberConnections);
		NotifyStatus();

		iSocket.Accept(*iConnection,iStatus);
		SetActive();	
	}
	else if(iWebServerState == EShuttingDownServer)
	{
		delete this;
	}
	else
	{		
		if (iWebServerState == EWaitingForConnections)
			iSocket.CancelAccept();
		
		iWebServerState = EShuttingDownServer;
		iSocket.Shutdown(RSocket::ENormal,iStatus);
		SetActive();
	}
		
}
Example #14
0
/*
void CWebServerEng::ReadConfigFileL()
{
	// Read Config File.
	TRAP(err,iServerEnv->ReadConfigFileL(CFG_FILENAME));
	if ((err == KErrNotFound) || (err == KErrPathNotFound))
	{
		iObserver->ShowWarningL(R_CONFIG_FILE_MISSING_WAR);
		iServerEnv->CheckAndSetDefaultL();
	}
	else
	{
		User::LeaveIfError(err);
	}
}

void CWebServerEng::ReadHttpTypesFileL()
{
	// Read Http types files
	TRAP(err,iHttpTypes.ReadHttpTypesFileL(HTTP_TYPES_FILENAME));
	if ((err == KErrNotFound) || (err == KErrPathNotFound))
	{
		iObserver->ShowWarningL(R_TYPES_FILE_MISSING_WAR);
		iHttpTypes.SetDefaultHttpTypesL();
	}
	else
	{
		User::LeaveIfError(err);
	}
}

*/
void CWebServerEng::StartWebServerL()
// This function starts the WebServer.
{
	
	TInt err;
/*
// *** TEST of the Security Database.
	CWebServerSecDB SecDb; // ----> Must be menber of the object.

//TRAP(err,SecDb.OpenSecDBL(_L("WebServer")));
//if (err == KErrNotFound)
//{
	SecDb.CreateSecDB(_L("webserver.db"));
	SecDb.OpenSecDBL(_L("webserver.db"));
	SecDb.InsertUserL(_L("Litos"),_L("Groo"),_L("GrooWorld"));
	SecDb.InsertUserL(_L("Rufferto"),_L("Groo"),_L("RuffertoWorld"));
	TInt ruffertotwice = SecDb.InsertUserL(_L("Rufferto"),_L("Groonan"),_L("RuffertoWorld"));
	SecDb.InsertRealmL(_L("GrooWorld"),_L("Basic"));
	SecDb.InsertResourceDirL(_L("\\ws\\laetitia\\"),_L("GrooWorld"),SEC_GET);
	SecDb.CloseSecDB();
	SecDb.OpenSecDBL(_L("webserver.db"));
	TBool boolean1 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet);
	TBool boolean2 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EPut);
	TBool boolean3 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EDelete);
	TBool boolean4 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EOptions);
	TBool boolean5 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EPost);
	TBool boolean6 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet);
	TBool boolean7 = SecDb.GrantAccessL(_L("Litos5"),_L("Groo"),_L("\\ws\\laetitia\\"),EPost);
	TBool boolean8 = SecDb.GrantAccessL(_L("Litos"),_L("Groonan"),_L("\\ws\\laetitia\\"),EPost);
	TBool boolean9 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\lala\\laetitia\\"),EPost);
	TBool boolean10 = SecDb.GrantAccessL(_L("Rufferto"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet);
	TInt deluser = SecDb.DeleteUserL(_L("Litos"),_L("RuffertoWorld"));
	SecDb.DeleteUserL(_L("Litos"),_L("GrooWorld"));
	TInt dellit = SecDb.DeleteUserL(_L("Litos"),_L("GrooWorld"));
	TBool boolean11 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet);
	SecDb.InsertUserL(_L("Litos"),_L("Groo"),_L("GrooWorld"));
	SecDb.DeleteRealm(_L("GrooWorld"));
	TBool boolean12 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet);
	SecDb.CloseSecDB();
	
//}


*/

//***********************************

#ifdef IPV4_ORIG

	iStatusText = _L("************* IPV4 STACK ****************\n\n");
#else

	iStatusText=_L("*************** DUAL STACK IPV4/IPV6 ****************\n\n");
#endif
	NotifyStatus();

	// Setting up the dial connection.
	iStatusText=_L("Setting up net connection.\n");
	NotifyStatus();

	// Make a connection to the Socket Server.
	iStatusText=_L("Connecting to the Socket Server.\n");
	NotifyStatus();
	err = iSocketServer.Connect(201);
	User::LeaveIfError(err);

#if EPOC_SDK >= 0x07010000
    User::LeaveIfError(iRConnection.Open(iSocketServer));
    err = iRConnection.Start();

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

#elif EPOC_SDK >= 0x06010000

    User::LeaveIfError(iGenericAgent.Open());
    err = iGenericAgent.StartOutgoing();
    err = iGenericAgent.DisableTimers();

    if (err != KErrAlreadyExists)
        User::LeaveIfError(err);
#else
    User::LeaveIfError(iNetdial.Open());
    
	err = iNetdial.DisableTimers();
	if (err != KErrAlreadyExists)
		User::LeaveIfError(err);

	err = iNetdial.StartDialOut();

	if (err != KErrAlreadyExists)
		User::LeaveIfError(err);
#endif // EPOC_SDK >= 0x06010000

	// Open a socket to listen on.
	iStatusText=_L("Opening the Socket.\n");
	NotifyStatus();

	err = iSocket.Open(iSocketServer, KAfInet, KSockStream, KProtocolInetTcp);
	User::LeaveIfError(err);

	// Reuse the port
	iSocket.SetOpt(KSoReuseAddr, KProtocolInetIp, 1);

	// Bind the socket to the http port.
	iStatusText=_L("Binding the Socket.\n");
	NotifyStatus();

	TInetAddr httpPort(KInetAddrAny, iServerEnv->iPort);
	httpPort.SetFamily(0); // Listen both IPV4 and IPV6. (Dual-Stack).
	err = iSocket.Bind(httpPort);
	User::LeaveIfError(err);

	// Listen for incoming connections.
	iStatusText=_L("Listening through the Socket.\n");
	NotifyStatus();
	err = iSocket.Listen(100);
	User::LeaveIfError(err);

	// The Socket for the "real" connection.(between the client and the WebServer)
	iStatusText=_L("Waiting for a Connection.\n");
	NotifyStatus();
	
	CreateSocketAndConnectionL();
	
	iWebServerState = EWaitingForConnections;
	iSocket.Accept(*iConnection,iStatus);
	iCurrentNumberConnections = 0;
	iTotalNumberConnections = 0;
	SetActive();
}