2019-12-19 03:24:12 +00:00
|
|
|
#include "cwCommon.h"
|
|
|
|
#include "cwLog.h"
|
|
|
|
#include "cwCommonImpl.h"
|
|
|
|
#include "cwMem.h"
|
|
|
|
#include "cwFileSys.h"
|
2019-12-24 15:05:24 +00:00
|
|
|
#include "cwTextBuf.h"
|
2019-12-19 03:24:12 +00:00
|
|
|
#include "cwLex.h"
|
|
|
|
#include "cwNumericConvert.h"
|
|
|
|
#include "cwObject.h"
|
|
|
|
#include "cwThread.h"
|
|
|
|
#include "cwText.h"
|
2019-12-24 15:05:24 +00:00
|
|
|
#include "cwWebSock.h"
|
|
|
|
#include "cwWebSockSvr.h"
|
|
|
|
#include "cwSerialPort.h"
|
|
|
|
#include "cwSerialPortSrv.h"
|
|
|
|
#include "cwMidi.h"
|
|
|
|
#include "cwTime.h"
|
|
|
|
#include "cwMidiPort.h"
|
2019-12-26 02:44:14 +00:00
|
|
|
#include "cwAudioDevice.h"
|
|
|
|
#include "cwAudioDeviceTest.h"
|
|
|
|
#include "cwAudioDeviceAlsa.h"
|
2019-12-24 15:05:24 +00:00
|
|
|
#include "cwAudioBuf.h"
|
2019-12-27 21:52:45 +00:00
|
|
|
#include "cwTcpSocket.h"
|
|
|
|
#include "cwTcpSocketSrv.h"
|
|
|
|
#include "cwTcpSocketTest.h"
|
2020-01-27 22:54:40 +00:00
|
|
|
#include "cwMdns.h"
|
|
|
|
//#include "cwNbMem.h"
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
void print()
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
template<typename T0, typename T1, typename ...ARGS>
|
|
|
|
void print(T0 t0, T1 t1, ARGS&&... args)
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
|
|
|
static const unsigned short int size = sizeof...(ARGS);
|
|
|
|
std::cout << t0 << ":" << t1 << " (" << size << "), ";
|
2019-12-24 15:05:24 +00:00
|
|
|
print(std::forward<ARGS>(args)...);
|
2019-12-19 03:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void get(int)
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T0, typename T1, typename... ARGS>
|
2019-12-24 15:05:24 +00:00
|
|
|
void get(int n, T0 t0, T1& t1, ARGS&&... args)
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
|
|
|
std::cout << t0 << ":" " (" << n << "), ";
|
2019-12-24 15:05:24 +00:00
|
|
|
t1 = n;
|
|
|
|
get(n+1,std::forward<ARGS>(args)...);
|
2019-12-19 03:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
void variadicTplTest( cw::object_t* cfg, int argc, const char* argv[] )
|
|
|
|
{
|
|
|
|
print("a", 1, "b", 3.14, "c",5L);
|
|
|
|
|
|
|
|
int v0=0,v1=0,v2=0;
|
|
|
|
get(0, "a", v0, "b", v1, "c", v2);
|
|
|
|
printf("get: %i %i %i",v0,v1,v2);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void fileSysTest( cw::object_t* cfg, int argc, const char* argv[] )
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
2019-12-28 02:51:28 +00:00
|
|
|
cw::filesys::pathPart_t* pp = cw::filesys::pathParts(__FILE__);
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
cwLogInfo("dir:%s",pp->dirStr);
|
|
|
|
cwLogInfo("fn: %s",pp->fnStr);
|
|
|
|
cwLogInfo("ext:%s",pp->extStr);
|
|
|
|
|
2019-12-28 02:51:28 +00:00
|
|
|
char* fn = cw::filesys::makeFn( pp->dirStr, pp->fnStr, pp->extStr, nullptr );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
cwLogInfo("fn: %s",fn);
|
|
|
|
|
2019-12-28 02:51:28 +00:00
|
|
|
cw::mem::release(pp);
|
|
|
|
cw::mem::release(fn);
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
void numbCvtTest( cw::object_t* cfg, int argc, const char* argv[] )
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
|
|
|
int8_t x0 = 3;
|
|
|
|
int x1 = 127;
|
|
|
|
|
|
|
|
cw::numeric_convert( x1, x0 );
|
|
|
|
printf("%i %i\n",x0,x1);
|
|
|
|
|
|
|
|
|
|
|
|
int v0;
|
|
|
|
double v1;
|
|
|
|
cw::string_to_number("123",v0);
|
|
|
|
cw::string_to_number("3.4",v1);
|
|
|
|
printf("%i %f\n",v0,v1 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
void objectTest( cw::object_t* cfg, int argc, const char* argv[] )
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
|
|
|
cw::object_t* o;
|
|
|
|
const char s [] = "{ a:1, b:2, c:[ 1.23, 4.56 ] }";
|
|
|
|
cw::objectFromString(s,o);
|
|
|
|
|
|
|
|
int v;
|
|
|
|
o->get("b",v);
|
|
|
|
printf("value:%i\n",v);
|
|
|
|
|
|
|
|
o->print();
|
|
|
|
|
|
|
|
int a = 0;
|
|
|
|
int b = 0;
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
o->getv("a",a,"b",b);
|
2019-12-19 03:24:12 +00:00
|
|
|
printf("G: %i %i\n",a,b);
|
|
|
|
|
|
|
|
o->free();
|
|
|
|
}
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
void threadTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::threadTest(); }
|
|
|
|
void websockSrvTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::websockSrvTest(); }
|
|
|
|
void serialPortSrvTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::serialPortSrvTest(); }
|
|
|
|
void midiDeviceTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::midi::device::test();}
|
|
|
|
void textBufTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::textBuf::test(); }
|
|
|
|
void audioBufTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::audio::buf::test(); }
|
2019-12-26 02:44:14 +00:00
|
|
|
void audioDevTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::audio::device::test( argc, argv ); }
|
|
|
|
void audioDevAlsaTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::audio::device::alsa::report(); }
|
2020-01-27 22:54:40 +00:00
|
|
|
//void nbmemTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::nbmem::test(); }
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
void socketTest( cw::object_t* cfg, int argc, const char* argv[] )
|
|
|
|
{
|
|
|
|
if( argc >= 3 )
|
|
|
|
{
|
|
|
|
unsigned short localPort = atoi(argv[1]);
|
|
|
|
unsigned short remotePort = atoi(argv[2]);
|
2020-01-27 22:54:40 +00:00
|
|
|
const char* remoteAddr = "127.0.0.1"; //"224.0.0.251"; //"127.0.0.1";
|
2019-12-27 21:52:45 +00:00
|
|
|
printf("local:%i remote:%i\n", localPort, remotePort);
|
|
|
|
|
2020-01-27 22:54:40 +00:00
|
|
|
cw::net::socket::test( localPort, remoteAddr, remotePort );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void socketTestTcp( cw::object_t* cfg, int argc, const char* argv[] )
|
|
|
|
{
|
|
|
|
// server: ./cw_rt main.cfg socketTcp 5434 5435 dgram/stream server
|
|
|
|
// client: ./cw_rt main.cfg socketTcp 5435 5434 dgram/stream
|
|
|
|
|
|
|
|
if( argc >= 4 )
|
|
|
|
{
|
|
|
|
unsigned short localPort = atoi(argv[1]);
|
|
|
|
unsigned short remotePort = atoi(argv[2]);
|
|
|
|
bool dgramFl = strcmp(argv[3],"dgram") == 0;
|
|
|
|
bool serverFl = false;
|
|
|
|
|
|
|
|
if( argc >= 5 )
|
|
|
|
serverFl = strcmp(argv[4],"server") == 0;
|
|
|
|
|
|
|
|
printf("local:%i remote:%i %s %s\n", localPort, remotePort, dgramFl ? "dgram":"stream", serverFl?"server":"client");
|
|
|
|
|
|
|
|
cw::net::socket::test_tcp( localPort, "127.0.0.1", remotePort, dgramFl, serverFl );
|
2019-12-27 21:52:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void socketSrvTest( cw::object_t* cfg, int argc, const char* argv[] )
|
|
|
|
{
|
|
|
|
if( argc >= 3 )
|
|
|
|
{
|
|
|
|
unsigned short localPort = atoi(argv[1]);
|
|
|
|
unsigned short remotePort = atoi(argv[2]);
|
|
|
|
|
|
|
|
printf("local:%i remote:%i\n", localPort, remotePort);
|
|
|
|
|
|
|
|
cw::net::srv::test( localPort, "127.0.0.1", remotePort );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 22:54:40 +00:00
|
|
|
void socketMdnsTest( cw::object_t* cfg, int argc, const char* argv[] )
|
|
|
|
{
|
|
|
|
cw::net::mdns::test();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-28 04:35:39 +00:00
|
|
|
void dirEntryTest( cw::object_t* cfg, int argc, const char* argv[] )
|
|
|
|
{
|
|
|
|
if( argc >= 2 )
|
|
|
|
{
|
|
|
|
const char* path = argv[1];
|
|
|
|
unsigned dirEntryN = 0;
|
|
|
|
unsigned includeFlags = cw::filesys::kFileFsFl | cw::filesys::kDirFsFl | cw::filesys::kFullPathFsFl | cw::filesys::kRecurseFsFl;
|
|
|
|
cw::filesys::dirEntry_t* de = cw::filesys::dirEntries( path,includeFlags, &dirEntryN );
|
|
|
|
for(unsigned i=0; i<dirEntryN; ++i)
|
|
|
|
cwLogInfo("%s",de[i].name);
|
|
|
|
|
|
|
|
cw::mem::release(de);
|
|
|
|
}
|
|
|
|
}
|
2019-12-27 21:52:45 +00:00
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
void stubTest( cw::object_t* cfg, int argc, const char* argv[] )
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
2020-01-27 22:54:40 +00:00
|
|
|
/*
|
2019-12-24 15:05:24 +00:00
|
|
|
typedef struct v_str
|
|
|
|
{
|
|
|
|
int x = 1;
|
|
|
|
int y = 2;
|
|
|
|
void* z = nullptr;
|
|
|
|
} v_t;
|
|
|
|
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
v_t v;
|
|
|
|
printf("%i %i %p\n",v.x,v.y,v.z);
|
2020-01-27 22:54:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
const char* s = "\x16lmac=00-90-D5-80-F4-DE\x7dummy=0";
|
|
|
|
printf("len:%li\n",strlen(s));
|
|
|
|
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
}
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
int main( int argc, const char* argv[] )
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
typedef struct func_str
|
|
|
|
{
|
|
|
|
const char* label;
|
2019-12-24 15:05:24 +00:00
|
|
|
void (*func)(cw::object_t* cfg, int argc, const char* argv[] );
|
2019-12-19 03:24:12 +00:00
|
|
|
} func_t;
|
|
|
|
|
|
|
|
// function dispatch list
|
|
|
|
func_t modeArray[] =
|
|
|
|
{
|
2019-12-24 15:05:24 +00:00
|
|
|
{ "variadicTpl", variadicTplTest },
|
2019-12-19 03:24:12 +00:00
|
|
|
{ "fileSys", fileSysTest },
|
|
|
|
{ "numbCvt", numbCvtTest },
|
|
|
|
{ "object", objectTest },
|
|
|
|
{ "thread", threadTest },
|
2019-12-24 15:05:24 +00:00
|
|
|
{ "websockSrv", websockSrvTest },
|
|
|
|
{ "serialSrv", serialPortSrvTest },
|
|
|
|
{ "midiDevice", midiDeviceTest },
|
|
|
|
{ "textBuf", textBufTest },
|
|
|
|
{ "audioBuf", audioBufTest },
|
2019-12-26 02:44:14 +00:00
|
|
|
{ "audioDev",audioDevTest },
|
|
|
|
{ "audioDevAlsa", audioDevAlsaTest },
|
2020-01-27 22:54:40 +00:00
|
|
|
//{ "nbmem", nbmemTest },
|
2019-12-27 21:52:45 +00:00
|
|
|
{ "socket", socketTest },
|
2020-01-27 22:54:40 +00:00
|
|
|
{ "socketTcp", socketTestTcp },
|
2019-12-27 21:52:45 +00:00
|
|
|
{ "socketSrv", socketSrvTest },
|
2020-01-27 22:54:40 +00:00
|
|
|
{ "socketMdns", socketMdnsTest },
|
2019-12-28 04:35:39 +00:00
|
|
|
{ "dirEntry", dirEntryTest },
|
2019-12-24 15:05:24 +00:00
|
|
|
{ "stub", stubTest },
|
2019-12-19 03:24:12 +00:00
|
|
|
{ nullptr, nullptr }
|
|
|
|
};
|
|
|
|
|
|
|
|
// read the command line
|
|
|
|
cw::object_t* cfg = NULL;
|
|
|
|
const char* cfgFn = argc > 1 ? argv[1] : nullptr;
|
|
|
|
const char* mode = argc > 2 ? argv[2] : nullptr;
|
|
|
|
|
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
cw::log::createGlobal();
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
// if valid command line args were given and the cfg file was successfully read
|
|
|
|
if( cfgFn != nullptr && mode != nullptr && objectFromFile( cfgFn, cfg ) == cw::kOkRC )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
// locate the requested function and call it
|
|
|
|
for(i=0; modeArray[i].label!=nullptr; ++i)
|
2020-01-27 22:54:40 +00:00
|
|
|
{
|
|
|
|
//printf("'%s' '%s'\n",modeArray[i].label,mode);
|
|
|
|
|
2019-12-19 03:24:12 +00:00
|
|
|
if( cw::textCompare(modeArray[i].label,mode)==0 )
|
|
|
|
{
|
|
|
|
modeArray[i].func( cfg, argc-2, argv + 2 );
|
|
|
|
break;
|
|
|
|
}
|
2020-01-27 22:54:40 +00:00
|
|
|
}
|
2019-12-19 03:24:12 +00:00
|
|
|
// if the requested function was not found
|
|
|
|
if( modeArray[i].label == nullptr )
|
|
|
|
cwLogError(cw::kInvalidArgRC,"The mode selector: '%s' is not valid.", cwStringNullGuard(mode));
|
|
|
|
|
|
|
|
cfg->free();
|
|
|
|
}
|
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
cw::log::destroyGlobal();
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|