]> git.sesse.net Git - vlc/blob - mozilla/vlcplugin.cpp
* mozilla/*: Additional Mozilla 1.4 compilation fixes.
[vlc] / mozilla / vlcplugin.cpp
1 /*****************************************************************************
2  * vlcplugin.cpp: a VLC plugin for Mozilla
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: vlcplugin.cpp,v 1.5 2003/07/16 16:33:59 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28
29 #include <nsISupports.h>
30 #include <nsMemory.h>
31 #include <npapi.h>
32
33 #include "vlcpeer.h"
34 #include "vlcplugin.h"
35
36 /*****************************************************************************
37  * VlcPlugin constructor and destructor
38  *****************************************************************************/
39 VlcPlugin::VlcPlugin( NPP instance )
40 {
41     p_instance = instance;
42     p_peer = NULL;
43 }
44
45
46 VlcPlugin::~VlcPlugin()
47 {
48     if( p_peer )
49     {
50         p_peer->Disable();
51         p_peer->Release();
52     }
53 }
54
55
56 /*****************************************************************************
57  * VlcPlugin methods
58  *****************************************************************************/
59 void VlcPlugin::SetInstance( NPP instance )
60 {
61     p_instance = instance;
62 }
63
64
65 NPP VlcPlugin::GetInstance()
66 {
67     return p_instance;
68 }
69
70
71 VlcIntf* VlcPlugin::GetPeer()
72 {
73     if( !p_peer )
74     {
75         p_peer = new VlcPeer( this );
76         if( p_peer == NULL )
77         {
78             return NULL;
79         }
80
81         NS_ADDREF( p_peer );
82     }
83
84     NS_ADDREF( p_peer );
85     return p_peer;
86 }
87
88 void VlcPlugin::SetFileName(const char * filename)
89 {
90 #if 0
91     FILE * fh;
92     fh = fopen(filename, "rb");
93     if(!fh)
94     {
95         fprintf(stderr, "Error while opening %s.\n", filename);
96         return;
97     }
98     fseek(fh, 0, SEEK_END);
99     m_lSize = ftell(fh);
100     m_szSound = (char*) malloc(m_lSize);
101     if(!m_szSound)
102     {
103         fprintf(stderr, "Error while allocating memory.\n");
104         fclose(fh);
105         return;
106     }
107     rewind(fh);
108     long pos = 0;
109     do
110     {
111         pos += fread(m_szSound + pos, 1, m_lSize - pos, fh);
112         fprintf(stderr, "pos = %d\n", pos);
113     }
114     while (pos < m_lSize -1);
115     fclose (fh);
116     fprintf(stderr, "File loaded\n");
117 #endif
118     return;
119 }
120