diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2013-12-31 16:10:17 +0100 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-12-31 16:10:17 +0100 | 
| commit | 40f4c6944799bd696ccf358c5378b230ecc7f52b (patch) | |
| tree | 5b4d8f8e61ba57800f8570ee195551ce1abecd18 /ftnoir_protocol_sc | |
| parent | 4abd0ca3b5090018a7db05e8c2e0f478d861d978 (diff) | |
sc: settings framework
Diffstat (limited to 'ftnoir_protocol_sc')
| -rw-r--r-- | ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 173 | ||||
| -rw-r--r-- | ftnoir_protocol_sc/ftnoir_protocol_sc.h | 62 | ||||
| -rw-r--r-- | ftnoir_protocol_sc/ftnoir_protocol_sc_dialog.cpp | 96 | ||||
| -rw-r--r-- | ftnoir_protocol_sc/ftnoir_protocol_sc_dll.cpp | 17 | 
4 files changed, 75 insertions, 273 deletions
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 8449f6ce..9fb48527 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -50,15 +50,12 @@ float FTNoIR_Protocol::prevSCRotZ = 0.0f;  static QLibrary SCClientLib; -/** constructor **/  FTNoIR_Protocol::FTNoIR_Protocol()  { -	ProgramName = "Microsoft FSX";  	blnSimConnectActive = false;  	hSimConnect = 0;  } -/** destructor **/  FTNoIR_Protocol::~FTNoIR_Protocol()  {  	qDebug() << "~FTNoIR_Protocol says: inside" << FTNoIR_Protocol::hSimConnect; @@ -69,18 +66,8 @@ FTNoIR_Protocol::~FTNoIR_Protocol()  			qDebug() << "~FTNoIR_Protocol says: close SUCCEEDED";  		}  	} -//	SCClientLib.unload(); Generates crash when tracker is ended...  } -// -// Load the current Settings from the currently 'active' INI-file. -// -void FTNoIR_Protocol::loadSettings() { -} - -// -// Update Headpose in Game. -//  void FTNoIR_Protocol::sendHeadposeToGame( const double *headpose ) {      virtSCRotX = -headpose[Pitch];					// degrees      virtSCRotY = -headpose[Yaw]; @@ -90,14 +77,8 @@ void FTNoIR_Protocol::sendHeadposeToGame( const double *headpose ) {      virtSCPosY = headpose[TY]/100.f;      virtSCPosZ = -headpose[TZ]/100.f; -	// -	// It's only useful to send data, if the connection was made. -	//  	if (!blnSimConnectActive) {          if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) { -            qDebug() << "FTNoIR_Protocol::sendHeadposeToGame() says: SimConnect active!"; - -            //set up the events we want to listen for              HRESULT hr;              simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame"); @@ -105,39 +86,11 @@ void FTNoIR_Protocol::sendHeadposeToGame( const double *headpose ) {              hr = simconnect_mapclienteventtosimevent(hSimConnect, EVENT_INIT, "");              hr = simconnect_addclienteventtonotificationgroup(hSimConnect, GROUP0, EVENT_INIT, false);              hr = simconnect_setnotificationgrouppriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_HIGHEST); -            ////hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "VK_COMMA", EVENT_INIT); -            ////hr = SimConnect_SetInputGroupState(hSimConnect, INPUT0, SIMCONNECT_STATE_ON); -              blnSimConnectActive = true;          }  	} -	else { -		// -		// Write the 6DOF-data to FSX -//		// -//		// Only do this when the data has changed. This way, the HAT-switch can be used when tracking is OFF. -//		// -//		if ((prevPosX != virtPosX) || (prevPosY != virtPosY) || (prevPosZ != virtPosZ) || -//			(prevRotX != virtRotX) || (prevRotY != virtRotY) || (prevRotZ != virtRotZ)) { -////			if (S_OK == simconnect_set6DOF(hSimConnect, virtPosX, virtPosY, virtPosZ, virtRotX, virtRotZ, virtRotY)) { -////					qDebug() << "FTNoIR_Protocol::run() says: SimConnect data written!"; -////			} -//		} -// -//		prevPosX = virtPosX; -//		prevPosY = virtPosY; -//		prevPosZ = virtPosZ; -//		prevRotX = virtRotX; -//		prevRotY = virtRotY; -//		prevRotZ = virtRotZ; - -		if (SUCCEEDED(simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL))) { -			qDebug() << "FTNoIR_Protocol::sendHeadposeToGame() says: Dispatching"; -		} -		else { -			qDebug() << "FTNoIR_Protocol::sendHeadposeToGame() says: Error Dispatching!"; -		} -	} +    else +        (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL));  }  class ActivationContext { @@ -176,30 +129,16 @@ private:      HANDLE hactctx;  }; -// -// Returns 'true' if all seems OK. -//  bool FTNoIR_Protocol::checkServerInstallationOK()  {         if (!SCClientLib.isLoaded())                                 { -        qDebug() << "SCCheckClientDLL says: Starting Function"; -         -        QSettings settings("opentrack"); -        QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); -        QSettings iniFile( currentFile, QSettings::IniFormat );		// Application settings (in INI-file) -        iniFile.beginGroup ( "FSX" ); -        int act = iniFile.value("version", 0).toInt(); -        iniFile.endGroup(); -         -        ActivationContext ctx(142 + act); +        ActivationContext ctx(142 + static_cast<int>(s.sxs_manifest));          if (!SCClientLib.load()) {              qDebug() << "SC load" << SCClientLib.errorString();              return false;          } -    } else { -        qDebug() << "SimConnect already loaded";      }  	// @@ -260,97 +199,47 @@ bool FTNoIR_Protocol::checkServerInstallationOK()  void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)  { -//    HRESULT hr; -      switch(pData->dwID)      { -        case SIMCONNECT_RECV_ID_EVENT: -        { -            SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData; - -			qDebug() << "FTNoIR_Protocol::processNextSimconnectEvent() says: SimConnect active!"; -            //switch(evt->uEventID) -            //{ -            //    //case EVENT_CAMERA_RIGHT: - -            //    //    cameraBank = normalize180( cameraBank + 5.0f); - -            //    //    hr = SimConnect_CameraSetRelative6DOF(hSimConnect, 0.0f, 0.0f, 0.0f, -            //    //            SIMCONNECT_CAMERA_IGNORE_FIELD,SIMCONNECT_CAMERA_IGNORE_FIELD, cameraBank); - -            //    //    printf("\nCamera Bank = %f", cameraBank); -            //    //    break; - -            //    //case EVENT_CAMERA_LEFT: -            //    //     -            //    //    cameraBank = normalize180( cameraBank - 5.0f); - -            //    //    hr = SimConnect_CameraSetRelative6DOF(hSimConnect, 0.0f, 0.0f, 0.0f, -            //    //            SIMCONNECT_CAMERA_IGNORE_FIELD,SIMCONNECT_CAMERA_IGNORE_FIELD, cameraBank); -            //    //     -            //    //    printf("\nCamera Bank = %f", cameraBank); -            //    //    break; - -            //    //default: -            //    //    break; -            //} -            //break; +    default: +        break; +    case SIMCONNECT_RECV_ID_EVENT_FRAME: +    { +        if ((prevSCPosX != virtSCPosX) || (prevSCPosY != virtSCPosY) || (prevSCPosZ != virtSCPosZ) || +                (prevSCRotX != virtSCRotX) || (prevSCRotY != virtSCRotY) || (prevSCRotZ != virtSCRotZ)) { +            (void) simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY);          } -		case SIMCONNECT_RECV_ID_EVENT_FRAME: -		{ -//			qDebug() << "FTNoIR_Protocol::processNextSimconnectEvent() says: Frame event!"; -			if ((prevSCPosX != virtSCPosX) || (prevSCPosY != virtSCPosY) || (prevSCPosZ != virtSCPosZ) || -				(prevSCRotX != virtSCRotX) || (prevSCRotY != virtSCRotY) || (prevSCRotZ != virtSCRotZ)) { -				if (S_OK == simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY)) { -	//					qDebug() << "FTNoIR_Protocol::run() says: SimConnect data written!"; -				} -			} -			prevSCPosX = virtSCPosX; -			prevSCPosY = virtSCPosY; -			prevSCPosZ = virtSCPosZ; -			prevSCRotX = virtSCRotX; -			prevSCRotY = virtSCRotY; -			prevSCRotZ = virtSCRotZ; -		} +        prevSCPosX = virtSCPosX; +        prevSCPosY = virtSCPosY; +        prevSCPosZ = virtSCPosZ; +        prevSCRotX = virtSCRotX; +        prevSCRotY = virtSCRotY; +        prevSCRotZ = virtSCRotZ; +    } +    case SIMCONNECT_RECV_ID_EXCEPTION: +    { +        SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData; -        case SIMCONNECT_RECV_ID_EXCEPTION: +        switch (except->dwException)          { -            SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData; -             -            switch (except->dwException) -            { -            case SIMCONNECT_EXCEPTION_ERROR: -                printf("\nCamera error"); -                break; - -            default: -                printf("\nException"); -                break; -            } +        case SIMCONNECT_EXCEPTION_ERROR: +            qDebug() << "Camera error";              break; -        } -        case SIMCONNECT_RECV_ID_QUIT: -        { -			qDebug() << "FTNoIR_Protocol::processNextSimconnectEvent() says: Quit event!"; -//            quit = 1; +        default: +            qDebug() << "Exception";              break;          } +        break; +    } -        default: -            break; +    case SIMCONNECT_RECV_ID_QUIT: +    { +        break; +    }      }  } -//////////////////////////////////////////////////////////////////////////////// -// Factory function that creates instances if the Protocol object. - -// Export both decorated and undecorated names. -//   GetProtocol     - Undecorated name, which can be easily used with GetProcAddress -//                Win32 API function. -//   _GetProtocol@0  - Common name decoration for __stdcall functions in C language. -//#pragma comment(linker, "/export:GetProtocol=_GetProtocol@0") -  extern "C" FTNOIR_PROTOCOL_BASE_EXPORT IProtocol* CALLING_CONVENTION GetConstructor()  {      return new FTNoIR_Protocol; diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h index 7917c532..a13c0097 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h @@ -27,8 +27,6 @@  *				must be treated as such...										*  ********************************************************************************/  #pragma once -#ifndef INCLUDED_SCSERVER_H -#define INCLUDED_SCSERVER_H  #undef _WIN32_WINNT  #define _WIN32_WINNT 0x0502  #include "facetracknoir/global-settings.h" @@ -48,7 +46,8 @@  #include <QProcess>  #include <QDebug>  #include <QFile> -//#include "math.h" +#include "facetracknoir/options.h" +using namespace options;  typedef HRESULT (WINAPI *importSimConnect_Open)(HANDLE * phSimConnect, LPCSTR szName, HWND hWnd, DWORD UserEventWin32, HANDLE hEventHandle, DWORD ConfigIndex);  typedef HRESULT (WINAPI *importSimConnect_Close)(HANDLE hSimConnect); @@ -77,6 +76,15 @@ enum INPUT_ID      INPUT0=0,  }; +struct settings { +    pbundle b; +    value<int> sxs_manifest; +    settings() : +        b(bundle("proto-simconnect")), +        sxs_manifest(b, "sxs-manifest-version", 0) +    {} +}; +  class FTNoIR_Protocol : public IProtocol  {  public: @@ -87,11 +95,7 @@ public:      QString getGameName() {          return "FS2004/FSX";      } -  private: -	// Private properties -	QString ProgramName; -  	static float virtSCPosX;  	static float virtSCPosY;  	static float virtSCPosZ; @@ -121,7 +125,7 @@ private:  	static HANDLE hSimConnect;						// Handle to SimConnect  	static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext); -	void loadSettings(); +    settings s;  };  // Widget that has controls for FTNoIR protocol client-settings. @@ -129,28 +133,15 @@ class SCControls: public QWidget, public IProtocolDialog  {      Q_OBJECT  public: - -	explicit SCControls(); -	void registerProtocol(IProtocol *protocol) { -		theProtocol = (FTNoIR_Protocol *) protocol;			// Accept the pointer to the Protocol -	} -	void unRegisterProtocol() { -		theProtocol = NULL;									// Reset the pointer -	} - +    SCControls(); +    void registerProtocol(IProtocol *protocol) {} +    void unRegisterProtocol() {}  private: -	Ui::UICSCControls ui; -	void loadSettings(); -	void save(); - -	/** helper **/ -	bool settingsDirty; -	FTNoIR_Protocol *theProtocol; - +    Ui::UICSCControls ui; +    settings s;  private slots: -	void doOK(); -	void doCancel(); -	void settingChanged() { settingsDirty = true; }; +    void doOK(); +    void doCancel();  };  //******************************************************************************************************* @@ -159,15 +150,8 @@ private slots:  class FTNoIR_ProtocolDll : public Metadata  {  public: -	FTNoIR_ProtocolDll(); -	~FTNoIR_ProtocolDll(); - -	void getFullName(QString *strToBeFilled) { *strToBeFilled = QString("FSX SimConnect"); }; -	void getShortName(QString *strToBeFilled) { *strToBeFilled = QString("SimConnect"); }; -	void getDescription(QString *strToBeFilled) { *strToBeFilled = QString("Microsoft SimConnect protocol"); }; - -    void getIcon(QIcon *icon) { *icon = QIcon(":/images/fsx.png"); }; +    void getFullName(QString *strToBeFilled) { *strToBeFilled = QString("FSX SimConnect"); } +    void getShortName(QString *strToBeFilled) { *strToBeFilled = QString("SimConnect"); } +    void getDescription(QString *strToBeFilled) { *strToBeFilled = QString("Microsoft SimConnect protocol"); } +    void getIcon(QIcon *icon) { *icon = QIcon(":/images/fsx.png"); }  }; - -#endif//INCLUDED_SCSERVER_H -//END diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc_dialog.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc_dialog.cpp index eb15ca69..6af87285 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc_dialog.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc_dialog.cpp @@ -26,13 +26,6 @@  #include <QDebug>  #include "facetracknoir/global-settings.h" -//******************************************************************************************************* -// FaceTrackNoIR Client Settings-dialog. -//******************************************************************************************************* - -// -// Constructor for server-settings-dialog -//  SCControls::SCControls() :  QWidget()  { @@ -41,85 +34,38 @@ QWidget()  	// Connect Qt signals to member-functions      connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));      connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); -	//connect(ui.cbxSelectPPJoyNumber, SIGNAL(currentIndexChanged(int)), this, SLOT(virtualJoystickSelected( int ))); - -	theProtocol = NULL; -	// Load the settings from the current .INI-file -	loadSettings(); +    tie_setting(s.sxs_manifest, ui.comboBox);  }  void SCControls::doOK() { -	save(); +    s.b->save();  	this->close();  }  void SCControls::doCancel() { -	// -	// Ask if changed Settings should be saved -	// -	if (settingsDirty) { -		int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard ); - -		qDebug() << "doCancel says: answer =" << ret; - -		switch (ret) { -			case QMessageBox::Save: -				save(); -				this->close(); -				break; -			case QMessageBox::Discard: -				this->close(); -				break; -			case QMessageBox::Cancel: -				// Cancel was clicked -				break; -			default: -				// should never be reached -			break; -		} -	} -	else { -		this->close(); -	} -} +    if (s.b->modifiedp()) { +        int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); -// -// Load the current Settings from the currently 'active' INI-file. -// -void SCControls::loadSettings() { -    QSettings settings("opentrack"); -    QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); -    QSettings iniFile( currentFile, QSettings::IniFormat );		// Application settings (in INI-file) -    iniFile.beginGroup ( "FSX" ); -    int act = iniFile.value("version", 0).toInt(); -    iniFile.endGroup(); -    ui.comboBox->setCurrentIndex(act); -	settingsDirty = false; +        switch (ret) { +        case QMessageBox::Save: +            s.b->save(); +            this->close(); +            break; +        case QMessageBox::Discard: +            s.b->revert(); +            this->close(); +            break; +        case QMessageBox::Cancel: +        default: +            break; +        } +    } +    else { +        this->close(); +    }  } -// -// Save the current Settings to the currently 'active' INI-file. -// -void SCControls::save() { -    QSettings settings("opentrack"); -    QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); -    QSettings iniFile( currentFile, QSettings::IniFormat );		// Application settings (in INI-file) -    iniFile.beginGroup ( "FSX" ); -    iniFile.setValue("version", ui.comboBox->currentIndex()); -    iniFile.endGroup(); -	settingsDirty = false; -} - -//////////////////////////////////////////////////////////////////////////////// -// Factory function that creates instances if the Protocol-settings dialog object. - -// Export both decorated and undecorated names. -//   GetProtocolDialog     - Undecorated name, which can be easily used with GetProcAddress -//                          Win32 API function. -//   _GetProtocolDialog@0  - Common name decoration for __stdcall functions in C language. -//#pragma comment(linker, "/export:GetProtocolDialog=_GetProtocolDialog@0") -  extern "C" FTNOIR_PROTOCOL_BASE_EXPORT IProtocolDialog* CALLING_CONVENTION GetDialog( )  {      return new SCControls; diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc_dll.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc_dll.cpp index 59a921b8..0a52fa96 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc_dll.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc_dll.cpp @@ -26,23 +26,6 @@  #include <QDebug>  #include "facetracknoir/global-settings.h" -FTNoIR_ProtocolDll::FTNoIR_ProtocolDll() { -} - -FTNoIR_ProtocolDll::~FTNoIR_ProtocolDll() -{ - -} - -//////////////////////////////////////////////////////////////////////////////// -// Factory function that creates instances if the Protocol object. - -// Export both decorated and undecorated names. -//   GetProtocolDll     - Undecorated name, which can be easily used with GetProcAddress -//						Win32 API function. -//   _GetProtocolDll@0  - Common name decoration for __stdcall functions in C language. -//#pragma comment(linker, "/export:GetProtocolDll=_GetProtocolDll@0") -  extern "C" FTNOIR_PROTOCOL_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata()  {  	return new FTNoIR_ProtocolDll;  | 
