added Sttp::sendCmdV()

This commit is contained in:
hyung-hwan 2020-08-10 16:55:58 +00:00
parent 301b56b3eb
commit 04ede03b37
3 changed files with 69 additions and 47 deletions

View File

@ -32,6 +32,7 @@
#include <qse/cmn/Mmged.hpp> #include <qse/cmn/Mmged.hpp>
#include <qse/cmn/ErrorGrab.hpp> #include <qse/cmn/ErrorGrab.hpp>
#include <qse/sttp/SttpCmd.hpp> #include <qse/sttp/SttpCmd.hpp>
#include <stdarg.h>
QSE_BEGIN_NAMESPACE(QSE) QSE_BEGIN_NAMESPACE(QSE)
@ -59,6 +60,10 @@ public:
int sendCmdL (const qse_mchar_t* name, qse_size_t nargs, ...); int sendCmdL (const qse_mchar_t* name, qse_size_t nargs, ...);
int sendCmdL (const qse_wchar_t* name, qse_size_t nargs, ...); int sendCmdL (const qse_wchar_t* name, qse_size_t nargs, ...);
int sendCmdV (const qse_mchar_t* name, qse_size_t nargs, va_list ap);
int sendCmdV (const qse_wchar_t* name, qse_size_t nargs, va_list ap);
// TODO: sendCmdLV
// ------------------------------------------------------------------ // ------------------------------------------------------------------
virtual int handle_command (const SttpCmd& cmd) virtual int handle_command (const SttpCmd& cmd)

View File

@ -118,7 +118,7 @@ int qse_mtx_init (qse_mtx_t* mtx, qse_mmgr_t* mmgr)
qse_ensure (pthread_mutex_init (&mtx->hnd, &attr) == 0); qse_ensure (pthread_mutex_init (&mtx->hnd, &attr) == 0);
qse_ensure (pthread_mutexattr_destroy (&attr) == 0); qse_ensure (pthread_mutexattr_destroy (&attr) == 0);
*/ */
if (pthread_mutex_init ((pthread_mutex_t*)&mtx->hnd, QSE_NULL) != 0) return -1; if (pthread_mutex_init((pthread_mutex_t*)&mtx->hnd, QSE_NULL) != 0) return -1;
#endif #endif
return 0; return 0;
@ -229,8 +229,7 @@ int qse_mtx_lock (qse_mtx_t* mtx, const qse_ntime_t* waiting_time)
else else
{ {
#endif #endif
if (pthread_mutex_lock ((pthread_mutex_t*)&mtx->hnd) != 0) return -1; if (pthread_mutex_lock((pthread_mutex_t*)&mtx->hnd) != 0) return -1;
#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) #if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
} }
#endif #endif

View File

@ -679,59 +679,32 @@ int Sttp::write_char (qse_wchar_t c)
return 0; return 0;
} }
int Sttp::sendCmd (const qse_mchar_t* name, qse_size_t nargs = 0, ...)
{
if (name[0] == '\0') return 0; // don't send a null command
if (this->beginWrite(name) <= -1) return -1;
if (nargs > 0) int Sttp::sendCmd (const qse_mchar_t* name, qse_size_t nargs, ...)
{ {
int n;
va_list ap; va_list ap;
va_start (ap, nargs); va_start (ap, nargs);
n = this->sendCmd(name, nargs, ap);
for (qse_size_t i = 1; i <= nargs; i++)
{
qse_mchar_t* p = va_arg(ap, qse_mchar_t*);
if (this->writeStringArg(p) <= -1)
{
va_end (ap); va_end (ap);
return -1;
}
}
va_end (ap);
}
if (this->endWrite() <= -1) return -1; return n;
return 0;
} }
int Sttp::sendCmd (const qse_wchar_t* name, qse_size_t nargs = 0, ...) int Sttp::sendCmd (const qse_wchar_t* name, qse_size_t nargs, ...)
{ {
if (name[0] == '\0') return 0; // don't send a null command int n;
if (this->beginWrite(name) <= -1) return -1;
if (nargs > 0)
{
va_list ap; va_list ap;
va_start (ap, nargs); va_start (ap, nargs);
n = this->sendCmd(name, nargs, ap);
for (qse_size_t i = 1; i <= nargs; i++)
{
qse_wchar_t* p = va_arg(ap, qse_wchar_t*);
if (this->writeStringArg(p) <= -1)
{
va_end (ap); va_end (ap);
return -1;
}
}
va_end (ap);
}
if (this->endWrite() <= -1) return -1; return n;
return 0;
} }
int Sttp::sendCmdL (const qse_mchar_t* name, qse_size_t nargs = 0, ...) int Sttp::sendCmdL (const qse_mchar_t* name, qse_size_t nargs, ...)
{ {
if (name[0] == '\0') return 0; // don't send a null command if (name[0] == '\0') return 0; // don't send a null command
if (this->beginWrite(name) <= -1) return -1; if (this->beginWrite(name) <= -1) return -1;
@ -758,7 +731,7 @@ int Sttp::sendCmdL (const qse_mchar_t* name, qse_size_t nargs = 0, ...)
return 0; return 0;
} }
int Sttp::sendCmdL (const qse_wchar_t* name, qse_size_t nargs = 0, ...) int Sttp::sendCmdL (const qse_wchar_t* name, qse_size_t nargs, ...)
{ {
if (name[0] == '\0') return 0; // don't send a null command if (name[0] == '\0') return 0; // don't send a null command
if (this->beginWrite(name) <= -1) return -1; if (this->beginWrite(name) <= -1) return -1;
@ -785,4 +758,49 @@ int Sttp::sendCmdL (const qse_wchar_t* name, qse_size_t nargs = 0, ...)
return 0; return 0;
} }
int Sttp::sendCmdV (const qse_mchar_t* name, qse_size_t nargs, va_list ap)
{
if (name[0] == '\0') return 0; // don't send a null command
if (this->beginWrite(name) <= -1) return -1;
if (nargs > 0)
{
for (qse_size_t i = 1; i <= nargs; i++)
{
qse_mchar_t* p = va_arg(ap, qse_mchar_t*);
if (this->writeStringArg(p) <= -1)
{
va_end (ap);
return -1;
}
}
}
if (this->endWrite() <= -1) return -1;
return 0;
}
int Sttp::sendCmdV (const qse_wchar_t* name, qse_size_t nargs, va_list ap)
{
if (name[0] == '\0') return 0; // don't send a null command
if (this->beginWrite(name) <= -1) return -1;
if (nargs > 0)
{
for (qse_size_t i = 1; i <= nargs; i++)
{
qse_wchar_t* p = va_arg(ap, qse_wchar_t*);
if (this->writeStringArg(p) <= -1)
{
va_end (ap);
return -1;
}
}
}
if (this->endWrite() <= -1) return -1;
return 0;
}
QSE_END_NAMESPACE(QSE) QSE_END_NAMESPACE(QSE)