AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.3.3
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 <errno.h>
35 #include <pthread.h>
36 #include <unistd.h>
37 #endif
38 #include <string.h>
39 #include <time.h>
40 #include <stdio.h>
41 #include "amps_generated.h"
42 
43 #ifdef _WIN32
44 #ifdef AMPS_SHARED
45 #ifdef AMPS_BUILD
46 #define AMPSDLL __declspec(dllexport)
47 #else
48 #define AMPSDLL __declspec(dllimport)
49 #endif
50 #else
51 #define AMPSDLL
52 #endif
53 #define AMPS_USLEEP(x) Sleep((DWORD)(x)/(DWORD)1000);
54 #define AMPS_YIELD() SwitchToThread()
55 typedef HANDLE AMPS_THREAD_T;
56 typedef SOCKET AMPS_SOCKET;
57 typedef __int32 amps_int32_t;
58 typedef unsigned __int32 amps_uint32_t;
59 typedef __int64 amps_int64_t;
60 typedef unsigned __int64 amps_uint64_t;
61 #else
62 #define AMPSDLL
63 #define AMPS_USLEEP(x) usleep((unsigned int)(x));
64 #define AMPS_YIELD() sched_yield()
65 typedef pthread_t AMPS_THREAD_T;
66 typedef int AMPS_SOCKET;
67 typedef int32_t amps_int32_t;
68 typedef uint32_t amps_uint32_t;
69 typedef int64_t amps_int64_t;
70 typedef uint64_t amps_uint64_t;
71 #endif
72 
73 #if defined(_WIN32) || defined(__SSE_4_2__)
74 #define AMPS_SSE_42 1
75 #endif
76 
175 #ifdef __cplusplus
176 extern "C" {
177 #endif
178 
179  typedef char amps_char;
180 
187  typedef void* amps_handle;
188 
192  typedef enum
193  {
250  } amps_result;
251 
252  typedef amps_result(*amps_handler)(amps_handle, void*);
253  typedef void(*amps_predisconnect_handler)(amps_handle, unsigned, void*);
254 
255 
265  AMPSDLL amps_handle amps_client_create(
266  const amps_char* clientName);
267 
278  AMPSDLL amps_result amps_client_set_name(
279  amps_handle handle,
280  const amps_char* clientName);
281 
289  AMPSDLL amps_result amps_client_connect(
290  amps_handle handle,
291  const amps_char* uri);
292 
297  AMPSDLL void amps_client_disconnect(
298  amps_handle handle);
299 
306  AMPSDLL void amps_client_destroy(
307  amps_handle handle);
308 
317  AMPSDLL size_t amps_client_get_error(
318  amps_handle client,
319  amps_char* errorMessageOut,
320  size_t bufferSize);
321 
329  AMPSDLL amps_result amps_client_send(
330  amps_handle client,
331  amps_handle message);
332 
341  AMPSDLL amps_result amps_client_send_with_version(
342  amps_handle client,
343  amps_handle message,
344  unsigned* version_out);
345 
346 
355  AMPSDLL void amps_client_set_message_handler(
356  amps_handle client,
357  amps_handler messageHandler,
358  void* userData);
359 
369  amps_handle client,
370  amps_predisconnect_handler predisconnectHandler,
371  void* userData);
372 
382  amps_handle client,
383  amps_handler disconnectHandler,
384  void* userData);
385 
392  AMPSDLL amps_handle amps_client_get_transport(
393  amps_handle client);
394 
402  AMPSDLL amps_result
403  amps_client_attempt_reconnect(amps_handle client, unsigned version);
404 
414  AMPSDLL amps_handle amps_message_create(amps_handle client);
415 
421  AMPSDLL amps_handle amps_message_copy(amps_handle message);
422 
427  AMPSDLL void amps_message_destroy(amps_handle message);
428 
435  AMPSDLL void amps_message_reset(amps_handle message);
436 
451  AMPSDLL void amps_message_get_field_value(
452  amps_handle message,
453  FieldId field,
454  const amps_char** value_ptr,
455  size_t* length_ptr);
456 
464  AMPSDLL void amps_message_set_field_value(
465  amps_handle message,
466  FieldId field,
467  const amps_char* value,
468  size_t length);
469 
477  AMPSDLL void amps_message_assign_field_value(
478  amps_handle message,
479  FieldId field,
480  const amps_char* value,
481  size_t length);
482 
491  amps_handle message,
492  FieldId field,
493  const amps_char* value);
494 
495 
502  AMPSDLL void amps_message_set_field_guid(
503  amps_handle message,
504  FieldId field);
505 
512  AMPSDLL void amps_message_set_data(
513  amps_handle message,
514  const amps_char* value,
515  size_t length);
516 
523  AMPSDLL void amps_message_assign_data(
524  amps_handle message,
525  const amps_char* value,
526  size_t length);
527 
533  AMPSDLL void amps_message_set_data_nts(
534  amps_handle message,
535  const amps_char* value);
536 
549  AMPSDLL void amps_message_get_data(
550  amps_handle message,
551  amps_char** value_ptr,
552  size_t* length_ptr);
553 
560  AMPSDLL unsigned long amps_message_get_field_long(
561  amps_handle message,
562  FieldId field);
563 
570  AMPSDLL amps_uint64_t amps_message_get_field_uint64(
571  amps_handle message,
572  FieldId field);
573 
583  AMPSDLL amps_result amps_client_set_read_timeout(
584  amps_handle client,
585  int readTimeout);
586 
587 
597  AMPSDLL amps_result amps_client_set_idle_time(
598  amps_handle client,
599  int idleTime);
600 
609 typedef void(*amps_transport_filter_function)(const unsigned char*,size_t,short,void*);
610 
624  AMPSDLL amps_result amps_client_set_transport_filter_function(
625  amps_handle client,
627  void* userData);
628 
635 typedef amps_result(*amps_thread_created_callback)(AMPS_THREAD_T,void*);
636 
648  AMPSDLL amps_result amps_client_set_thread_created_callback(
649  amps_handle client,
651  void* userData);
652 
658  AMPSDLL AMPS_SOCKET
659  amps_tcp_get_socket(amps_handle transport);
660 
661  AMPSDLL AMPS_SOCKET
662  amps_tcps_get_socket(amps_handle transport);
663 
669  AMPSDLL void*
670  amps_tcps_get_SSL(amps_handle transport);
671 
672 /*
673  * Returns the current wall-clock time in milliseconds
674  */
675  AMPSDLL amps_uint64_t
676  amps_now(void);
677 
678 
702 AMPSDLL int amps_ssl_init(const char* dllPath_);
703 
711 AMPSDLL int amps_ssl_set_verify(int mode_);
712 
723 AMPSDLL int amps_ssl_load_verify_locations(const char* caFile_, const char* caPath_);
724 
730 AMPSDLL void amps_ssl_free(void);
731 
737 AMPSDLL const char* amps_ssl_get_error(void);
738 
739 AMPSDLL void amps_noOpFn(void*);
740 
741 /*
742  * Internal API for use by the python client.
743  */
744 AMPSDLL void amps_set_waiting_function(void*);
745 AMPSDLL void amps_invoke_waiting_function(void);
746 AMPSDLL void amps_set_remove_route_function(void*);
747 AMPSDLL void amps_invoke_remove_route_function(void*);
748 AMPSDLL void amps_set_copy_route_function(void*);
749 AMPSDLL void* amps_invoke_copy_route_function(void*);
750 
751 #ifdef __cplusplus
752 }
753 #if !defined(_AMPS_BUILD_C_CLIENT) && !defined(_AMPS_SKIP_AMPSPLUSPLUS)
754 #include <ampsplusplus.hpp>
755 #endif
756 #endif
757 
758 #endif
AMPSDLL void amps_ssl_free(void)
Frees OpenSSL context and shared library.
A connection error occured.
Definition: amps.h:209
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:237
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.
A Secure Sockets Layer (SSL) error occured.
Definition: amps.h:249
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:197
The specified topic was invalid.
Definition: amps.h:213
void * amps_handle
Opaque handle type used to refer to objects in the AMPS api.
Definition: amps.h:187
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:192
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:609
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 occured.
Definition: amps.h:201
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:217
An error with a command occured.
Definition: amps.h:205
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:229
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:245
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:635
A stream error has occured.
Definition: amps.h:233
The operation has not succeeded, but ought to be retried.
Definition: amps.h:221
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:225
The specified transport type is invalid.
Definition: amps.h:241