Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
TIMIQLib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Control System
Libraries
TIMIQLib
Commits
74e2a290
Commit
74e2a290
authored
8 years ago
by
Jacques Gouno
Browse files
Options
Downloads
Patches
Plain Diff
TANGODEVIC-1647: updating source code
parent
5b5b8132
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/TIMIQCurl.cpp
+65
-56
65 additions, 56 deletions
src/TIMIQCurl.cpp
src/TIMIQCurl.h
+8
-9
8 additions, 9 deletions
src/TIMIQCurl.h
src/TIMIQLib.cpp
+0
-3
0 additions, 3 deletions
src/TIMIQLib.cpp
src/TIMIQTypesAndConsts.h
+2
-2
2 additions, 2 deletions
src/TIMIQTypesAndConsts.h
with
75 additions
and
70 deletions
src/TIMIQCurl.cpp
+
65
−
56
View file @
74e2a290
...
...
@@ -17,16 +17,38 @@
namespace
TIMIQLib_ns
{
// ============================================================================
// static variables & functions
// ============================================================================
//- timiq internal web buffer
static
std
::
string
m_timiq_internal_buff
;
// ----------------------------------------------------------------------------
// write callback functions
// @param buffer data , size*nmemb buffer size, void userp
// @return size*nmemb buffer size
// ----------------------------------------------------------------------------
static
size_t
write_callback
(
char
*
buffer
,
size_t
size
,
size_t
nmemb
,
void
*
)
{
// std::cout<<"static size_t write_callback <"<<size<<"> nmemb<"<<nmemb<<">"<<std::endl;
for
(
size_t
idx
=
0
;
idx
<
size
*
nmemb
;
idx
++
)
m_timiq_internal_buff
.
push_back
(
buffer
[
idx
]);
return
size
*
nmemb
;
}
// ============================================================================
// TIMIQCurl::TIMIQCurl
// ============================================================================
TIMIQCurl
::
TIMIQCurl
(
const
std
::
string
&
ip_address
,
const
std
::
string
&
num_port
)
{
//std::cout << "TIMIQCurl constructor" << std::endl;
m_base_addr
=
kHTTP_WEB_PROTOCOL
+
ip_address
+
":"
+
num_port
+
"/"
;
m_base_addr
=
kHTTP_WEB_PROTOCOL
+
ip_address
+
":"
+
num_port
;
m_error_string
=
""
;
m_timiq_internal_buff
.
clear
();
// use the static timiq internal buffer
// m_timiq_internal_buff.clear();
m_hw_curl
=
NULL
;
}
...
...
@@ -267,18 +289,6 @@ E_timiq_errno_t TIMIQCurl::read_state_and_status(std::string& status, E_timiq_c
return
err_num
;
}
// ============================================================================
// TIMIQCurl::writeTimIQCallback
// ============================================================================
size_t
TIMIQCurl
::
writeTimIQCallback
(
char
*
buffer
,
size_t
size
,
size_t
nmemb
,
void
*
)
{
//- fill the buffer with the data collected from TIMQ webserver
for
(
size_t
idx
=
0
;
idx
<
size
*
nmemb
;
idx
++
)
m_timiq_internal_buff
.
push_back
(
buffer
[
idx
]);
return
size
*
nmemb
;
}
// ============================================================================
// TIMIQCurl::connect_i
// ============================================================================
...
...
@@ -323,9 +333,6 @@ bool TIMIQCurl::write_i(std::string& url, std::string& strData)
m_error_string
=
""
;
//- clean the timiq buffer data before perform
m_timiq_internal_buff
.
clear
();
#if !defined (_SIMULATION_)
//- no connection is possible
if
(
this
->
connect_i
()
!=
timiq_NO_ERROR
)
...
...
@@ -333,15 +340,7 @@ bool TIMIQCurl::write_i(std::string& url, std::string& strData)
try
{
//send to webserver
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_URL
,
url
.
c_str
());
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_WRITEFUNCTION
,
&
TIMIQCurl
::
writeTimIQCallback
);
//- perform the query
result
=
curl_easy_perform
(
m_hw_curl
);
//- clean up
curl_easy_cleanup
(
m_hw_curl
);
result
=
send_to_webserver_i
(
url
);
}
catch
(...)
{
...
...
@@ -395,27 +394,14 @@ bool TIMIQCurl::read_float_i(const std::string& url, const std::string& strData,
m_error_string
=
""
;
//- clean the timiq buffer data before perform
m_timiq_internal_buff
.
clear
();
#if !defined (_SIMULATION_)
//- no connection is possible
if
(
this
->
connect_i
()
!=
timiq_NO_ERROR
)
{
return
false
;
}
try
{
//send to webserver
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_URL
,
url
.
c_str
());
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_WRITEFUNCTION
,
&
TIMIQCurl
::
writeTimIQCallback
);
//- perform the query
result
=
curl_easy_perform
(
m_hw_curl
);
//- clean up
curl_easy_cleanup
(
m_hw_curl
);
result
=
send_to_webserver_i
(
url
);
}
catch
(...)
{
...
...
@@ -428,7 +414,10 @@ bool TIMIQCurl::read_float_i(const std::string& url, const std::string& strData,
if
(
result
!=
CURLE_OK
)
{
//- HTTP error
m_error_string
=
m_timiq_internal_buff
;
char
buff
[
kMAX_DATA_SIZE
];
memset
(
buff
,
0
,
sizeof
(
buff
));
sprintf
(
buff
,
"TIMIQCurl::read_float_i - CURL code error <%d>"
,
result
);
m_error_string
=
buff
;
return
false
;
}
else
...
...
@@ -491,9 +480,6 @@ bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& sta
m_error_string
=
""
;
//- clean the timiq buffer data before perform
m_timiq_internal_buff
.
clear
();
#if !defined (_SIMULATION_)
//- no connection is possible
if
(
this
->
connect_i
()
!=
timiq_NO_ERROR
)
...
...
@@ -501,15 +487,7 @@ bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& sta
try
{
//- send to webserver
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_URL
,
url
.
c_str
());
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_WRITEFUNCTION
,
&
TIMIQCurl
::
writeTimIQCallback
);
//- perform the query
result
=
curl_easy_perform
(
m_hw_curl
);
//- clean up
curl_easy_cleanup
(
m_hw_curl
);
result
=
send_to_webserver_i
(
url
);
}
catch
(...)
{
...
...
@@ -521,8 +499,11 @@ bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& sta
//----------------------------
if
(
result
!=
CURLE_OK
)
{
//- HTTP error
m_error_string
=
m_timiq_internal_buff
;
//- HTTP error
char
buff
[
kMAX_DATA_SIZE
];
memset
(
buff
,
0
,
sizeof
(
buff
));
sprintf
(
buff
,
"TIMIQCurl::read_state_and_status_i - CURL code error <%d>"
,
result
);
m_error_string
=
buff
;
return
false
;
}
else
...
...
@@ -583,4 +564,32 @@ bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& sta
return
false
;
}
// ============================================================================
// TIMIQCurl::send_to_webserver_i
// ============================================================================
CURLcode
TIMIQCurl
::
send_to_webserver_i
(
const
std
::
string
&
url
)
{
CURLcode
result
;
//- clean the timiq buffer data before perform
m_timiq_internal_buff
.
clear
();
/* ask libcurl to set options */
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_URL
,
url
.
c_str
());
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_PROXY
,
""
);
curl_easy_setopt
(
m_hw_curl
,
CURLOPT_WRITEFUNCTION
,
&
write_callback
);
/* ask libcurl to show us the verbose output */
// curl_easy_setopt(m_hw_curl, CURLOPT_VERBOSE, 1L);
//- perform the query
result
=
curl_easy_perform
(
m_hw_curl
);
//- clean up
curl_easy_cleanup
(
m_hw_curl
);
return
result
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/TIMIQCurl.h
+
8
−
9
View file @
74e2a290
...
...
@@ -87,7 +87,7 @@ namespace TIMIQLib_ns
private
:
//- internal members
//-------------------
//- IP address
+":"+ port number
//- IP address
std
::
string
m_base_addr
;
//- CURL easy handle
...
...
@@ -96,9 +96,6 @@ namespace TIMIQLib_ns
// message error
std
::
string
m_error_string
;
//- timiq internal web buffer
std
::
string
m_timiq_internal_buff
;
//- internal functions
//--------------------
...
...
@@ -113,11 +110,7 @@ namespace TIMIQLib_ns
// connects to an easy handle using curl
// @return 0: no error, others: an internal error occurred
E_timiq_errno_t
connect_i
();
// write callback functions
// @param buffer data , size*nb_member buffer size, void pointer
// @return size*nb_member buffer size
size_t
writeTimIQCallback
(
char
*
buffer
,
size_t
size
,
size_t
nb_member
,
void
*
);
// writes on timiq WebServer
// @param url of the page, strData data to send
...
...
@@ -133,6 +126,12 @@ namespace TIMIQLib_ns
// @param url of the page, string state
// @return true if success, false otherwise
bool
read_state_and_status_i
(
const
std
::
string
&
url
,
std
::
string
&
state
,
E_timiq_code_t
&
codeRet
);
// send data to webserver
// @param string
// @return CURLcode
CURLcode
send_to_webserver_i
(
const
std
::
string
&
url
);
};
}
#endif //- _TIMIQ_CURL_H_
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/TIMIQLib.cpp
+
0
−
3
View file @
74e2a290
...
...
@@ -30,7 +30,6 @@ if (!m_timiq_hw) \
// ============================================================================
TIMIQLib
::
TIMIQLib
()
{
//std::cout << "TIMIQLib constructor" << std::endl;
m_timiq_hw
=
NULL
;
m_ipAddress
=
""
;
m_numPort
=
""
;
...
...
@@ -40,8 +39,6 @@ TIMIQLib::TIMIQLib ()
// ============================================================================
TIMIQLib
::~
TIMIQLib
()
{
//std::cout << "TIMIQLib destructor" << std::endl;
if
(
m_timiq_hw
)
{
delete
m_timiq_hw
;
...
...
This diff is collapsed.
Click to expand it.
src/TIMIQTypesAndConsts.h
+
2
−
2
View file @
74e2a290
...
...
@@ -60,7 +60,7 @@ const std::string kTIMIQ_MIXER_SIN_OUTPUT_KEY= "mixerSinOutput";
//- Web page: state
//-------------------------
const
std
::
string
kTIMIQ_STATE_PAGE
=
"/get_
feedback
.wsgi"
;
const
std
::
string
kTIMIQ_STATE_PAGE
=
"/get_
state
.wsgi"
;
//- message key
const
std
::
string
kTIMIQ_MESSAGE_KEY
=
"message="
;
...
...
@@ -70,7 +70,7 @@ const std::string kTIMIQ_STATE_KEY= "state=";
const
std
::
string
kTIMIQ_CODE_KEY
=
"code="
;
//- buffer key size
const
size_t
kMAX_DATA_SIZE
=
3
5
;
const
size_t
kMAX_DATA_SIZE
=
5
0
;
// ============================================================================
// TYPES
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment