AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.3.4
amps.h
Go to the documentation of this file.
1 /* ////////////////////////////////////////////////////////////////////////
2  *
3  * Copyright (c) 2010-2023 60East Technologies Inc., All Rights Reserved.
4  *
5  * This computer software is owned by 60East Technologies Inc. and is
6  * protected by U.S. copyright laws and other laws and by international
7  * treaties. This computer software is furnished by 60East Technologies
8  * Inc. pursuant to a written license agreement and may be used, copied,
9  * transmitted, and stored only in accordance with the terms of such
10  * license agreement and with the inclusion of the above copyright notice.
11  * This computer software or any other copies thereof may not be provided
12  * or otherwise made available to any other person.
13  *
14  * U.S. Government Restricted Rights. This computer software: (a) was
15  * developed at private expense and is in all respects the proprietary
16  * information of 60East Technologies Inc.; (b) was not developed with
17  * government funds; (c) is a trade secret of 60East Technologies Inc.
18  * for all purposes of the Freedom of Information Act; and (d) is a
19  * commercial item and thus, pursuant to Section 12.212 of the Federal
20  * Acquisition Regulations (FAR) and DFAR Supplement Section 227.7202,
21  * Government's use, duplication or disclosure of the computer software
22  * is subject to the restrictions set forth by 60East Technologies Inc..
23  *
24  * ////////////////////////////////////////////////////////////////////// */
25 
26 #ifndef _AMPS_H_
27 #define _AMPS_H_
28 
29 #ifdef _WIN32
30  #include <WinSock2.h>
31 #else
32  #include <netdb.h>
33  #include <netinet/ip.h>
34  #include <netinet/tcp.h>
35  #include <errno.h>
36  #include <pthread.h>
37  #include <sys/socket.h>
38  #include <unistd.h>
39 #endif
40 #include <string.h>
41 #include <time.h>
42 #include <stdio.h>
43 #include "amps_generated.h"
44 
45 //Avoid compiler warnings on win
46 #ifdef INVALID_SOCKET
47  #define AMPS_INVALID_SOCKET INVALID_SOCKET
48 #else
49  #define AMPS_INVALID_SOCKET -1
50 #endif
51 
52 #ifdef _WIN32
53  #ifdef AMPS_SHARED
54  #ifdef AMPS_BUILD
55  #define AMPSDLL __declspec(dllexport)
56  #else
57  #define AMPSDLL __declspec(dllimport)
58  #endif
59  #else
60  #define AMPSDLL
61  #endif
62  #define AMPS_USLEEP(x) Sleep((DWORD)(x)/(DWORD)1000);
63  #define AMPS_YIELD() SwitchToThread()
64  typedef HANDLE AMPS_THREAD_T;
65  typedef SOCKET AMPS_SOCKET;
66  typedef __int32 amps_int32_t;
67  typedef unsigned __int32 amps_uint32_t;
68  typedef __int64 amps_int64_t;
69  typedef unsigned __int64 amps_uint64_t;
70 #else
71  #define AMPSDLL
72  #define AMPS_USLEEP(x) usleep((unsigned int)(x));
73  #define AMPS_YIELD() sched_yield()
74  typedef pthread_t AMPS_THREAD_T;
75  typedef int AMPS_SOCKET;
76  typedef int32_t amps_int32_t;
77  typedef uint32_t amps_uint32_t;
78  typedef int64_t amps_int64_t;
79  typedef uint64_t amps_uint64_t;
80 #endif
81 
82 #if defined(_WIN32) || defined(__SSE_4_2__)
83  #define AMPS_SSE_42 1
84 #endif
85 
184 #ifdef __cplusplus
185 extern "C" {
186 #endif
187 
188 typedef char amps_char;
189 
196 typedef void* amps_handle;
197 
201 typedef enum
202 {
259 } amps_result;
260 
261 typedef amps_result(*amps_handler)(amps_handle, void*);
262 typedef void(*amps_predisconnect_handler)(amps_handle, unsigned, void*);
263 
264 
274 AMPSDLL amps_handle amps_client_create(
275  const amps_char* clientName);
276 
287 AMPSDLL amps_result amps_client_set_name(
288  amps_handle handle,
289  const amps_char* clientName);
290 
298 AMPSDLL amps_result amps_client_connect(
299  amps_handle handle,
300  const amps_char* uri);
301 
306 AMPSDLL void amps_client_disconnect(
307  amps_handle handle);
308 
315 AMPSDLL void amps_client_destroy(
316  amps_handle handle);
317 
326 AMPSDLL size_t amps_client_get_error(
327  amps_handle client,
328  amps_char* errorMessageOut,
329  size_t bufferSize);
330 
338 AMPSDLL amps_result amps_client_send(
339  amps_handle client,
340  amps_handle message);
341 
350 AMPSDLL amps_result amps_client_send_with_version(
351  amps_handle client,
352  amps_handle message,
353  unsigned* version_out);
354 
355 
365  amps_handle client,
366  amps_handler messageHandler,
367  void* userData);
368 
378  amps_handle client,
379  amps_predisconnect_handler predisconnectHandler,
380  void* userData);
381 
391  amps_handle client,
392  amps_handler disconnectHandler,
393  void* userData);
394 
401 AMPSDLL amps_handle amps_client_get_transport(
402  amps_handle client);
403 
411 AMPSDLL amps_result
412 amps_client_attempt_reconnect(amps_handle client, unsigned version);
413 
420 AMPSDLL AMPS_SOCKET
421 amps_client_get_socket(amps_handle client);
422 
432 AMPSDLL amps_handle amps_message_create(amps_handle client);
433 
439 AMPSDLL amps_handle amps_message_copy(amps_handle message);
440 
445 AMPSDLL void amps_message_destroy(amps_handle message);
446 
453 AMPSDLL void amps_message_reset(amps_handle message);
454 
469 AMPSDLL void amps_message_get_field_value(
470  amps_handle message,
471  FieldId field,
472  const amps_char** value_ptr,
473  size_t* length_ptr);
474 
482 AMPSDLL void amps_message_set_field_value(
483  amps_handle message,
484  FieldId field,
485  const amps_char* value,
486  size_t length);
487 
496  amps_handle message,
497  FieldId field,
498  const amps_char* value,
499  size_t length);
500 
509  amps_handle message,
510  FieldId field,
511  const amps_char* value);
512 
513 
520 AMPSDLL void amps_message_set_field_guid(
521  amps_handle message,
522  FieldId field);
523 
530 AMPSDLL void amps_message_set_data(
531  amps_handle message,
532  const amps_char* value,
533  size_t length);
534 
541 AMPSDLL void amps_message_assign_data(
542  amps_handle message,
543  const amps_char* value,
544  size_t length);
545 
551 AMPSDLL void amps_message_set_data_nts(
552  amps_handle message,
553  const amps_char* value);
554 
567 AMPSDLL void amps_message_get_data(
568  amps_handle message,
569  amps_char** value_ptr,
570  size_t* length_ptr);
571 
578 AMPSDLL unsigned long amps_message_get_field_long(
579  amps_handle message,
580  FieldId field);
581 
588 AMPSDLL amps_uint64_t amps_message_get_field_uint64(
589  amps_handle message,
590  FieldId field);
591 
601 AMPSDLL amps_result amps_client_set_read_timeout(
602  amps_handle client,
603  int readTimeout);
604 
605 
615 AMPSDLL amps_result amps_client_set_idle_time(
616  amps_handle client,
617  int idleTime);
618 
627 typedef void(*amps_transport_filter_function)(const unsigned char*, size_t, short, void*);
628 
643  amps_handle client,
645  void* userData);
646 
653 typedef amps_result(*amps_thread_created_callback)(AMPS_THREAD_T, void*);
654 
666 AMPSDLL amps_result amps_client_set_thread_created_callback(
667  amps_handle client,
669  void* userData);
670 
676 AMPSDLL AMPS_SOCKET
677 amps_tcp_get_socket(amps_handle transport);
678 
679 AMPSDLL AMPS_SOCKET
680 amps_tcps_get_socket(amps_handle transport);
681 
687 AMPSDLL void*
688 amps_tcps_get_SSL(amps_handle transport);
689 
690 /*
691  * Returns the current wall-clock time in milliseconds
692  */
693 AMPSDLL amps_uint64_t
694 amps_now(void);
695 
696 
720 AMPSDLL int amps_ssl_init(const char* dllPath_);
721 
729 AMPSDLL int amps_ssl_set_verify(int mode_);
730 
741 AMPSDLL int amps_ssl_load_verify_locations(const char* caFile_, const char* caPath_);
742 
748 AMPSDLL void amps_ssl_free(void);
749 
755 AMPSDLL const char* amps_ssl_get_error(void);
756 
757 AMPSDLL void amps_noOpFn(void*);
758 
759 /*
760  * Internal API for use by the python client.
761  */
762 AMPSDLL void amps_set_waiting_function(void*);
763 AMPSDLL void amps_invoke_waiting_function(void);
764 AMPSDLL void amps_set_remove_route_function(void*);
765 AMPSDLL void amps_invoke_remove_route_function(void*);
766 AMPSDLL void amps_set_copy_route_function(void*);
767 AMPSDLL void* amps_invoke_copy_route_function(void*);
768 
769 #ifdef __cplusplus
770 }
771 #if !defined(_AMPS_BUILD_C_CLIENT) && !defined(_AMPS_SKIP_AMPSPLUSPLUS)
772  #include <ampsplusplus.hpp>
773 #endif
774 #endif
775 
776 #endif
AMPSDLL void amps_ssl_free(void)
Frees OpenSSL context and shared library.
A connection error occurred.
Definition: amps.h:218
AMPSDLL 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.
AMPSDLL amps_handle amps_message_create(amps_handle client)
Functions for creation and manipulation of AMPS messages.
AMPSDLL int amps_ssl_set_verify(int mode_)
Configures OpenSSL to validate the server&#39;s certificate when connecting.
The specified URI is invalid.
Definition: amps.h:246
AMPSDLL amps_result amps_client_set_name(amps_handle handle, const amps_char *clientName)
Sets the name on an amps client object.
AMPSDLL 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...
AMPSDLL amps_result amps_client_connect(amps_handle handle, const amps_char *uri)
Connects to the AMPS server specified in uri.
AMPSDLL void amps_client_disconnect(amps_handle handle)
Disconnects from the AMPS server, if connected.
AMPSDLL AMPS_SOCKET amps_client_get_socket(amps_handle client)
Returns the socket from the underlying transport in client, or NULL if no transport is associated wit...
A Secure Sockets Layer (SSL) error occurred.
Definition: amps.h:258
AMPSDLL 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...
AMPSDLL 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.
AMPSDLL amps_result amps_client_set_idle_time(amps_handle client, int idleTime)
Sets an idle-time (milliseconds).
AMPSDLL 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.
AMPSDLL 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.
Success.
Definition: amps.h:206
The specified topic was invalid.
Definition: amps.h:222
void * amps_handle
Opaque handle type used to refer to objects in the AMPS api.
Definition: amps.h:196
AMPSDLL 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_result
Return values from amps_xxx functions.
Definition: amps.h:201
AMPSDLL amps_handle amps_client_create(const amps_char *clientName)
Functions for creation of an AMPS client.
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:627
AMPSDLL size_t amps_client_get_error(amps_handle client, amps_char *errorMessageOut, size_t bufferSize)
Returns the last error set on this client.
AMPSDLL amps_result amps_client_send_with_version(amps_handle client, amps_handle message, unsigned *version_out)
Sends a message to the AMPS server.
AMPSDLL void amps_client_set_message_handler(amps_handle client, amps_handler messageHandler, void *userData)
Sets the message handler function for this client.
A memory error occurred.
Definition: amps.h:210
AMPSDLL void amps_message_set_data_nts(amps_handle message, const amps_char *value)
Sets the data component of an AMPS message.
AMPSDLL void amps_message_reset(amps_handle message)
Clears all fields and data in a message.
Core type, function, and class declarations for the AMPS C++ client.
The specified filter was invalid.
Definition: amps.h:226
An error with a command occurred.
Definition: amps.h:214
AMPSDLL 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.
AMPSDLL void * amps_tcps_get_SSL(amps_handle transport)
Retrieves the SSL object from the underlying TCPS transport.
AMPSDLL void amps_message_get_data(amps_handle message, amps_char **value_ptr, size_t *length_ptr)
Gets the data component of an AMPS message.
AMPSDLL AMPS_SOCKET amps_tcp_get_socket(amps_handle transport)
TRANSPORT-SPECIFIC APIS.
AMPSDLL void amps_message_destroy(amps_handle message)
Destroys and frees the memory associated with an AMPS message object.
The server could not be found, or it actively refused our connection.
Definition: amps.h:238
AMPSDLL 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.
AMPSDLL void amps_message_set_data(amps_handle message, const amps_char *value, size_t length)
Sets the data component of an AMPS message.
AMPSDLL 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.
AMPSDLL 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...
AMPSDLL 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") ...
The usage of this function is invalid.
Definition: amps.h:254
AMPSDLL 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.
AMPSDLL amps_result amps_client_send(amps_handle client, amps_handle message)
Sends a message to the AMPS server.
AMPSDLL amps_result amps_client_set_thread_created_callback(amps_handle client, amps_thread_created_callback callback, void *userData)
Sets a user-supplied callback function to allow thread attributes to set when a new thread is created...
amps_result(* amps_thread_created_callback)(AMPS_THREAD_T, void *)
Prototype for a user-supplied callback function to allow thread attributes to be set when a new threa...
Definition: amps.h:653
A stream error has occurred.
Definition: amps.h:242
The operation has not succeeded, but ought to be retried.
Definition: amps.h:230
AMPSDLL 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...
AMPSDLL const char * amps_ssl_get_error(void)
Returns the description of the last error from calling amps_ssl_init().
AMPSDLL int amps_ssl_init(const char *dllPath_)
Initializes SSL support in the AMPS Client.
AMPSDLL amps_result amps_client_attempt_reconnect(amps_handle client, unsigned version)
Manually invokes the user-supplied disconnect handler for this client.
AMPSDLL void amps_client_destroy(amps_handle handle)
Disconnects and destroys an AMPS client object.
AMPSDLL int amps_ssl_load_verify_locations(const char *caFile_, const char *caPath_)
Configures OpenSSL to use the specified locations for locating CA certificates.
The client and server are disconnected.
Definition: amps.h:234
The specified transport type is invalid.
Definition: amps.h:250