AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.0.5
amps.h
Go to the documentation of this file.
1 
25 #ifndef _AMPS_H_
26 #define _AMPS_H_
27 
28 #ifdef _WIN32
29 #include <WinSock2.h>
30 #else
31 #include <netdb.h>
32 #include <netinet/ip.h>
33 #include <errno.h>
34 #include <pthread.h>
35 #include <unistd.h>
36 #endif
37 #include <string.h>
38 #include <time.h>
39 #include <stdio.h>
40 #include "amps_generated.h"
41 
42 #define AMPSDLL
43 
44 #ifdef _WIN32
45 #define AMPS_USLEEP(x) Sleep((DWORD)(x)/(DWORD)1000);
46 #define AMPS_YIELD() SwitchToThread()
47 #else
48 #define AMPS_USLEEP(x) usleep((unsigned int)(x));
49 #define AMPS_YIELD() pthread_yield()
50 #endif
51 
52 #ifdef _WIN32
53 typedef SOCKET AMPS_SOCKET;
54 #else
55 typedef int AMPS_SOCKET;
56 #endif
57 #ifndef _WIN32
58 typedef int32_t amps_int32_t;
59 typedef uint32_t amps_uint32_t;
60 typedef int64_t amps_int64_t;
61 typedef uint64_t amps_uint64_t;
62 #else
63 typedef unsigned __int64 amps_uint64_t;
64 typedef __int64 amps_int64_t;
65 typedef unsigned __int32 amps_uint32_t;
66 typedef __int32 amps_int32_t;
67 #endif
68 
69 #if defined(_WIN32) || defined(__SSE_4_2__)
70 #define AMPS_SSE_42 1
71 #endif
72 
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98  typedef char amps_char;
99 
106  typedef void* amps_handle;
107 
111  typedef enum
112  {
169  } amps_result;
170 
171  typedef amps_result(*amps_handler)(amps_handle, void*);
172  typedef void(*amps_predisconnect_handler)(amps_handle, unsigned, void*);
173 
174 
184  amps_handle AMPSDLL amps_client_create(
185  const amps_char* clientName);
186 
197  amps_result AMPSDLL amps_client_set_name(
198  amps_handle handle,
199  const amps_char* clientName);
200 
208  amps_result AMPSDLL amps_client_connect(
209  amps_handle handle,
210  const amps_char* uri);
211 
217  amps_handle handle);
218 
226  amps_handle handle);
227 
236  size_t amps_client_get_error(
237  amps_handle client,
238  amps_char* errorMessageOut,
239  size_t bufferSize);
240 
248  amps_result amps_client_send(
249  amps_handle client,
250  amps_handle message);
251 
260  amps_result amps_client_send_with_version(
261  amps_handle client,
262  amps_handle message,
263  unsigned* version_out);
264 
265 
275  amps_handle client,
276  amps_handler messageHandler,
277  void* userData);
278 
288  amps_handle client,
289  amps_predisconnect_handler predisconnectHandler,
290  void* userData);
291 
301  amps_handle client,
302  amps_handler disconnectHandler,
303  void* userData);
304 
311  amps_handle amps_client_get_transport(
312  amps_handle client);
313 
321  amps_result
322  amps_client_attempt_reconnect(amps_handle client, unsigned version);
323 
333  amps_handle amps_message_create(amps_handle client);
334 
340  amps_handle amps_message_copy(amps_handle message);
341 
346  void amps_message_destroy(amps_handle message);
347 
354  void amps_message_reset(amps_handle message);
355 
371  amps_handle message,
372  FieldId field,
373  const amps_char** value_ptr,
374  size_t* length_ptr);
375 
384  amps_handle message,
385  FieldId field,
386  const amps_char* value,
387  size_t length);
388 
397  amps_handle message,
398  FieldId field,
399  const amps_char* value,
400  size_t length);
401 
410  amps_handle message,
411  FieldId field,
412  const amps_char* value);
413 
414 
422  amps_handle message,
423  FieldId field);
424 
432  amps_handle message,
433  const amps_char* value,
434  size_t length);
435 
443  amps_handle message,
444  const amps_char* value,
445  size_t length);
446 
453  amps_handle message,
454  const amps_char* value);
455 
469  amps_handle message,
470  amps_char** value_ptr,
471  size_t* length_ptr);
472 
479  unsigned long amps_message_get_field_long(
480  amps_handle message,
481  FieldId field);
482 
489  amps_uint64_t amps_message_get_field_uint64(
490  amps_handle message,
491  FieldId field);
492 
502  amps_result amps_client_set_read_timeout(
503  amps_handle client,
504  int readTimeout);
505 
506 
516  amps_result amps_client_set_idle_time(
517  amps_handle client,
518  int idleTime);
519 
528 typedef void(*amps_transport_filter_function)(const unsigned char*,size_t,short,void*);
529 
544  amps_handle client,
546  void* userData);
547 
553  AMPS_SOCKET
554  amps_tcp_get_socket(amps_handle transport);
555 
561  void*
562  amps_tcps_get_SSL(amps_handle transport);
563 
564 /*
565  * Returns the current wall-clock time in milliseconds
566  */
567  amps_uint64_t
568  amps_now(void);
569 
570 
594 int amps_ssl_init(const char* dllPath_);
595 
603 int amps_ssl_set_verify(int mode_);
604 
615 int amps_ssl_load_verify_locations(const char* caFile_, const char* caPath_);
616 
622 void amps_ssl_free(void);
623 
629 const char* amps_ssl_get_error(void);
630 
631 
632 /*
633  * Internal API for use by the python client.
634  */
635 void amps_set_waiting_function(void*);
636 void amps_invoke_waiting_function(void);
637 
638 #ifdef __cplusplus
639 }
640 #ifndef _AMPS_BUILD_C_CLIENT
641 #include <ampsplusplus.hpp>
642 #endif
643 #endif
644 
645 #endif
A connection error occured.
Definition: amps.h:128
int amps_ssl_load_verify_locations(const char *caFile_, const char *caPath_)
Configures OpenSSL to use the specified locations for locating CA certificates.
The specified URI is invalid.
Definition: amps.h:156
void amps_message_reset(amps_handle message)
Clears all fields and data in a message.
void amps_message_assign_data(amps_handle message, const amps_char *value, size_t length)
Assigns the data component of an AMPS message, without copying the value.
amps_handle amps_message_copy(amps_handle message)
Creates and returns a handle to a new AMPS message object that is a deep copy of the message passed i...
A Secure Sockets Layer (SSL) error occured.
Definition: amps.h:168
void AMPSDLL amps_client_disconnect(amps_handle handle)
Disconnects from the AMPS server, if connected.
amps_result amps_client_set_read_timeout(amps_handle client, int readTimeout)
Sets a read timeout (seconds), in which if no message is received, the connection is presumed dead...
#define AMPSDLL
////////////////////////////////////////////////////////////////////////
Definition: amps.h:42
size_t amps_client_get_error(amps_handle client, amps_char *errorMessageOut, size_t bufferSize)
Returns the last error set on this client.
void amps_message_set_field_value_nts(amps_handle message, FieldId field, const amps_char *value)
Sets the value of a header field in an AMPS message from a null-terminated string.
Success.
Definition: amps.h:116
amps_handle AMPSDLL amps_client_create(const amps_char *clientName)
Functions for creation of an AMPS client.
The specified topic was invalid.
Definition: amps.h:132
void * amps_handle
Opaque handle type used to refer to objects in the AMPS api.
Definition: amps.h:106
amps_result
Return values from amps_xxx functions.
Definition: amps.h:111
void amps_ssl_free(void)
Frees OpenSSL context and shared library.
void(* amps_transport_filter_function)(const unsigned char *, size_t, short, void *)
Prototype for a user-supplied callback function for filtering data before it is sent and after it is ...
Definition: amps.h:528
amps_result AMPSDLL amps_client_connect(amps_handle handle, const amps_char *uri)
Connects to the AMPS server specified in uri.
int amps_ssl_init(const char *dllPath_)
Initializes SSL support in the AMPS Client.
A memory error occured.
Definition: amps.h:120
amps_result amps_client_attempt_reconnect(amps_handle client, unsigned version)
Manually invokes the user-supplied disconnect handler for this client.
Core type, function, and class declarations for the AMPS C++ client.
The specified filter was invalid.
Definition: amps.h:136
void AMPSDLL amps_client_destroy(amps_handle handle)
Disconnects and destroys an AMPS client object.
void * amps_tcps_get_SSL(amps_handle transport)
Retrieves the SSL object from the underlying TCPS transport.
An error with a command occured.
Definition: amps.h:124
void amps_message_set_field_guid(amps_handle message, FieldId field)
Sets the value of a header field in an AMPS message to a new, globally unique identifier("GUID") ...
amps_handle amps_client_get_transport(amps_handle client)
Returns a handle to the transport set in client, or NULL if no transport is associated with this tran...
amps_result amps_client_send_with_version(amps_handle client, amps_handle message, unsigned *version_out)
Sends a message to the AMPS server.
The server could not be found, or it actively refused our connection.
Definition: amps.h:148
void amps_client_set_message_handler(amps_handle client, amps_handler messageHandler, void *userData)
Sets the message handler function for this client.
void amps_message_get_data(amps_handle message, amps_char **value_ptr, size_t *length_ptr)
Gets the data component of an AMPS message.
amps_handle amps_message_create(amps_handle client)
Functions for creation and manipulation of AMPS messages.
void amps_message_assign_field_value(amps_handle message, FieldId field, const amps_char *value, size_t length)
Assigns the value of a header field in an AMPS message, without copying the value.
void amps_message_set_field_value(amps_handle message, FieldId field, const amps_char *value, size_t length)
Sets the value of a header field in an AMPS message.
AMPS_SOCKET amps_tcp_get_socket(amps_handle transport)
TRANSPORT-SPECIFIC APIS.
void amps_message_set_data_nts(amps_handle message, const amps_char *value)
Sets the data component of an AMPS message.
unsigned long amps_message_get_field_long(amps_handle message, FieldId field)
Gets the long integer value of a header field in an AMPS message.
int amps_ssl_set_verify(int mode_)
Configures OpenSSL to validate the server&#39;s certificate when connecting.
void amps_message_get_field_value(amps_handle message, FieldId field, const amps_char **value_ptr, size_t *length_ptr)
Retrieves the value of a header field in an AMPS message.
amps_result amps_client_set_idle_time(amps_handle client, int idleTime)
Sets an idle-time (milliseconds).
The usage of this function is invalid.
Definition: amps.h:164
amps_result AMPSDLL amps_client_set_name(amps_handle handle, const amps_char *clientName)
Sets the name on an amps client object.
amps_result amps_client_set_transport_filter_function(amps_handle client, amps_transport_filter_function filter, void *userData)
Sets a user-supplied callback function for filtering data before it is sent and after it is received...
void amps_message_set_data(amps_handle message, const amps_char *value, size_t length)
Sets the data component of an AMPS message.
void amps_client_set_disconnect_handler(amps_handle client, amps_handler disconnectHandler, void *userData)
Sets the disconnect handler function to be called when a disconnect occurs.
A stream error has occured.
Definition: amps.h:152
The operation has not succeeded, but ought to be retried.
Definition: amps.h:140
void amps_client_set_predisconnect_handler(amps_handle client, amps_predisconnect_handler predisconnectHandler, void *userData)
Sets the predisconnect handler function to be called when a disconnect occurs.
The client and server are disconnected.
Definition: amps.h:144
const char * amps_ssl_get_error(void)
Returns the description of the last error from calling amps_ssl_init().
amps_uint64_t amps_message_get_field_uint64(amps_handle message, FieldId field)
Gets the unsigned 64-bit int value of a header field in an AMPS message.
amps_result amps_client_send(amps_handle client, amps_handle message)
Sends a message to the AMPS server.
The specified transport type is invalid.
Definition: amps.h:160
void amps_message_destroy(amps_handle message)
Destroys and frees the memory associated with an AMPS message object.