diff options
Diffstat (limited to 'src/include/gnunet_pq_lib.h')
-rw-r--r-- | src/include/gnunet_pq_lib.h | 125 |
1 files changed, 11 insertions, 114 deletions
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h index 1f2915165..fe3fabbea 100644 --- a/src/include/gnunet_pq_lib.h +++ b/src/include/gnunet_pq_lib.h | |||
@@ -853,113 +853,8 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db); | |||
853 | 853 | ||
854 | 854 | ||
855 | /** | 855 | /** |
856 | * Function called whenever the socket needed for | ||
857 | * notifications from postgres changes. | ||
858 | * | ||
859 | * @param cls closure | ||
860 | * @param fd socket to listen on, -1 for none | ||
861 | */ | ||
862 | typedef void | ||
863 | (*GNUNET_PQ_SocketCallback)(void *cls, | ||
864 | int fd); | ||
865 | |||
866 | |||
867 | /** | ||
868 | * Obtain the file descriptor to poll on for notifications. | ||
869 | * Useful if the GNUnet scheduler is NOT to be used for | ||
870 | * such notifications. | ||
871 | * | ||
872 | * @param db database handle | ||
873 | * @param sc function to call with the socket | ||
874 | * @param sc_cls closure for @a sc | ||
875 | */ | ||
876 | void | ||
877 | GNUNET_PQ_event_set_socket_callback (struct GNUNET_PQ_Context *db, | ||
878 | GNUNET_PQ_SocketCallback sc, | ||
879 | void *sc_cls); | ||
880 | |||
881 | |||
882 | /** | ||
883 | * Poll for database events now. Used if the event FD | ||
884 | * is ready and the application wants to trigger applicable | ||
885 | * events. | ||
886 | * Useful if the GNUnet scheduler is NOT to be used for | ||
887 | * such notifications. | ||
888 | * | ||
889 | * @param db database handle | ||
890 | */ | ||
891 | void | ||
892 | GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db); | ||
893 | |||
894 | |||
895 | /** | ||
896 | * Run poll event loop using the GNUnet scheduler. | ||
897 | * | ||
898 | * @param db database handle | ||
899 | */ | ||
900 | void | ||
901 | GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db); | ||
902 | |||
903 | |||
904 | /** | ||
905 | * Stop running poll event loop using the GNUnet scheduler. | ||
906 | * | ||
907 | * @param db database handle | ||
908 | */ | ||
909 | void | ||
910 | GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db); | ||
911 | |||
912 | |||
913 | /** | ||
914 | * Handle for an active LISTENer to the database. | ||
915 | */ | ||
916 | struct GNUNET_PQ_EventHandler; | ||
917 | |||
918 | /** | ||
919 | * Function called on events received from Postgres. | ||
920 | * | ||
921 | * @param cls closure | ||
922 | * @param extra additional event data provided | ||
923 | * @param extra_size number of bytes in @a extra | ||
924 | */ | ||
925 | typedef void | ||
926 | (*GNUNET_PQ_EventCallback)(void *cls, | ||
927 | const void *extra, | ||
928 | size_t extra_size); | ||
929 | |||
930 | GNUNET_NETWORK_STRUCT_BEGIN | ||
931 | |||
932 | |||
933 | /** | ||
934 | * Header of a structure that describes an | ||
935 | * event channel we may subscribe to or notify on. | ||
936 | */ | ||
937 | struct GNUNET_PQ_EventHeaderP | ||
938 | { | ||
939 | /** | ||
940 | * The length of the struct (in bytes, including the length field itself), | ||
941 | * in big-endian format. | ||
942 | */ | ||
943 | uint16_t size GNUNET_PACKED; | ||
944 | |||
945 | /** | ||
946 | * The type of the message (GNUNET_PQ_EVENT_TYPE_XXXX), in big-endian format. | ||
947 | */ | ||
948 | uint16_t type GNUNET_PACKED; | ||
949 | |||
950 | }; | ||
951 | |||
952 | GNUNET_NETWORK_STRUCT_END | ||
953 | |||
954 | |||
955 | /** | ||
956 | * Handle for an active LISTENer to the database. | ||
957 | */ | ||
958 | struct GNUNET_PQ_EventHandler; | ||
959 | |||
960 | /** | ||
961 | * Register callback to be invoked on events of type @a es. | 856 | * Register callback to be invoked on events of type @a es. |
962 | * | 857 | * |
963 | * Unlike many other calls, this function is thread-safe | 858 | * Unlike many other calls, this function is thread-safe |
964 | * and may be called from threads that are different | 859 | * and may be called from threads that are different |
965 | * from the one that setup @a db. However, the @a cb | 860 | * from the one that setup @a db. However, the @a cb |
@@ -968,21 +863,23 @@ struct GNUNET_PQ_EventHandler; | |||
968 | * | 863 | * |
969 | * @param db database context to use | 864 | * @param db database context to use |
970 | * @param es specification of the event to listen for | 865 | * @param es specification of the event to listen for |
866 | * @param timeout when to trigger @a cb based on timeout | ||
971 | * @param cb function to call when the event happens, possibly | 867 | * @param cb function to call when the event happens, possibly |
972 | * multiple times (until #GNUNET_PQ_event_listen_cancel() is invoked) | 868 | * multiple times (until #GNUNET_PQ_event_listen_cancel() is invoked), including on timeout |
973 | * @param cb_cls closure for @a cb | 869 | * @param cb_cls closure for @a cb |
974 | * @return handle useful to cancel the listener | 870 | * @return handle useful to cancel the listener |
975 | */ | 871 | */ |
976 | struct GNUNET_PQ_EventHandler * | 872 | struct GNUNET_DB_EventHandler * |
977 | GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | 873 | GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, |
978 | const struct GNUNET_PQ_EventHeaderP *es, | 874 | const struct GNUNET_DB_EventHeaderP *es, |
979 | GNUNET_PQ_EventCallback cb, | 875 | struct GNUNET_TIME_Relative timeout, |
876 | GNUNET_DB_EventCallback cb, | ||
980 | void *cb_cls); | 877 | void *cb_cls); |
981 | 878 | ||
982 | 879 | ||
983 | /** | 880 | /** |
984 | * Stop notifications. | 881 | * Stop notifications. |
985 | * | 882 | * |
986 | * Unlike many other calls, this function is thread-safe | 883 | * Unlike many other calls, this function is thread-safe |
987 | * and may be called from threads that are different | 884 | * and may be called from threads that are different |
988 | * from the one that setup @a db. However, the @a cb | 885 | * from the one that setup @a db. However, the @a cb |
@@ -992,12 +889,12 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
992 | * @param eh handle to unregister. | 889 | * @param eh handle to unregister. |
993 | */ | 890 | */ |
994 | void | 891 | void |
995 | GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh); | 892 | GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh); |
996 | 893 | ||
997 | 894 | ||
998 | /** | 895 | /** |
999 | * Notify all that listen on @a es of an event. | 896 | * Notify all that listen on @a es of an event. |
1000 | * | 897 | * |
1001 | * Unlike many other calls, this function is thread-safe | 898 | * Unlike many other calls, this function is thread-safe |
1002 | * and may be called from threads that are different | 899 | * and may be called from threads that are different |
1003 | * from the one that setup @a db. However, the @a cb | 900 | * from the one that setup @a db. However, the @a cb |
@@ -1011,7 +908,7 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh); | |||
1011 | */ | 908 | */ |
1012 | void | 909 | void |
1013 | GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, | 910 | GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, |
1014 | const struct GNUNET_PQ_EventHeaderP *es, | 911 | const struct GNUNET_DB_EventHeaderP *es, |
1015 | const void *extra, | 912 | const void *extra, |
1016 | size_t extra_size); | 913 | size_t extra_size); |
1017 | 914 | ||