Blame src/mw_srvc_aware.h

Packit 16808d
Packit 16808d
/*
Packit 16808d
  Meanwhile - Unofficial Lotus Sametime Community Client Library
Packit 16808d
  Copyright (C) 2004  Christopher (siege) O'Brien
Packit 16808d
  
Packit 16808d
  This library is free software; you can redistribute it and/or
Packit 16808d
  modify it under the terms of the GNU Library General Public
Packit 16808d
  License as published by the Free Software Foundation; either
Packit 16808d
  version 2 of the License, or (at your option) any later version.
Packit 16808d
  
Packit 16808d
  This library is distributed in the hope that it will be useful,
Packit 16808d
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 16808d
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 16808d
  Library General Public License for more details.
Packit 16808d
  
Packit 16808d
  You should have received a copy of the GNU Library General Public
Packit 16808d
  License along with this library; if not, write to the Free
Packit 16808d
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Packit 16808d
*/
Packit 16808d
Packit 16808d
#ifndef _MW_SRVC_AWARE_H
Packit 16808d
#define _MW_SRVC_AWARE_H
Packit 16808d
Packit 16808d
Packit 16808d
/** @file mw_srvc_aware.h
Packit 16808d
Packit 16808d
    The aware service...
Packit 16808d
Packit 16808d
    @todo remove the whole idea of an instantiated mwAwareList and
Packit 16808d
    instead use arbitrary pointers (including NULL) as keys to
Packit 16808d
    internally stored lists. This removes the problem of the service
Packit 16808d
    free'ing its lists and invalidating mwAwareList references from
Packit 16808d
    client code.
Packit 16808d
*/
Packit 16808d
Packit 16808d
Packit 16808d
#include "mw_common.h"
Packit 16808d
Packit 16808d
Packit 16808d
#ifdef __cplusplus
Packit 16808d
extern "C" {
Packit 16808d
#endif
Packit 16808d
Packit 16808d
Packit 16808d
/** Type identifier for the aware service */
Packit 16808d
#define mwService_AWARE  0x00000011
Packit 16808d
Packit 16808d
Packit 16808d
/** @struct mwServiceAware
Packit 16808d
Packit 16808d
    Instance of an Aware Service. The members of this structure are
Packit 16808d
    not made available. Accessing the parts of an aware service should
Packit 16808d
    be performed through the appropriate functions. Note that
Packit 16808d
    instances of this structure can be safely cast to a mwService.
Packit 16808d
*/
Packit 16808d
struct mwServiceAware;
Packit 16808d
Packit 16808d
Packit 16808d
/** @struct mwAwareList
Packit 16808d
Packit 16808d
    Instance of an Aware List. The members of this structure are not
Packit 16808d
    made available. Access to the parts of an aware list should be
Packit 16808d
    handled through the appropriate functions.
Packit 16808d
Packit 16808d
    Any references to an aware list are rendered invalid when the
Packit 16808d
    parent service is free'd
Packit 16808d
*/
Packit 16808d
struct mwAwareList;
Packit 16808d
Packit 16808d
Packit 16808d
/** @struct mwAwareAttribute
Packit 16808d
Packit 16808d
    Key/Opaque pair indicating an identity's attribute.
Packit 16808d
 */
Packit 16808d
struct mwAwareAttribute;
Packit 16808d
Packit 16808d
Packit 16808d
/** Predefined keys appropriate for a mwAwareAttribute
Packit 16808d
 */
Packit 16808d
enum mwAwareAttributeKeys {
Packit 16808d
  mwAttribute_AV_PREFS_SET   = 0x01, /**< A/V prefs specified, gboolean */
Packit 16808d
  mwAttribute_MICROPHONE     = 0x02, /**< has a microphone, gboolean */
Packit 16808d
  mwAttribute_SPEAKERS       = 0x03, /**< has speakers, gboolean */
Packit 16808d
  mwAttribute_VIDEO_CAMERA   = 0x04, /**< has a video camera, gboolean */
Packit 16808d
  mwAttribute_FILE_TRANSFER  = 0x06, /**< supports file transfers, gboolean */
Packit 16808d
};
Packit 16808d
Packit 16808d
Packit 16808d
typedef void (*mwAwareAttributeHandler)
Packit 16808d
     (struct mwServiceAware *srvc,
Packit 16808d
      struct mwAwareAttribute *attrib);
Packit 16808d
Packit 16808d
Packit 16808d
struct mwAwareHandler {
Packit 16808d
  mwAwareAttributeHandler on_attrib;
Packit 16808d
  void (*clear)(struct mwServiceAware *srvc);
Packit 16808d
};
Packit 16808d
Packit 16808d
Packit 16808d
/** Appropriate function type for the on-aware signal
Packit 16808d
Packit 16808d
    @param list  mwAwareList emiting the signal
Packit 16808d
    @param id    awareness status information
Packit 16808d
    @param data  user-specified data
Packit 16808d
*/
Packit 16808d
typedef void (*mwAwareSnapshotHandler)
Packit 16808d
     (struct mwAwareList *list,
Packit 16808d
      struct mwAwareSnapshot *id);
Packit 16808d
Packit 16808d
Packit 16808d
/** Appropriate function type for the on-option signal. The option's
Packit 16808d
    value may need to be explicitly loaded in some instances,
Packit 16808d
    resulting in this handler being triggered again.
Packit 16808d
Packit 16808d
    @param list    mwAwareList emiting the signal
Packit 16808d
    @param id      awareness the attribute belongs to
Packit 16808d
    @param attrib  attribute
Packit 16808d
*/
Packit 16808d
typedef void (*mwAwareIdAttributeHandler)
Packit 16808d
     (struct mwAwareList *list,
Packit 16808d
      struct mwAwareIdBlock *id,
Packit 16808d
      struct mwAwareAttribute *attrib);
Packit 16808d
Packit 16808d
Packit 16808d
struct mwAwareListHandler {
Packit 16808d
  /** handle aware updates */
Packit 16808d
  mwAwareSnapshotHandler on_aware;
Packit 16808d
Packit 16808d
  /** handle attribute updates */
Packit 16808d
  mwAwareIdAttributeHandler on_attrib;
Packit 16808d
Packit 16808d
  /** optional. Called from mwAwareList_free */
Packit 16808d
  void (*clear)(struct mwAwareList *list);
Packit 16808d
};
Packit 16808d
Packit 16808d
Packit 16808d
struct mwServiceAware *
Packit 16808d
mwServiceAware_new(struct mwSession *session,
Packit 16808d
		   struct mwAwareHandler *handler);
Packit 16808d
Packit 16808d
Packit 16808d
/** Set an attribute value for this session */
Packit 16808d
int mwServiceAware_setAttribute(struct mwServiceAware *srvc,
Packit 16808d
				guint32 key, struct mwOpaque *opaque);
Packit 16808d
Packit 16808d
Packit 16808d
int mwServiceAware_setAttributeBoolean(struct mwServiceAware *srvc,
Packit 16808d
				       guint32 key, gboolean val);
Packit 16808d
Packit 16808d
Packit 16808d
int mwServiceAware_setAttributeInteger(struct mwServiceAware *srvc,
Packit 16808d
				       guint32 key, guint32 val);
Packit 16808d
Packit 16808d
Packit 16808d
int mwServiceAware_setAttributeString(struct mwServiceAware *srvc,
Packit 16808d
				      guint32 key, const char *str);
Packit 16808d
Packit 16808d
Packit 16808d
/** Unset an attribute for this session */
Packit 16808d
int mwServiceAware_unsetAttribute(struct mwServiceAware *srvc,
Packit 16808d
				  guint32 key);
Packit 16808d
Packit 16808d
Packit 16808d
guint32 mwAwareAttribute_getKey(const struct mwAwareAttribute *attrib);
Packit 16808d
Packit 16808d
Packit 16808d
gboolean mwAwareAttribute_asBoolean(const struct mwAwareAttribute *attrib);
Packit 16808d
Packit 16808d
Packit 16808d
guint32 mwAwareAttribute_asInteger(const struct mwAwareAttribute *attrib);
Packit 16808d
Packit 16808d
Packit 16808d
/** Copy of attribute string, must be g_free'd. If the attribute's
Packit 16808d
    content cannot be loaded as a string, returns NULL */
Packit 16808d
char *mwAwareAttribute_asString(const struct mwAwareAttribute *attrib);
Packit 16808d
Packit 16808d
Packit 16808d
/** Direct access to an attribute's underlying opaque */
Packit 16808d
const struct mwOpaque *
Packit 16808d
mwAwareAttribute_asOpaque(const struct mwAwareAttribute *attrib);
Packit 16808d
Packit 16808d
Packit 16808d
/** Allocate and initialize an aware list */
Packit 16808d
struct mwAwareList *
Packit 16808d
mwAwareList_new(struct mwServiceAware *srvc,
Packit 16808d
		struct mwAwareListHandler *handler);
Packit 16808d
Packit 16808d
Packit 16808d
/** Clean and free an aware list */
Packit 16808d
void mwAwareList_free(struct mwAwareList *list);
Packit 16808d
Packit 16808d
Packit 16808d
struct mwAwareListHandler *mwAwareList_getHandler(struct mwAwareList *list);
Packit 16808d
Packit 16808d
Packit 16808d
/** Add a collection of user IDs to an aware list.
Packit 16808d
    @param list     mwAwareList to add user ID to
Packit 16808d
    @param id_list  mwAwareIdBlock list of user IDs to add
Packit 16808d
    @return         0 for success, non-zero to indicate an error.
Packit 16808d
*/
Packit 16808d
int mwAwareList_addAware(struct mwAwareList *list, GList *id_list);
Packit 16808d
Packit 16808d
Packit 16808d
/** Remove a collection of user IDs from an aware list.
Packit 16808d
    @param list     mwAwareList to remove user ID from
Packit 16808d
    @param id_list  mwAwareIdBlock list of user IDs to remove
Packit 16808d
    @return  0      for success, non-zero to indicate an error.
Packit 16808d
*/
Packit 16808d
int mwAwareList_removeAware(struct mwAwareList *list, GList *id_list);
Packit 16808d
Packit 16808d
Packit 16808d
int mwAwareList_removeAllAware(struct mwAwareList *list);
Packit 16808d
Packit 16808d
Packit 16808d
/** watch an NULL terminated array of keys */
Packit 16808d
int mwAwareList_watchAttributeArray(struct mwAwareList *list,
Packit 16808d
				    guint32 *keys);
Packit 16808d
Packit 16808d
Packit 16808d
/** watch a NULL terminated list of keys */
Packit 16808d
int mwAwareList_watchAttributes(struct mwAwareList *list,
Packit 16808d
				guint32 key, ...);
Packit 16808d
Packit 16808d
Packit 16808d
/** stop watching a NULL terminated array of keys */
Packit 16808d
int mwAwareList_unwatchAttributeArray(struct mwAwareList *list,
Packit 16808d
				      guint32 *keys);
Packit 16808d
Packit 16808d
Packit 16808d
/** stop watching a NULL terminated list of keys */
Packit 16808d
int mwAwareList_unwatchAttributes(struct mwAwareList *list,
Packit 16808d
				  guint32 key, ...);
Packit 16808d
Packit 16808d
Packit 16808d
/** remove all watched attributes */
Packit 16808d
int mwAwareList_unwatchAllAttributes(struct mwAwareList *list);
Packit 16808d
Packit 16808d
Packit 16808d
guint32 *mwAwareList_getWatchedAttributes(struct mwAwareList *list);
Packit 16808d
Packit 16808d
Packit 16808d
void mwAwareList_setClientData(struct mwAwareList *list,
Packit 16808d
			       gpointer data, GDestroyNotify cleanup);
Packit 16808d
Packit 16808d
Packit 16808d
void mwAwareList_removeClientData(struct mwAwareList *list);
Packit 16808d
Packit 16808d
Packit 16808d
gpointer mwAwareList_getClientData(struct mwAwareList *list);
Packit 16808d
Packit 16808d
Packit 16808d
/** trigger a got_aware event constructed from the passed user and
Packit 16808d
    status information. Useful for adding false users and having the
Packit 16808d
    getText function work for them */
Packit 16808d
void mwServiceAware_setStatus(struct mwServiceAware *srvc,
Packit 16808d
			      struct mwAwareIdBlock *user,
Packit 16808d
			      struct mwUserStatus *stat);
Packit 16808d
Packit 16808d
Packit 16808d
/** look up the status description for a user */
Packit 16808d
const char *mwServiceAware_getText(struct mwServiceAware *srvc,
Packit 16808d
				   struct mwAwareIdBlock *user);
Packit 16808d
Packit 16808d
Packit 16808d
/** look up the last known copy of an attribute for a user by the
Packit 16808d
    attribute's key */
Packit 16808d
const struct mwAwareAttribute *
Packit 16808d
mwServiceAware_getAttribute(struct mwServiceAware *srvc,
Packit 16808d
			    struct mwAwareIdBlock *user,
Packit 16808d
			    guint32 key);
Packit 16808d
Packit 16808d
Packit 16808d
#ifdef __cplusplus
Packit 16808d
}
Packit 16808d
#endif
Packit 16808d
Packit 16808d
Packit 16808d
#endif /* _MW_SRVC_AWARE_H */
Packit 16808d