Commit c0f90425 authored by Olivier Bertrand's avatar Olivier Bertrand

Some small changes.

===================
- Modify tracing to use htrc to be compatible with old versions
  when this code is used to make an EOM module.
  modified:   storage/connect/restget.cpp
  modified:   storage/connect/tabrest.cpp

- Path apparently not needed for the cpprest lib on Linux
  modified:   storage/connect/CMakeLists.txt
parent 4d93c7f3
......@@ -321,8 +321,8 @@ IF(CONNECT_WITH_REST)
MESSAGE(STATUS "=====> cpprestsdk found")
IF(UNIX)
# INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR})
# Edit next line to set the path to libcpprest.so
SET(REST_LIBRARY -L/usr/lib64 -lcpprest)
# If needed edit next line to set the path to libcpprest.so
SET(REST_LIBRARY -lcpprest)
MESSAGE (STATUS ${REST_LIBRARY})
ENDIF(UNIX)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h)
......
......@@ -19,14 +19,13 @@ using namespace concurrency::streams; // Asynchronous streams
#include "global.h"
static uint xt = 0; // Used by lamda expressions
/***********************************************************************/
/* Make a local copy of the requested file. */
/***********************************************************************/
int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
{
int rc = 0;
bool xt = trace(515);
auto fileStream = std::make_shared<ostream>();
if (!http || !fn) {
......@@ -34,15 +33,15 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
return 2;
} // endif
xt = GetTraceValue();
xtrc(515, "restGetFile: fn=%s\n", fn);
if (xt)
htrc("restGetFile: fn=%s\n", fn);
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(to_string_t(fn))
.then([=](ostream outFile) {
*fileStream= outFile;
if (xt & 515)
if (xt)
htrc("Outfile isopen=%d\n", outFile.is_open());
// Create http_client to send the request.
......@@ -58,7 +57,7 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
// Handle response headers arriving.
.then([=](http_response response) {
if (xt & 515)
if (xt)
htrc("Received response status code:%u\n",
response.status_code());
......@@ -68,7 +67,7 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
// Close the file stream.
.then([=](size_t n) {
if (xt & 515)
if (xt)
htrc("Return size=%u\n", n);
return fileStream->close();
......@@ -77,13 +76,19 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
// Wait for all the outstanding I/O to complete and handle any exceptions
try {
requestTask.wait();
xtrc(515, "In Wait\n");
if (xt)
htrc("In Wait\n");
} catch (const std::exception &e) {
xtrc(515, "Error exception: %s\n", e.what());
if (xt)
htrc("Error exception: %s\n", e.what());
sprintf(g->Message, "Error exception: %s", e.what());
rc= 1;
} // end try/catch
xtrc(515, "restget done: rc=%d\n", rc);
if (xt)
htrc("restget done: rc=%d\n", rc);
return rc;
} // end of restGetFile
......@@ -135,7 +135,7 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
ftype = GetStringCatInfo(g, "Ftype", "JSON");
#endif // !MARIADB
if (trace(1))
if (trace(515))
htrc("ftype = %s am = %s\n", ftype, SVP(am));
n = (!stricmp(ftype, "JSON")) ? 1
......@@ -159,7 +159,7 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
// Retrieve the file from the web and copy it locally
rc = restGetFile(g, Http, Uri, filename);
if (trace(1))
if (trace(515))
htrc("Return from restGetFile: rc=%d\n", rc);
if (rc)
......@@ -175,7 +175,7 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST"))
Tdp = NULL; // Error occured
if (trace(1))
if (trace(515))
htrc("Tdp defined\n", rc);
// Return true in case of error
......@@ -187,7 +187,8 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/
PTDB RESTDEF::GetTable(PGLOBAL g, MODE m)
{
xtrc(515, "REST GetTable mode=%d\n", m);
if (trace(515))
htrc("REST GetTable mode=%d\n", m);
if (m != MODE_READ && m != MODE_READX) {
strcpy(g->Message, "REST tables are currently read only");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment