sbMetadataChannel.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
32 #ifndef __METADATA_CHANNEL_H__
33 #define __METADATA_CHANNEL_H__
34 
35 // INCLUDES ===================================================================
36 #include <nscore.h>
37 #include <nsStringGlue.h>
38 #include <nsMemory.h>
39 #include <nsIChannelEventSink.h>
40 #include <nsIInterfaceRequestor.h>
41 #include <nsCOMPtr.h>
42 #include "sbIMetadataChannel.h"
43 #include <map>
44 
45 // DEFINES ====================================================================
46 #define SONGBIRD_METADATACHANNEL_CONTRACTID \
47  "@songbirdnest.com/Songbird/MetadataChannel;1"
48 #define SONGBIRD_METADATACHANNEL_CLASSNAME \
49  "Songbird Metadata Channel Helper"
50 #define SONGBIRD_METADATACHANNEL_CID \
51 { /* 37595d88-f49e-4309-89a1-376749a4b285 */ \
52  0x37595d88, \
53  0xf49e, \
54  0x4309, \
55  {0x89, 0xa1, 0x37, 0x67, 0x49, 0xa4, 0xb2, 0x85} \
56 }
57 // FUNCTIONS ==================================================================
58 
59 // CLASSES ====================================================================
61 {
63  NS_DECL_SBIMETADATACHANNEL
64  NS_DECL_NSISTREAMLISTENER
65  NS_DECL_NSIREQUESTOBSERVER
66 
68  virtual ~sbMetadataChannel();
69 
70  NS_IMETHODIMP SetRedirectedChannel(nsIChannel* aChannel);
71 
72  // Internal constants
73  enum sbBufferConstants
74  {
75  SIZE_SHIFT = 16, // 64k blocks (what things seem to prefer)
76  BLOCK_SIZE = ( 1 << SIZE_SHIFT ),
77  BLOCK_MASK = BLOCK_SIZE - 1
78  };
79 
80  // Helper functions
81  inline PRUint64 IDX( PRUint64 i ) { return ( i >> SIZE_SHIFT ); }
82  inline PRUint64 POS( PRUint64 i ) { return ( i & (PRUint64)BLOCK_MASK ); }
83  inline char * BUF( PRUint64 i ) { return m_Blocks[ IDX(i) ].buf + POS(i); }
84 
85  // Self allocating memory block. Works well with the map [] dereference.
86  struct sbBufferBlock {
87  char *buf;
88  sbBufferBlock() { buf = (char *)nsMemory::Alloc( BLOCK_SIZE ); }
89  sbBufferBlock( const sbBufferBlock &T ) { buf = T.buf; const_cast<sbBufferBlock &>(T).buf = nsnull; }
90  ~sbBufferBlock() { if ( buf ) nsMemory::Free( buf ); }
91  };
92  class blockmap_t : public std::map<PRUint64, sbBufferBlock> {};
93 
94  nsCOMPtr<nsIChannel> m_Channel;
95  nsCOMPtr<sbIMetadataHandler> m_Handler;
96  PRUint64 m_Pos;
97  PRUint64 m_Buf;
98  PRUint64 m_BufDeadZoneStart;
99  PRUint64 m_BufDeadZoneEnd;
100  blockmap_t m_Blocks;
101  PRBool m_Completed;
102 };
103 
104 class sbMetadataChannelEventSink : public nsIChannelEventSink,
105  public nsIInterfaceRequestor
106 {
107 public:
109  NS_DECL_NSICHANNELEVENTSINK
110  NS_DECL_NSIINTERFACEREQUESTOR
111 
112  sbMetadataChannelEventSink(sbMetadataChannel* aMetadataChannel);
113 
114 private:
115  ~sbMetadataChannelEventSink();
116 
117  sbMetadataChannel* mMetadataChannel;
118 };
119 
120 // Now I have a slightly smaller chance of getting screwed.
121 #define NS_ERROR_SONGBIRD_METADATA_CHANNEL_RESTART NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_GENERAL, 1 )
122 
123 #endif // __METADATA_CHANNEL_H__
124 
A wrapper for an nsIChannel that buffers the incoming data.
readonly attribute PRUInt64 buf
The current internal buffer position (everything the channel has sent)
const nsIChannel
const nsIInterfaceRequestor
_getSelectedPageStyle s i