libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

gnunet_chat_discourse.h (3655B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2024 GNUnet e.V.
      4 
      5    GNUnet is free software: you can redistribute it and/or modify it
      6    under the terms of the GNU Affero General Public License as published
      7    by the Free Software Foundation, either version 3 of the License,
      8    or (at your option) any later version.
      9 
     10    GNUnet is distributed in the hope that it will be useful, but
     11    WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13    Affero General Public License for more details.
     14 
     15    You should have received a copy of the GNU Affero General Public License
     16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18    SPDX-License-Identifier: AGPL3.0-or-later
     19  */
     20 /*
     21  * @author Tobias Frisch
     22  * @file gnunet_chat_discourse.h
     23  */
     24 
     25 #ifndef GNUNET_CHAT_DISCOURSE_H_
     26 #define GNUNET_CHAT_DISCOURSE_H_
     27 
     28 #include "gnunet_chat_util.h"
     29 
     30 #include <gnunet/gnunet_common.h>
     31 #include <gnunet/gnunet_messenger_service.h>
     32 #include <gnunet/gnunet_time_lib.h>
     33 #include <gnunet/gnunet_util_lib.h>
     34 
     35 struct GNUNET_CHAT_Contact;
     36 struct GNUNET_CHAT_Context;
     37 
     38 struct GNUNET_CHAT_DiscourseSubscription
     39 {
     40   struct GNUNET_CHAT_DiscourseSubscription *prev;
     41   struct GNUNET_CHAT_DiscourseSubscription *next;
     42 
     43   struct GNUNET_CHAT_Discourse *discourse;
     44 
     45   struct GNUNET_TIME_Absolute start;
     46   struct GNUNET_TIME_Absolute end;
     47 
     48   struct GNUNET_CHAT_Contact *contact;
     49   struct GNUNET_SCHEDULER_Task *task;
     50 };
     51 
     52 struct GNUNET_CHAT_Discourse
     53 {
     54   struct GNUNET_CHAT_Context *context;
     55 
     56   struct GNUNET_CHAT_DiscourseId id;
     57   int pipe [2];
     58 
     59   struct GNUNET_CHAT_DiscourseSubscription *head;
     60   struct GNUNET_CHAT_DiscourseSubscription *tail;
     61 
     62   struct GNUNET_SCHEDULER_Task *pipe_task;
     63 
     64   void *user_pointer;
     65 };
     66 
     67 /**
     68  * Creates a chat discourse within a chat <i>context</i>
     69  * with a selected discourse <i>id</i>.
     70  *
     71  * @param[in,out] context Chat context
     72  * @param[in] id Discourse id
     73  * @return New chat discourse
     74  */
     75 struct GNUNET_CHAT_Discourse*
     76 discourse_create (struct GNUNET_CHAT_Context *context,
     77                   const struct GNUNET_CHAT_DiscourseId *id);
     78 
     79 /**
     80  * Destroys a chat <i>discourse</i> and frees its memory.
     81  *
     82  * @param[in,out] discourse Chat discourse
     83  */
     84 void
     85 discourse_destroy (struct GNUNET_CHAT_Discourse *discourse);
     86 
     87 /**
     88  * Updates the subscription of a specific chat <i>contact</i>
     89  * to a given chat <i>discourse</i> with a selected
     90  * <i>timestamp</i> and relative <i>time</i> window.
     91  *
     92  * @param[in,out] discourse Chat discourse
     93  * @param[in,out] contact Chat contact
     94  * @param[in] timestamp Timestamp
     95  * @param[in] time Time window
     96  * @return #GNUNET_YES on updating an existing subscription,
     97  *         #GNUNET_SYSERR on failure, otherwise #GNUNET_NO
     98  */
     99 enum GNUNET_GenericReturnValue
    100 discourse_subscribe (struct GNUNET_CHAT_Discourse *discourse,
    101                      struct GNUNET_CHAT_Contact *contact,
    102                      const struct GNUNET_TIME_Absolute timestamp,
    103                      const struct GNUNET_TIME_Relative time);
    104 
    105 /**
    106  * Ends the subscription of a specific chat <i>contact</i>
    107  * to a given chat <i>discourse</i> at a selected 
    108  * <i>timestamp</i> with a potential <i>delay</i>.
    109  *
    110  * @param[in,out] discourse Chat discourse
    111  * @param[in,out] contact Chat contact
    112  * @param[in] timestamp Timestamp
    113  * @param[in] delay Delay
    114  */
    115 void
    116 discourse_unsubscribe (struct GNUNET_CHAT_Discourse *discourse,
    117                        struct GNUNET_CHAT_Contact *contact,
    118                        const struct GNUNET_TIME_Absolute timestamp,
    119                        const struct GNUNET_TIME_Relative delay);
    120 
    121 #endif /* GNUNET_CHAT_DISCOURSE_H_ */