Added persistence for the network settings

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6492 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
beaglejoe 2017-01-10 04:51:14 +00:00
parent 87f6403aff
commit d49c5f6fbb
5 changed files with 173 additions and 24 deletions

View File

@ -1,17 +1,26 @@
INCLUDE(../../cmake/macros.cmake)
# User settings.
SET(_CONFIG_USER_FILES logging.xml raceengine.xml screen.xml graph.xml sound.xml)
IF(OPTION_WEBSERVER)
SD_INSTALL_FILES(DATA config USER config
FILES logging.xml raceengine.xml screen.xml graph.xml sound.xml webserver.xml)
ELSE(OPTION_WEBSERVER)
SD_INSTALL_FILES(DATA config USER config
FILES logging.xml raceengine.xml screen.xml graph.xml sound.xml)
SET(_CONFIG_USER_FILES ${_CONFIG_USER_FILES} webserver.xml)
ENDIF(OPTION_WEBSERVER)
IF(OPTION_CLIENT_SERVER)
SET(_CONFIG_USER_FILES ${_CONFIG_USER_FILES} networking.xml)
ENDIF(OPTION_CLIENT_SERVER)
# User settings.
SD_INSTALL_FILES(DATA config USER config FILES ${_CONFIG_USER_FILES})
# Other config files.
SD_INSTALL_FILES(DATA config FILES raceresults.xsl)
SET (_OTHER_CONFIG_FILES raceresults.xsl)
SD_INSTALL_FILES(DATA config FILES ${_OTHER_CONFIG_FILES})
# Fictive = no-output target, for having source files available in IDEs.
ADD_CUSTOM_TARGET(config_xml SOURCES ${_CONFIG_USER_FILES} ${_OTHER_CONFIG_FILES})
# Race modes.
ADD_SUBDIRECTORY(raceman)

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
file : networking.xml
created : 07/11/2016
copyright : (C) 2016 Joe Thompson
email : beaglejoe@users.sourceforge.net
version : $Id$
-->
<!-- This program is free software; you can redistribute it and/or modify -->
<!-- it under the terms of the GNU General Public License as published by -->
<!-- the Free Software Foundation; either version 2 of the License, or -->
<!-- (at your option) any later version. -->
<!DOCTYPE params SYSTEM "../../libs/tgf/params.dtd">
<params name="networking" type="param" mode="mw" version="1.0">
<section name="Network Server Settings">
<attnum name="port" val="28500"/>
</section>
<section name="Network Client Settings">
<attstr name="ip4" val="127.0.0.1"/>
<attnum name="port" val="28500"/>
</section>
</params>

View File

@ -49,7 +49,11 @@ IF(OPTION_CLIENT_SERVER)
${RS}/csnetclientsettings.cpp
${RS}/csnetserversettings.cpp)
ENDIF(OPTION_CLIENT_SERVER)
SET(RACESCREENS_HEADERS ${RS}/racescreens.h ${RS}/garagemenu.h) #${RS}/raceweekendscreens.h)
IF(OPTION_CLIENT_SERVER)
SET(RACESCREENS_HEADERS ${RACESCREENS_HEADERS} ${RS}/csnetworking.h)
ENDIF(OPTION_CLIENT_SERVER)
SET(LEGACYMENU_SOURCES ${MAINSCREENS_SOURCES}
${CONFSCREENS_SOURCES}

View File

@ -33,6 +33,9 @@
#include "racescreens.h"
#include "csnetworking.h"
#include <csnetwork.h>
// Menu variables.
static void* menuScreen;
@ -42,27 +45,93 @@ static tRmNetworkSetting *MenuData;
static int rmcsIpEditId;
static int rmcsPortEditId;
// value variables
static int portNumber = SPEEDDREAMSPORT;
static std::string hostIP = "127.0.0.1";
extern std::string g_strHostIP;
extern std::string g_strHostPort;
static void
rmcsChangeIP(void * /* dummy */)
{
char *val;
static char buf[512];
val = GfuiEditboxGetString(menuScreen, rmcsIpEditId);
if (val!=NULL)
g_strHostIP = val;
static void
loadOptions()
{
snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), CS_PARAM_FILE);
void* grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
portNumber = GfParmGetNum(grHandle, CS_SECT_CLIENT, CS_ATT_PORT, NULL, SPEEDDREAMSPORT);
hostIP = GfParmGetStr(grHandle, CS_SECT_CLIENT, CS_ATT_IP4, "127.0.0.1");
// TODO
GfParmReleaseHandle(grHandle);
}
static void
rmcsChangePort(void * /* dummy */)
saveOptions()
{
char *val;
// Force current edit to loose focus (if one has it) and update associated variable.
GfuiUnSelectCurrent();
snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), CS_PARAM_FILE);
void* grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
GfParmSetNum(grHandle, CS_SECT_CLIENT, CS_ATT_PORT, NULL, portNumber);
GfParmSetStr(grHandle, CS_SECT_CLIENT, CS_ATT_IP4, hostIP.c_str());
// TODO
GfParmWriteFile(NULL, grHandle, "networking");
GfParmReleaseHandle(grHandle);
g_strHostIP = hostIP;
snprintf(buf,sizeof(buf),"%ud",portNumber);
g_strHostPort = buf;
}
static void
rmcsChangeIP(void* vp)
{
if (vp)
{
char* val = GfuiEditboxGetString(menuScreen, rmcsIpEditId);
if (val != NULL)
{
hostIP = val;
}
}
// Display current value
GfuiEditboxSetString(menuScreen, rmcsIpEditId, hostIP.c_str());
}
static void
rmcsChangePort(void* vp)
{
if (vp)
{
char* val = GfuiEditboxGetString(menuScreen, rmcsPortEditId);
if (val != NULL)
{
portNumber = strtol(val, (char **)NULL, 0);
}
}
// Display current value
snprintf(buf, sizeof(buf), "%d", portNumber);
GfuiEditboxSetString(menuScreen, rmcsPortEditId, buf);
}
static void
rmcsActivate(void* /* dummy */)
{
loadOptions();
rmcsChangeIP(0);
rmcsChangePort(0);
val = GfuiEditboxGetString(menuScreen, rmcsPortEditId);
if (val!=NULL)
g_strHostPort = val;
}
static void
@ -75,11 +144,19 @@ rmcsDeactivate(void *screen)
}
}
static void
rmcsNext(void* nextScreenHandle)
{
saveOptions();
rmcsDeactivate(nextScreenHandle);
}
static void
rmcsAddKeys(void)
{
GfuiMenuDefaultKeysAdd(menuScreen);
GfuiAddKey(menuScreen, GFUIK_RETURN, "Accept", MenuData->nextScreen, rmcsDeactivate, NULL);
GfuiAddKey(menuScreen, GFUIK_RETURN, "Accept", MenuData->nextScreen, rmcsNext, NULL);
GfuiAddKey(menuScreen, GFUIK_ESCAPE, "Cancel", MenuData->prevScreen, rmcsDeactivate, NULL);
}
@ -91,14 +168,14 @@ RmClientSettings(void *cs)
GfLogTrace("Entering Network Client Sttings menu.\n");
// Create the screen, load menu XML descriptor and create static controls.
menuScreen = GfuiScreenCreate(NULL, NULL, (tfuiCallback)NULL, NULL, (tfuiCallback)NULL, 1);
menuScreen = GfuiScreenCreate(NULL, NULL, rmcsActivate, NULL, (tfuiCallback)NULL, 1);
void *menuXML = GfuiMenuLoad("csnetworkclientmenu.xml");
GfuiMenuCreateStaticControls(menuScreen, menuXML);
rmcsIpEditId = GfuiMenuCreateEditControl(menuScreen, menuXML, "IPAddrEdit", 0, 0, rmcsChangeIP);
rmcsIpEditId = GfuiMenuCreateEditControl(menuScreen, menuXML, "IPAddrEdit", (void*)1, 0, rmcsChangeIP);
GfuiEditboxSetString(menuScreen, rmcsIpEditId, g_strHostIP.c_str());
rmcsPortEditId = GfuiMenuCreateEditControl(menuScreen, menuXML, "PortEdit", 0, 0, rmcsChangePort);
rmcsPortEditId = GfuiMenuCreateEditControl(menuScreen, menuXML, "PortEdit", (void*)1, 0, rmcsChangePort);
GfuiEditboxSetString(menuScreen, rmcsPortEditId, g_strHostPort.c_str());
// Create the variable title label.
@ -107,9 +184,9 @@ RmClientSettings(void *cs)
strTitle += MenuData->pRace->getManager()->getName().c_str();
GfuiLabelSetText(menuScreen, titleId, strTitle.c_str());
// Create Accept and Cancel buttons
// Create Next and Back buttons
GfuiMenuCreateButtonControl(menuScreen, menuXML, "nextbutton",
MenuData->nextScreen, rmcsDeactivate);
MenuData->nextScreen, rmcsNext);
GfuiMenuCreateButtonControl(menuScreen, menuXML, "backbutton",
MenuData->prevScreen, rmcsDeactivate);

View File

@ -0,0 +1,32 @@
/***************************************************************************
file : csnetworking.h
created : Mon Jan 09 2017
copyright : (C) 2017 by Joe Thompson
email : beaglejoe@users.sourceforge.net
version : $Id$
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef __CSNETWORKING_H__
#define __CSNETWORKING_H__
#define CS_PARAM_FILE "config/networking.xml"
#define CS_SECT_SERVER "Network Server Settings"
#define CS_SECT_CLIENT "Network Client Settings"
#define CS_ATT_IP4 "ip4"
#define CS_ATT_PORT "port"
#endif /* __CSNETWORKING_H__ */