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