File indexing completed on 2025-01-05 04:27:01

0001 /****************************************************************************************
0002  * Copyright (c) 2008 MP3tunes, LLC <copyright@mp3tunes.com>                            *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU Library General Public License as published by the Free         *
0006  * Software Foundation; either version 2.1 of the License, or (at your option) any      *
0007  * later version.                                                                       *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU Library General Public License along with *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef __HARMONY_H
0018 #define __HARMONY_H
0019 
0020 #include <stdlib.h>
0021 
0022 #include <glib.h>
0023 #include <glib-object.h>
0024 #include "locker.h"
0025 #include "loudmouth/loudmouth.h"
0026 
0027 G_BEGIN_DECLS
0028 
0029 
0030 #define MP3TUNES_HARMONY_HOST "harmony.mp3tunes.com"
0031 #define MP3TUNES_HARMONY_JID_HOST "mp3tunes.com"
0032 #define MP3TUNES_HARMONY_PORT 5222
0033 #define MP3TUNES_HARMONY_CONDUCTOR "harmony_conductor@mp3tunes.com/harmony"
0034 #define MP3TUNES_HARMONY_DEFAULT_PASSWORD "harmony"
0035 #define MP3TUNES_HARMONY_XMLNS "http://www.mp3tunes.com/api/harmony"
0036 
0037 enum {
0038     MP3TUNES_HARMONY_ERROR_MISC
0039 };
0040 
0041 typedef enum {
0042     MP3TUNES_HARMONY_STATE_DISCONNECTED,
0043     MP3TUNES_HARMONY_STATE_CONNECTED,
0044     MP3TUNES_HARMONY_STATE_WAITING_FOR_PIN,
0045     MP3TUNES_HARMONY_STATE_WAITING_FOR_EMAIL
0046 } mp3tunes_harmony_state_t;
0047 
0048 typedef enum {
0049     MP3TUNES_HARMONY_SID_STATE_NONE,
0050     MP3TUNES_HARMONY_SID_STATE_WAITING,
0051     MP3TUNES_HARMONY_SID_STATE_READY
0052 } mp3tunes_harmony_sid_state_t;
0053 
0054 typedef enum {
0055     MP3TUNES_HARMONY_DEVICE_ATTRIBUTE_TYPE_STRING,
0056     MP3TUNES_HARMONY_DEVICE_ATTRIBUTE_TYPE_INT
0057 } mp3tunes_harmony_device_attribute_type_t;
0058 
0059 typedef struct {
0060     char* attribute_name;
0061     char* attribute_string_value;
0062     long long int attribute_int_value;
0063     mp3tunes_harmony_device_attribute_type_t attribute_value_type;
0064 } mp3tunes_harmony_device_attribute_t;
0065 
0066 typedef struct {
0067     char* file_key;
0068     char* file_name;
0069     char* file_format;
0070     unsigned int file_size;
0071     char* artist_name;
0072     char* album_title;
0073     char* track_title;
0074     int track_number;
0075     char* device_bitrate;
0076     char* file_bitrate;
0077     char* url;
0078 } mp3tunes_harmony_download_t;
0079 
0080 int mp3tunes_harmony_download_init(mp3tunes_harmony_download_t **harmony_download_t);
0081 int mp3tunes_harmony_download_deinit(mp3tunes_harmony_download_t **harmony_download_t);
0082 
0083 typedef struct {
0084     GObject parent;
0085     LmConnection *connection;
0086     LmMessageHandler *harmony_iq_message_handler;
0087 
0088     mp3tunes_locker_object_t* mp3tunes_locker;
0089 
0090     GQueue *download_queue;
0091 
0092     gboolean connected;
0093     char *device_identifier;
0094     char *device_pin;
0095     char *device_email;
0096     char *device_formatted_email;
0097     const char *host;
0098     int port;
0099     mp3tunes_harmony_sid_state_t sid_state;
0100     GList *device_attributes;
0101     GError *error;
0102 } MP3tunesHarmony;
0103 
0104 typedef struct {
0105     GObjectClass parent;
0106 
0107     guint state_change_signal_id;
0108     guint error_signal_id;
0109     guint download_pending_signal_id;
0110     guint download_ready_signal_id;
0111 } MP3tunesHarmonyClass;
0112 
0113 #define MP3TUNES_HARMONY_ERROR_DOMAIN g_quark_from_string("MP3TUNES_HARMONY")
0114 
0115 #define MP3TUNES_TYPE_HARMONY            (mp3tunes_harmony_get_type ())
0116 #define MP3TUNES_HARMONY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), MP3TUNES_TYPE_HARMONY, MP3tunesHarmony))
0117 #define MP3TUNES_HARMONY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), MP3TUNES_TYPE_HARMONY, MP3tunesHarmonyClass))
0118 #define MP3TUNES_IS_HARMONY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj),MP3TUNES_TYPE_HARMONY))
0119 #define MP3TUNES_IS_HARMONY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MP3TUNES_TYPE_HARMONY))
0120 #define MP3TUNES_HARMONY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), MP3TUNES_TYPE_HARMONY, MP3tunesHarmonyClass))
0121 
0122 MP3tunesHarmony* mp3tunes_harmony_new(void);
0123 GType mp3tunes_harmony_get_type(void);
0124 
0125 void mp3tunes_harmony_set_pin(MP3tunesHarmony *harmony, const char *pin);
0126 void mp3tunes_harmony_set_email(MP3tunesHarmony *harmony, char *email);
0127 void mp3tunes_harmony_set_identifier(MP3tunesHarmony *harmony, char *email);
0128 void mp3tunes_harmony_set_device_attribute(MP3tunesHarmony *harmony, const char *attribute, ...);
0129 
0130 char *mp3tunes_harmony_get_pin(MP3tunesHarmony *harmony);
0131 char *mp3tunes_harmony_get_email(MP3tunesHarmony *harmony);
0132 char *mp3tunes_harmony_get_identifier(MP3tunesHarmony *harmony);
0133 char *mp3tunes_harmony_get_jid(MP3tunesHarmony *harmony);
0134 
0135 gboolean mp3tunes_harmony_connect(MP3tunesHarmony *harmony, GError** err);
0136 gboolean mp3tunes_harmony_disconnect(MP3tunesHarmony *harmony, GError** err);
0137 
0138 void mp3tunes_harmony_send_device_status(MP3tunesHarmony *harmony, GError **err);
0139 
0140 mp3tunes_harmony_download_t* mp3tunes_harmony_download_queue_pop(MP3tunesHarmony *harmony);
0141 
0142 G_END_DECLS
0143 
0144 #endif