87 lines
2.4 KiB
C++
87 lines
2.4 KiB
C++
#include <common/stdio.hpp>
|
|
#include <CapServer/Params.hpp>
|
|
|
|
void Params::setArgs(int argc,char **argv)
|
|
{
|
|
String strArg;
|
|
getParams(argc,argv);
|
|
if(getServer().isNull())setServer("127.0.0.1");
|
|
if(getHost().isNull())setHost("127.0.0.1");
|
|
if(getPort().isNull())setPort("1024");
|
|
if(getTimeout().isNull())setTimeout("1000");
|
|
if(getDevice().isNull())setDevice("0");
|
|
strArg=getValue(mRetainKey);
|
|
strArg.lower();
|
|
if(!(strArg==String("true")) && !(strArg==String("false")))setRetain(false);
|
|
else if(strArg==String("true"))setRetain(true);
|
|
else setRetain(false);
|
|
strArg=getValue(mDebugKey);
|
|
strArg.lower();
|
|
if(!(strArg==String("true")) && !(strArg==String("false")))setDebug(false);
|
|
else if(strArg==String("true"))setDebug(true);
|
|
else setDebug(false);
|
|
strArg=getValue(mShowSrcDlgKey);
|
|
strArg.lower();
|
|
if(!(strArg==String("true")) && !(strArg==String("false")))setShowSrcDlg(false);
|
|
else if(strArg==String("true"))setShowSrcDlg(true);
|
|
else setShowSrcDlg(false);
|
|
}
|
|
|
|
int Params::getParams(int argc,char**argv)
|
|
{
|
|
mNameValuePairs.remove();
|
|
for(int index=0;index<argc;index++)
|
|
{
|
|
NameValuePair nameValuePair;
|
|
nameValuePair.fromString(argv[index]);
|
|
mNameValuePairs.insert(&nameValuePair);
|
|
::OutputDebugString(nameValuePair.toString()+String("\n"));
|
|
}
|
|
return mNameValuePairs.size();
|
|
}
|
|
|
|
String Params::getValue(const String &key)const
|
|
{
|
|
for(int index=0;index<mNameValuePairs.size();index++)
|
|
{
|
|
NameValuePair &nameValuePair=((Params&)*this).mNameValuePairs[index];
|
|
if(nameValuePair.getName()==key)return nameValuePair.getValue();
|
|
}
|
|
return String();
|
|
}
|
|
|
|
void Params::setValue(const String &key,const String &value)
|
|
{
|
|
for(int index=0;index<mNameValuePairs.size();index++)
|
|
{
|
|
NameValuePair &nameValuePair=mNameValuePairs[index];
|
|
if(nameValuePair.getName()==key)
|
|
{
|
|
nameValuePair.setValue(value);
|
|
return;
|
|
}
|
|
}
|
|
mNameValuePairs.insert(&NameValuePair(key,value));
|
|
}
|
|
|
|
Params::Request Params::getRequest(void)const
|
|
{
|
|
String strRequest(getRun());
|
|
if(strRequest=="client")return Client;
|
|
else if(strRequest=="server")return Server;
|
|
else if(strRequest=="settings")return Settings;
|
|
return None;
|
|
}
|
|
|
|
void Params::showParams(void)
|
|
{
|
|
for(int index=0;index<mNameValuePairs.size();index++)
|
|
{
|
|
NameValuePair &nameValuePair=mNameValuePairs[index];
|
|
::printf("[Params::showParams]arg[%d]%s=%s\n",
|
|
index,
|
|
nameValuePair.getName().str(),
|
|
nameValuePair.getValue().str());
|
|
}
|
|
}
|