From b349b07ad887ef784ac1dd2517c577e01d537b70 Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Mon, 23 Mar 2020 21:27:10 -0400 Subject: [PATCH] Initial commit. --- .gitignore | 4 +- Makefile.am | 29 +-- README.md | 2 + configure.ac | 12 +- src/cwtest/cfg/main.cfg | 8 + src/cwtest/main.cpp | 439 ++++++++++++++++++++++++++++++++++++++++ src/proj/main.c | 10 - 7 files changed, 474 insertions(+), 30 deletions(-) create mode 100644 README.md create mode 100644 src/cwtest/cfg/main.cfg create mode 100644 src/cwtest/main.cpp delete mode 100644 src/proj/main.c diff --git a/.gitignore b/.gitignore index 3830b41..8ba348f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # directories to ignore -libproj +libcw +libcw.la .deps autom4te.cache @@ -7,6 +8,7 @@ build-aux build/linux/debug/src/ build/linux/debug/bin build/linux/debug/lib +build/linux/debug/.libs build/linux/debug/include build/linux/release/src/ build/linux/release/bin diff --git a/Makefile.am b/Makefile.am index da66bb8..b968946 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,16 +14,18 @@ include_HEADERS = # -Wno-multichar - turns off multi-character constant warnings from cmAudioFile.c +WS_DIR = /home/kevin/sdk/libwebsockets/build/out -AM_CPPFLAGS = -D _GNU_SOURCE -I.. + +AM_CPPFLAGS = -D _GNU_SOURCE -I.. -I$(srcdir)/src/libcw -I$(WS_DIR)/include AM_CFLAGS = -Wno-multichar -AM_CXXFLAGS = +AM_CXXFLAGS = --std=c++17 AM_LDFLAGS = # debug/release switches if DEBUG AM_CFLAGS += -g - AM_CXXFLAGS += -g + AM_CXXFLAGS += -g -Wall else AM_CFLAGS += -O3 AM_CXXFLAGS += -O3 @@ -33,21 +35,22 @@ endif if OS_LINUX if OS_64 + AM_LDFLAGS += -L/usr/lib64 -L$(WS_DIR)/lib -Wl,-Bstatic -lasound -Wl,-Bdynamic AM_CFLAGS += -m64 endif endif +include src/libcw/Makefile.am + +libcw_la_SOURCES = $(libcwSRC) $(libcwHDR) +lib_LTLIBRARIES += libcw.la +include_HEADERS += $(libcwHDR) -include src/libproj/Makefile.am +src_cwtest_cwtest_SOURCES = src/cwtest/main.cpp +# autoconfig manual recommends setting direct referenes to non-3rd party libraries rather than using -L and -l +src_cwtest_cwtest_LDADD = libcw.la -lpthread -lwebsockets -src_libproj_libproj_la_SOURCES = $(libprojSRC) $(libprojHDR) -lib_LTLIBRARIES += src/libproj/libproj.la -include_HEADERS += $(libprojHDR) - - -src_proj_proj_SOURCES = src/proj/main.c -src_proj_proj_LDADD = src/libproj/libproj.la # autoconfig manual recommends setting direct referenes to non-3rd party libraries rather than using -L and -l -src_proj_proj_CPPFLAGS = -I$(srcdir)/src/libproj $(AM_CPPFLAGS) -bin_PROGRAMS += src/proj/proj +# src_cwtest_cwtest_CPPFLAGS = -I$(srcdir)/src/libcw $(AM_CPPFLAGS) +bin_PROGRAMS += src/cwtest/cwtest diff --git a/README.md b/README.md new file mode 100644 index 0000000..825eb0f --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +foo man choo + diff --git a/configure.ac b/configure.ac index 12b5227..70ca416 100644 --- a/configure.ac +++ b/configure.ac @@ -3,12 +3,12 @@ # this configure.ac or any of the Makefile.am files. # -AC_INIT([proj],[1.0],[proj@larke.org]) +AC_INIT([cwtest],[1.0],[cwtest@larke.org]) AC_CONFIG_AUX_DIR([build-aux]) # put aux files in build-aux AM_INIT_AUTOMAKE([1.9 -Wall foreign subdir-objects]) # subdir-objects needed for non-recursive make -AC_CONFIG_SRCDIR([src/proj/main.c]) +AC_CONFIG_SRCDIR([src/cwtest/main.cpp]) AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_MACRO_DIRS([m4]) AM_PROG_AR @@ -22,7 +22,7 @@ AC_PROG_CXX AM_PROG_CC_C_O # Checks for libraries. -AC_CHECK_LIB([cairo],[cairo_debug_reset_static_data],[AC_MSG_RESULT([The 'cairo' library was found.])],[AC_MSG_ERROR([The 'cairo' library was not found.])]) +# AC_CHECK_LIB([cairo],[cairo_debug_reset_static_data],[AC_MSG_RESULT([The 'cairo' library was found.])],[AC_MSG_ERROR([The 'cairo' library was not found.])]) #TODO: add more library checks @@ -89,8 +89,8 @@ fi # # AC_SUBST([ADD_LIB], [$add_lib]) -proj_dir=src/libproj - AC_SUBST([proj_dir]) +#ldir = src/libcw +#AC_SUBST([ldir]) AC_CONFIG_FILES([ Makefile ]) AC_OUTPUT diff --git a/src/cwtest/cfg/main.cfg b/src/cwtest/cfg/main.cfg new file mode 100644 index 0000000..898901b --- /dev/null +++ b/src/cwtest/cfg/main.cfg @@ -0,0 +1,8 @@ +{ + + a:1, + b:2, + c:[1.23,4.56,7.89] + + +} \ No newline at end of file diff --git a/src/cwtest/main.cpp b/src/cwtest/main.cpp new file mode 100644 index 0000000..f599188 --- /dev/null +++ b/src/cwtest/main.cpp @@ -0,0 +1,439 @@ +#include "cwCommon.h" +#include "cwLog.h" +#include "cwCommonImpl.h" +#include "cwMem.h" +#include "cwFileSys.h" +#include "cwTextBuf.h" +#include "cwLex.h" +#include "cwText.h" +#include "cwNumericConvert.h" +#include "cwObject.h" +#include "cwThread.h" +#include "cwWebSock.h" +#include "cwWebSockSvr.h" +#include "cwSerialPort.h" +#include "cwSerialPortSrv.h" +#include "cwSocket.h" +#include "cwUi.h" +#include "cwUiTest.h" +#include "cwTime.h" +#include "cwMidi.h" +#include "cwMidiPort.h" +#include "cwAudioDevice.h" +#include "cwAudioDeviceTest.h" +#include "cwAudioDeviceAlsa.h" +#include "cwAudioBuf.h" +#include "cwTcpSocket.h" +#include "cwTcpSocketSrv.h" +#include "cwTcpSocketTest.h" +#include "cwMdns.h" +#include "cwDnsSd.h" +#include "cwEuCon.h" +#include "cwIo.h" +#include "cwIoTest.h" +//#include "cwNbMem.h" + +#include + + +void print() +{ + printf("\n"); +} + +template + void print(T0 t0, T1 t1, ARGS&&... args) +{ + static const unsigned short int size = sizeof...(ARGS); + std::cout << t0 << ":" << t1 << " (" << size << "), "; + print(std::forward(args)...); +} + +void get(int) +{ + printf("\n"); +} + +template + void get(int n, T0 t0, T1& t1, ARGS&&... args) +{ + std::cout << t0 << ":" " (" << n << "), "; + t1 = n; + get(n+1,std::forward(args)...); +} + + +template< typename T0 > + unsigned fmt_data( char* buf, unsigned n, T0 t0 ) +{ + return cw::toText(buf, n, t0); +} + +template<> + unsigned fmt_data( char* buf, unsigned n, const char* v ) +{ + return cw::toText(buf,n,v); +} + +unsigned to_text_base(char*, unsigned n, unsigned i ) +{ return i; } + +template + unsigned to_text_base( char* buf, unsigned n, unsigned i, T0 t0, T1 t1, ARGS&&... args) +{ + i += fmt_data(buf+i, n-i, t0); + i += fmt_data(buf+i, n-i, t1); + + if( i >= n ) + return i; + + return to_text_base(buf,n,i,std::forward(args)...); +} + +template< typename... ARGS> + unsigned to_text(const char* prefix, char* buf, unsigned n, ARGS&&... args) +{ + unsigned i = cw::toText(buf, n, prefix ); + + return to_text_base(buf,n,i,std::forward(args)...); +} + + + +using namespace std; + + +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"); + + const int bufN = 32; + char buf[bufN]; + buf[0] = '\0'; + unsigned n = to_text("prefix: ",buf,bufN,"a",1,"b",3.2,"hi","ho"); + printf("%i : %s\n",n,buf); +} + + + +void fileSysTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + cw::filesys::pathPart_t* pp = cw::filesys::pathParts(__FILE__); + + cwLogInfo("dir:%s",pp->dirStr); + cwLogInfo("fn: %s",pp->fnStr); + cwLogInfo("ext:%s",pp->extStr); + + char* fn = cw::filesys::makeFn( pp->dirStr, pp->fnStr, pp->extStr, nullptr ); + + cwLogInfo("fn: %s",fn); + + cw::mem::release(pp); + cw::mem::release(fn); + +} + +void numbCvtTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + 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 ); + +} + +void objectTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + cw::object_t* o; + const char s [] = "{ a:1, b:2, c:[ 1.23, 4.56 ], d:true, e:false, f:true }"; + cw::objectFromString(s,o); + + int v; + o->get("b",v); + printf("value:%i\n",v); + + o->print(); + + int a = 0; + int b = 0; + + o->getv("a",a,"b",b); + printf("G: %i %i\n",a,b); + + o->free(); +} + +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(); } +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(); } +void audioDevRpt( cw::object_t* cfg, int argc, const char* argv[] ) { cw::audio::device::report(); } +void ioTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::io::test(); } + +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]); + const char* remoteAddr = "127.0.0.1"; //"224.0.0.251"; //"127.0.0.1"; + printf("local:%i remote:%i\n", localPort, remotePort); + + 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 ); + } +} + +void socketSrvUdpTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + if( argc >= 4 ) + { + unsigned short localPort = atoi(argv[1]); + const char* remoteIp = argv[2]; + unsigned short remotePort = atoi(argv[3]); + + printf("local:%i to remote:%s %i\n", localPort, remoteIp, remotePort); + + cw::net::srv::test_udp_srv( localPort, remoteIp, remotePort ); + } +} +void socketSrvTcpTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + if( argc >= 4 ) + { + unsigned short localPort = atoi(argv[1]); + const char* remoteIp = argv[2]; + unsigned short remotePort = atoi(argv[3]); + + printf("local:%i to remote:%s %i\n", localPort, remoteIp, remotePort); + + cw::net::srv::test_tcp_srv( localPort, remoteIp, remotePort ); + } +} + +void sockMgrTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + bool tcpFl = false; + unsigned short localPort = 0; + const char* remoteIp = nullptr; + unsigned short remotePort = 0; + + if( argc <3 ) + { + printf("Invalid argument count."); + printf("Usage: ./cw_rt sockMgrTest 'udp | tcp' { }\n"); + goto errLabel; + } + + + if( argc >= 4 ) + { + remoteIp = argv[3]; + + if( argc >= 5 ) + remotePort = atoi(argv[4]); + + } + + if( strcmp(argv[1],"tcp")!=0 && strcmp(argv[1],"udp")!=0 ) + { + printf("The first argument must be 'udp' or 'tcp'\n"); + goto errLabel; + } + + tcpFl = strcmp(argv[1],"tcp")==0; + localPort = atoi(argv[2]); + + if( remoteIp != nullptr && remotePort == 0 ) + { + printf("A remote adddress '%s' was given but no remote port was given.", remoteIp); + goto errLabel; + } + + printf("style:%s local:%i to remote:%s %i\n", argv[1], localPort, cwStringNullGuard(remoteIp), remotePort); + + cw::socksrv::testMain( tcpFl, localPort, remoteIp, remotePort ); + + errLabel: + + return; +} + +void uiTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + cw::ui::test(); +} + +void socketMdnsTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + cw::net::mdns::test(); +} + +void dnsSdTest( cw::object_t* cfg, int arg, const char* argv[] ) +{ + cw::net::dnssd::test(); +} + +void euConTest( cw::object_t* cfg, int arg, const char* argv[] ) +{ + cw::net::eucon::test(); +} + + +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 1 ? argv[1] : nullptr; + const char* mode = argc > 2 ? argv[2] : nullptr; + + + cw::log::createGlobal(); + + // 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) + { + //printf("'%s' '%s'\n",modeArray[i].label,mode); + + if( cw::textCompare(modeArray[i].label,mode)==0 ) + { + modeArray[i].func( cfg, argc-2, argv + 2 ); + break; + } + } + // 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(); + } + + cw::log::destroyGlobal(); + + return 0; +} + + + + + diff --git a/src/proj/main.c b/src/proj/main.c deleted file mode 100644 index 61b3872..0000000 --- a/src/proj/main.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "mylib.h" -#include "config.h" - -int main( int argc, char* argv[] ) -{ - int result = my_func(1,2); - printf("tmpl_app %i\n",result); - return 0; -}