agent.h 4.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*
 * This file is part of the Nice GLib ICE library.
 *
 * (C) 2006, 2007 Collabora Ltd.
 *  Contact: Dafydd Harries
 * (C) 2006, 2007 Nokia Corporation. All rights reserved.
 *  Contact: Kai Vehmanen
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the Nice GLib ICE library.
 *
 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
 * Corporation. All Rights Reserved.
 *
 * Contributors:
 *   Dafydd Harries, Collabora Ltd.
 *
 * Alternatively, the contents of this file may be used under the terms of the
 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
 * case the provisions of LGPL are applicable instead of those above. If you
 * wish to allow use of your version of this file only under the terms of the
 * LGPL and not to allow others to use your version of this file under the
 * MPL, indicate your decision by deleting the provisions above and replace
 * them with the notice and other provisions required by the LGPL. If you do
 * not delete the provisions above, a recipient may use your version of this
 * file under either the MPL or the LGPL.
 */
Dafydd Harries's avatar
Dafydd Harries committed
37 38 39 40

#ifndef _AGENT_H
#define _AGENT_H

Dafydd Harries's avatar
Dafydd Harries committed
41
#include <glib-object.h>
42 43

#include "udp.h"
44
#include "address.h"
Dafydd Harries's avatar
Dafydd Harries committed
45
#include "candidate.h"
Dafydd Harries's avatar
Dafydd Harries committed
46
#include "random.h"
47

Dafydd Harries's avatar
Dafydd Harries committed
48
G_BEGIN_DECLS
49

Dafydd Harries's avatar
Dafydd Harries committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#define NICE_TYPE_AGENT nice_agent_get_type()

#define NICE_AGENT(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
  NICE_TYPE_AGENT, NiceAgent))

#define NICE_AGENT_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST ((klass), \
  NICE_TYPE_AGENT, NiceAgentClass))

#define NICE_IS_AGENT(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
  NICE_TYPE_AGENT))

#define NICE_IS_AGENT_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
  NICE_TYPE_AGENT))

#define NICE_AGENT_GET_CLASS(obj) \
  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
  NICE_TYPE_AGENT, NiceAgentClass))

72 73 74 75 76 77 78
typedef enum
{
  NICE_COMPONENT_STATE_DISCONNECTED,
  NICE_COMPONENT_STATE_CONNECTING,
  NICE_COMPONENT_STATE_CONNECTED,
} NiceComponentState;

79
typedef struct _NiceAgent NiceAgent;
Dafydd Harries's avatar
Dafydd Harries committed
80

81 82 83 84
typedef void (*NiceAgentRecvFunc) (
  NiceAgent *agent, guint stream_id, guint component_id, guint len,
  gchar *buf, gpointer user_data);

85
struct _NiceAgent
Dafydd Harries's avatar
Dafydd Harries committed
86
{
Dafydd Harries's avatar
Dafydd Harries committed
87
  GObject parent;
Dafydd Harries's avatar
Dafydd Harries committed
88
  guint next_candidate_id;
Dafydd Harries's avatar
Dafydd Harries committed
89
  guint next_stream_id;
Dafydd Harries's avatar
Dafydd Harries committed
90
  NiceUDPSocketFactory *socket_factory;
Dafydd Harries's avatar
Dafydd Harries committed
91 92
  GSList *local_addresses;
  GSList *streams;
93 94 95 96
  gboolean main_context_set;
  GMainContext *main_context;
  NiceAgentRecvFunc read_func;
  gpointer read_func_data;
Dafydd Harries's avatar
Dafydd Harries committed
97
  gchar *stun_server;
Dafydd Harries's avatar
Dafydd Harries committed
98
  NiceRNG *rng;
Dafydd Harries's avatar
Dafydd Harries committed
99 100
};

Dafydd Harries's avatar
Dafydd Harries committed
101 102 103 104 105 106 107 108 109
typedef struct _NiceAgentClass NiceAgentClass;

struct _NiceAgentClass
{
  GObjectClass parent_class;
};

GType nice_agent_get_type (void);

110
NiceAgent *
Dafydd Harries's avatar
Dafydd Harries committed
111
nice_agent_new (NiceUDPSocketFactory *factory);
112

Dafydd Harries's avatar
Dafydd Harries committed
113
void
114
nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr);
115

Dafydd Harries's avatar
Dafydd Harries committed
116
guint
117 118
nice_agent_add_stream (
  NiceAgent *agent,
119
  guint n_components);
120

Dafydd Harries's avatar
Dafydd Harries committed
121 122 123 124 125
void
nice_agent_remove_stream (
  NiceAgent *agent,
  guint stream_id);

126
void
127 128
nice_agent_add_remote_candidate (
  NiceAgent *agent,
129 130
  guint stream_id,
  guint component_id,
131 132
  NiceCandidateType type,
  NiceAddress *addr,
133 134
  const gchar *username,
  const gchar *password);
135

Dafydd Harries's avatar
Dafydd Harries committed
136
guint
137
nice_agent_recv (
Dafydd Harries's avatar
Dafydd Harries committed
138 139 140 141 142 143
  NiceAgent *agent,
  guint stream_id,
  guint component_id,
  guint buf_len,
  gchar *buf);

Dafydd Harries's avatar
Dafydd Harries committed
144 145 146 147 148 149 150 151 152
guint
nice_agent_recv_sock (
  NiceAgent *agent,
  guint stream_id,
  guint component_id,
  guint sock,
  guint buf_len,
  gchar *buf);

Dafydd Harries's avatar
Dafydd Harries committed
153 154 155
GSList *
nice_agent_poll_read (
  NiceAgent *agent,
156 157 158
  GSList *other_fds,
  NiceAgentRecvFunc func,
  gpointer data);
Dafydd Harries's avatar
Dafydd Harries committed
159

Dafydd Harries's avatar
Dafydd Harries committed
160 161 162 163 164 165
void
nice_agent_send (
  NiceAgent *agent,
  guint stream_id,
  guint component_id,
  guint len,
166
  const gchar *buf);
Dafydd Harries's avatar
Dafydd Harries committed
167

168
GSList *
169
nice_agent_get_local_candidates (
170 171 172
  NiceAgent *agent,
  guint stream_id,
  guint component_id);
Dafydd Harries's avatar
Dafydd Harries committed
173

174 175 176 177 178 179
GSList *
nice_agent_get_remote_candidates (
  NiceAgent *agent,
  guint stream_id,
  guint component_id);

180 181 182 183 184 185 186
gboolean
nice_agent_main_context_attach (
  NiceAgent *agent,
  GMainContext *ctx,
  NiceAgentRecvFunc func,
  gpointer data);

Dafydd Harries's avatar
Dafydd Harries committed
187 188
G_END_DECLS

Dafydd Harries's avatar
Dafydd Harries committed
189 190
#endif /* _AGENT_H */