Changes to support autotools build.

Changed #define cwLINUX to OS_LINUX.
This commit is contained in:
kevin.larke 2020-03-24 08:51:51 -04:00
parent 29e34cbeca
commit 7b2ebd5580
14 changed files with 62 additions and 522 deletions

View File

@ -1,56 +0,0 @@
HDR = cwCommon.h cwCommonImpl.h cwMem.h cwLog.h cwUtility.h
SRC = cwCommonImpl.cpp cwMem.cpp cwLog.cpp cwUtility.cpp
HDR += cwFileSys.h cwText.h cwFile.h cwTime.h cwLex.h cwNumericConvert.h
SRC += cwFileSys.cpp cwText.cpp cwFile.cpp cwTime.cpp cwLex.cpp
HDR += cwObject.h cwObjectTemplate.h cwTextBuf.h
SRC += cwObject.cpp cwTextBuf.cpp
HDR += cwThread.h cwMutex.h cwMpScNbQueue.h
SRC += cwThread.cpp cwMutex.cpp
HDR += cwWebSock.h cwWebSockSvr.h cwLib.h
SRC += cwWebSock.cpp cwWebSockSvr.cpp cwLib.cpp
HDR += cwUiDecls.h cwUi.h cwUiTest.h
SRC += cwUi.cpp cwUiTest.cpp
HDR += cwSerialPortDecls.h cwSerialPort.h cwSerialPortSrv.h
SRC += cwSerialPort.cpp cwSerialPortSrv.cpp
HDR += cwMidiDecls.h cwMidi.h cwMidiPort.h
SRC += cwMidi.cpp cwMidiPort.cpp cwMidiAlsa.cpp
HDR += cwAudioBufDecls.h cwAudioBuf.h cwAudioDeviceDecls.h cwAudioDevice.h cwAudioDeviceAlsa.h
SRC += cwAudioBuf.cpp cwAudioDevice.cpp cwAudioDeviceAlsa.cpp cwAudioDeviceTest.cpp
HDR += cwSocketDecls.h cwSocket.h
SRC += cwSocket.cpp
HDR += cwIo.h cwIoTest.h
SRC += cwIo.cpp cwIoTest.cpp
HDR += cwTcpSocket.h cwTcpSocketSrv.h cwTcpSocketTest.h
SRC += cwTcpSocket.cpp cwTcpSocketSrv.cpp cwTcpSocketTest.cpp
HDR += cwMdns.h cwEuCon.h cwDnsSd.h dns_sd/dns_sd.h dns_sd/dns_sd_print.h dns_sd/dns_sd_const.h dns_sd/fader.h dns_sd/rpt.h
SRC += cwMdns.cpp cwEuCon.cpp cwDnsSd.cpp dns_sd/dns_sd.cpp dns_sd/dns_sd_print.cpp dns_sd/fader.cpp dns_sd/rpt.cpp
# -ldl = dlopen,dlclose,dlsym
LIBS = -lpthread -lwebsockets -lasound -ldl
WS_DIR = /home/kevin/sdk/libwebsockets/build/out
INC_PATH = $(WS_DIR)/include
LIB_PATH = $(WS_DIR)/lib
cw_rt : main.cpp $(SRC) $(HDR)
g++ -g --std=c++17 $(LIBS) -Wall -L$(LIB_PATH) -I$(INC_PATH) -I .. -DcwLINUX -o $@ main.cpp $(SRC)
avahi_surface : cwAvahiSurface.cpp $(SRC) $(HDR)
g++ -g --std=c++17 $(LIBS) -Wall -L$(LIB_PATH) -lavahi-core -lavahi-common -lavahi-client -I$(INC_PATH) -DcwLINUX -o $@ cwAvahiSurface.cpp $(SRC)

49
Makefile.am Normal file
View File

@ -0,0 +1,49 @@
dir = src/libcw
libcwHDR =
libcwSRC =
libcwHDR += $(dir)/cwCommon.h $(dir)/cwCommonImpl.h $(dir)/cwMem.h $(dir)/cwLog.h $(dir)/cwUtility.h
libcwSRC += $(dir)/cwCommonImpl.cpp $(dir)/cwMem.cpp $(dir)/cwLog.cpp $(dir)/cwUtility.cpp
libcwHDR += $(dir)/cwFileSys.h $(dir)/cwText.h $(dir)/cwFile.h $(dir)/cwTime.h $(dir)/cwLex.h $(dir)/cwNumericConvert.h
libcwSRC += $(dir)/cwFileSys.cpp $(dir)/cwText.cpp $(dir)/cwFile.cpp $(dir)/cwTime.cpp $(dir)/cwLex.cpp
libcwHDR += $(dir)/cwObject.h $(dir)/cwObjectTemplate.h $(dir)/cwTextBuf.h
libcwSRC += $(dir)/cwObject.cpp $(dir)/cwTextBuf.cpp
libcwHDR += $(dir)/cwThread.h $(dir)/cwMutex.h $(dir)/cwMpScNbQueue.h
libcwSRC += $(dir)/cwThread.cpp $(dir)/cwMutex.cpp
libcwHDR += $(dir)/cwWebSock.h $(dir)/cwWebSockSvr.h $(dir)/cwLib.h
libcwSRC += $(dir)/cwWebSock.cpp $(dir)/cwWebSockSvr.cpp $(dir)/cwLib.cpp
libcwHDR += $(dir)/cwUiDecls.h $(dir)/cwUi.h $(dir)/cwUiTest.h
libcwSRC += $(dir)/cwUi.cpp $(dir)/cwUiTest.cpp
libcwHDR += $(dir)/cwSerialPortDecls.h $(dir)/cwSerialPort.h $(dir)/cwSerialPortSrv.h
libcwSRC += $(dir)/cwSerialPort.cpp $(dir)/cwSerialPortSrv.cpp
libcwHDR += $(dir)/cwMidiDecls.h $(dir)/cwMidi.h $(dir)/cwMidiPort.h
libcwSRC += $(dir)/cwMidi.cpp $(dir)/cwMidiPort.cpp $(dir)/cwMidiAlsa.cpp
libcwHDR += $(dir)/cwAudioDeviceDecls.h $(dir)/cwAudioDevice.h $(dir)/cwAudioDeviceAlsa.h
libcwSRC += $(dir)/cwAudioDevice.cpp $(dir)/cwAudioDeviceAlsa.cpp $(dir)/cwAudioDeviceTest.cpp
libcwHDR += $(dir)/cwAudioBufDecls.h $(dir)/cwAudioBuf.h
libcwSRC += $(dir)/cwAudioBuf.cpp
libcwHDR += $(dir)/cwSocketDecls.h $(dir)/cwSocket.h
libcwSRC += $(dir)/cwSocket.cpp
libcwHDR += $(dir)/cwIo.h $(dir)/cwIoTest.h
libcwSRC += $(dir)/cwIo.cpp $(dir)/cwIoTest.cpp
libcwHDR += $(dir)/cwTcpSocket.h $(dir)/cwTcpSocketSrv.h $(dir)/cwTcpSocketTest.h
libcwSRC += $(dir)/cwTcpSocket.cpp $(dir)/cwTcpSocketSrv.cpp $(dir)/cwTcpSocketTest.cpp
libcwHDR += $(dir)/cwMdns.h $(dir)/cwEuCon.h $(dir)/cwDnsSd.h $(dir)/dns_sd/dns_sd.h $(dir)/dns_sd/dns_sd_print.h $(dir)/dns_sd/dns_sd_const.h $(dir)/dns_sd/fader.h $(dir)/dns_sd/rpt.h
libcwSRC += $(dir)/cwMdns.cpp $(dir)/cwEuCon.cpp $(dir)/cwDnsSd.cpp $(dir)/dns_sd/dns_sd.cpp $(dir)/dns_sd/dns_sd_print.cpp $(dir)/dns_sd/fader.cpp $(dir)/dns_sd/rpt.cpp

View File

@ -1,7 +1,7 @@
#ifndef cwCommonImpl_H
#define cwCommonImpl_H
#include "config.h"
#include <cstdlib>
#include <cstring>
#include <cassert>
@ -16,7 +16,7 @@
#include <limits> // std::numeric_limits<
#include <atomic>
#if defined(cwLINUX) || defined(cwOSX)
#if defined(OS_LINUX) || defined(OS_OSX)
#define cwPOSIX_FILE_SYS
#include <time.h> // timespec
#include <netinet/in.h> // struct sockaddr_in

View File

@ -6,7 +6,7 @@
#include "cwText.h"
#include "cwFile.h"
#ifdef cwLINUX
#ifdef OS_LINUX
#include <sys/stat.h>
#endif

View File

@ -5,7 +5,7 @@
#include "cwCommonImpl.h"
#include "cwMem.h"
#ifdef cwLINUX
#ifdef OS_LINUX
#include <libgen.h> // basename() dirname()
#include <sys/stat.h>
#include <dirent.h> // opendir()/readdir()

View File

@ -5,7 +5,7 @@
#include "cwFileSys.h"
#include "cwLib.h"
#ifdef cwLINUX
#ifdef OS_LINUX
#include <dlfcn.h>

View File

@ -3,7 +3,7 @@
#include "cwCommonImpl.h"
#include "cwTime.h"
#ifdef cwOSX
#ifdef OS_OSX
#include <mach/mach.h>
#include <mach/mach_time.h>
@ -40,7 +40,7 @@ void cw::time::get( spec_t& t )
#endif
#ifdef cwLINUX
#ifdef OS_LINUX
void cw::time::get( spec_t& t )
{ clock_gettime(CLOCK_REALTIME,&t); }
#endif

View File

@ -1,8 +1,9 @@
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#ifdef cwLINUX
#ifdef OS_LINUX
#include <arpa/inet.h>
#endif

View File

@ -1,8 +1,9 @@
#include "config.h"
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#ifdef cwLINUX
#ifdef OS_LINUX
#include <arpa/inet.h>
#endif
#ifdef ARDUINO

View File

@ -1,3 +1,4 @@
#include "config.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@ -6,7 +7,7 @@
#include "rpt.h"
#include "fader.h"
#ifdef cwLINUX
#ifdef OS_LINUX
#include <arpa/inet.h>
#endif

View File

@ -1,8 +0,0 @@
{
a:1,
b:2,
c:[1.23,4.56,7.89]
}

439
main.cpp
View File

@ -1,439 +0,0 @@
#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 <iostream>
void print()
{
printf("\n");
}
template<typename T0, typename T1, typename ...ARGS>
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>(args)...);
}
void get(int)
{
printf("\n");
}
template<typename T0, typename T1, typename... ARGS>
void get(int n, T0 t0, T1& t1, ARGS&&... args)
{
std::cout << t0 << ":" " (" << n << "), ";
t1 = n;
get(n+1,std::forward<ARGS>(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<typename T0, typename T1, typename... ARGS>
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>(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>(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 <cfg_fn> sockMgrTest 'udp | tcp' <localPort> { <remote_ip> <remote_port> }\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<dirEntryN; ++i)
cwLogInfo("%s",de[i].name);
cw::mem::release(de);
}
}
void stubTest( cw::object_t* cfg, int argc, const char* argv[] )
{
/*
typedef struct v_str
{
int x = 1;
int y = 2;
void* z = nullptr;
} v_t;
v_t v;
printf("%i %i %p\n",v.x,v.y,v.z);
*/
/*
const char* s = "\x16lmac=00-90-D5-80-F4-DE\x7dummy=0";
printf("len:%li\n",strlen(s));
*/
}
int main( int argc, const char* argv[] )
{
typedef struct func_str
{
const char* label;
void (*func)(cw::object_t* cfg, int argc, const char* argv[] );
} func_t;
// function dispatch list
func_t modeArray[] =
{
{ "variadicTpl", variadicTplTest },
{ "fileSys", fileSysTest },
{ "numbCvt", numbCvtTest },
{ "object", objectTest },
{ "thread", threadTest },
{ "websockSrv", websockSrvTest },
{ "serialSrv", serialPortSrvTest },
{ "midiDevice", midiDeviceTest },
{ "textBuf", textBufTest },
{ "audioBuf", audioBufTest },
{ "audioDev",audioDevTest },
{ "audioDevAlsa", audioDevAlsaTest },
{ "audioDevRpt", audioDevRpt },
//{ "nbmem", nbmemTest },
{ "socket", socketTest },
{ "socketTcp", socketTestTcp },
{ "socketSrvUdp", socketSrvUdpTest },
{ "socketSrvTcp", socketSrvTcpTest },
{ "sockMgrTest", sockMgrTest },
{ "uiTest", uiTest },
{ "socketMdns", socketMdnsTest },
{ "dnssd", dnsSdTest },
{ "eucon", euConTest },
{ "dirEntry", dirEntryTest },
{ "io", ioTest },
{ "stub", stubTest },
{ 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;
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;
}

View File

@ -1,5 +0,0 @@
export LD_LIBRARY_PATH=~/sdk/libwebsockets/build/out/lib
# restart pulseaudio to free ALSA driver
systemctl --user restart pulseaudio

View File

@ -1,4 +0,0 @@
valgrind --track-origins=yes --leak-check=yes --log-file=vg0.txt ./cw_rt $1 $2 $3 $4 $5