front_idill/extern/fajran-npTuioClient/src/plugin.cpp
author bastiena
Fri, 06 Apr 2012 18:32:13 +0200
changeset 25 a7b0e40bcab0
parent 21 e4e5f02787a1
child 27 6c08d4d7219e
permissions -rw-r--r--
Front IDILL : Basic JS TUIO lib loaded
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     1
// 
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     2
//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     3
// 
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     4
// This program is free software; you can redistribute it and/or modify
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     5
// it under the terms of the GNU General Public License as published by
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     6
// the Free Software Foundation; either version 3 of the License, or
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     7
// (at your option) any later version.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     8
// 
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    12
// GNU General Public License for more details.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    13
// 
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    17
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    18
#include "plugin.h"
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    19
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    20
#include <cstring>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    21
#include <iostream>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    22
#include <sstream>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    23
#define D(s) /*std::cerr << s << std::endl;*/
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    24
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    25
#include <set>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    26
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    27
#define MIME_TYPES_HANDLED  "application/x-tuio"
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    28
// The name must be this value to get flash movies that check the
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    29
// plugin version to load.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    30
#define PLUGIN_NAME    "TUIO Client"
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    31
#define MIME_TYPES_DESCRIPTION  MIME_TYPES_HANDLED":tuio:"PLUGIN_NAME
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    32
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    33
#define PLUGIN_DESCRIPTION "TUIO Client plugin"
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    34
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    35
extern NPNetscapeFuncs NPNFuncs;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    36
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    37
NPBool plugInitialized = FALSE;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    38
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    39
static std::set<nsPluginInstance*> instances;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    40
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    41
void tuio_callback(TuioEventData data)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    42
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    43
	std::set<nsPluginInstance*>::iterator iter;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    44
	for (iter = instances.begin(); iter != instances.end(); iter++) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    45
		(*iter)->event(data);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    46
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    47
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    48
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    49
void
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    50
PR_CALLBACK Destructor(void * /* data */)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    51
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    52
#if 0
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    53
    /*
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    54
     * We don't actually free the storage since it's actually allocated
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    55
     * on the stack. Normally, this would not be the case and this is
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    56
     * the opportunity to free whatever.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    57
     */
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    58
    PR_Free(data);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    59
#endif
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    60
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    61
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    62
/// \brief Return the MIME Type description for this plugin.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    63
char*
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    64
NPP_GetMIMEDescription(void)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    65
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    66
    return const_cast<char *>(MIME_TYPES_DESCRIPTION);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    67
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    68
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    69
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    70
// general initialization and shutdown
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    71
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    72
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    73
/// \brief Initialize the plugin
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    74
///
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    75
/// This C++ function gets called once when the plugin is loaded,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    76
/// regardless of how many instantiations there is actually playing
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    77
/// movies. So this is where all the one time only initialization
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    78
/// stuff goes.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    79
NPError
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    80
NS_PluginInitialize()
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    81
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    82
    if ( plugInitialized )
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    83
    {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    84
        return NPERR_NO_ERROR;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    85
    }
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    86
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    87
    plugInitialized = TRUE;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    88
25
a7b0e40bcab0 Front IDILL :
bastiena
parents: 21
diff changeset
    89
	tuio_start(80);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    90
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    91
    return NPERR_NO_ERROR;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    92
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    93
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    94
/// \brief Shutdown the plugin
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    95
///
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    96
/// This C++ function gets called once when the plugin is being
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    97
/// shutdown, regardless of how many instantiations actually are
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    98
/// playing movies. So this is where all the one time only
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    99
/// shutdown stuff goes.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   100
void
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   101
NS_PluginShutdown()
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   102
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   103
#if 0
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   104
    if (!plugInitialized)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   105
    {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   106
#if GNASH_PLUGIN_DEBUG > 1
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   107
        std::cout << "Plugin already shut down" << std::endl;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   108
#endif
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   109
        return;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   110
    }
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   111
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   112
    plugInitialized = FALSE;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   113
#endif
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   114
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   115
	tuio_stop();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   116
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   117
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   118
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   119
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   120
/// \brief Retrieve values from the plugin for the Browser
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   121
///
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   122
/// This C++ function is called by the browser to get certain
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   123
/// information is needs from the plugin. This information is the
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   124
/// plugin name, a description, etc...
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   125
NPError
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   126
NS_PluginGetValue(NPPVariable aVariable, void *aValue)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   127
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   128
    NPError err = NPERR_NO_ERROR;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   129
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   130
    switch (aVariable)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   131
    {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   132
        case NPPVpluginNameString:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   133
            *static_cast<const char **> (aValue) = PLUGIN_NAME;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   134
            break;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   135
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   136
        // This becomes the description field you see below the opening
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   137
        // text when you type about:plugins and in
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   138
        // navigator.plugins["Shockwave Flash"].description, used in
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   139
        // many flash version detection scripts.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   140
        case NPPVpluginDescriptionString:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   141
            *static_cast<const char **>(aValue) = PLUGIN_DESCRIPTION;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   142
            break;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   143
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   144
        case NPPVpluginNeedsXEmbed:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   145
            *(int*)aValue = PR_TRUE;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   146
            break;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   147
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   148
        case NPPVpluginTimerInterval:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   149
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   150
        case NPPVpluginKeepLibraryInMemory:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   151
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   152
        default:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   153
            err = NPERR_INVALID_PARAM;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   154
            break;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   155
    }
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   156
    return err;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   157
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   158
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   159
/// \brief construct our plugin instance object
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   160
///
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   161
/// This instantiates a new object via a C++ function used by the
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   162
/// browser.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   163
nsPluginInstanceBase *
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   164
NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   165
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   166
    if(!aCreateDataStruct) return NULL;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   167
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   168
    return new nsPluginInstance(aCreateDataStruct);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   169
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   170
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   171
/// \brief destroy our plugin instance object
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   172
///
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   173
/// This destroys our instantiated object via a C++ function used by the
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   174
/// browser.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   175
void
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   176
NS_DestroyPluginInstance(nsPluginInstanceBase* aPlugin)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   177
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   178
    delete static_cast<nsPluginInstance *> (aPlugin);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   179
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   180
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   181
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   182
// nsPluginInstance class implementation
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   183
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   184
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   185
/// \brief Constructor
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   186
nsPluginInstance::nsPluginInstance(nsPluginCreateData* data)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   187
    :
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   188
    nsPluginInstanceBase(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   189
    _instance(data->instance),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   190
	_port(3333),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   191
	_callback("tuio_callback")
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   192
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   193
    for (size_t i=0, n=data->argc; i<n; ++i)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   194
    {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   195
        std::string name, val;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   196
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   197
        if (data->argn[i])
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   198
        {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   199
            name = data->argn[i];
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   200
        }
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   201
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   202
        if (data->argv[i])
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   203
        {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   204
            val = data->argv[i];
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   205
        }
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   206
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   207
        else if ( ! strstr(name.c_str(), "callback") )
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   208
        {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   209
            _callback = val;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   210
        }
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   211
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   212
        else if ( ! strstr(name.c_str(), "port") )
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   213
        {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   214
            _port = atoi(val.c_str());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   215
        }
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   216
    }
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   217
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   218
	instances.insert(this);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   219
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   220
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   221
/// \brief Destructor
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   222
nsPluginInstance::~nsPluginInstance()
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   223
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   224
	instances.erase(this);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   225
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   226
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   227
/// \brief Initialize an instance of the plugin object
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   228
/// 
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   229
/// This methods initializes the plugin object, and is called for
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   230
/// every movie that gets played. This is where the movie playing
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   231
/// specific initialization goes.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   232
NPBool
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   233
nsPluginInstance::init(NPWindow* aWindow)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   234
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   235
	D("[ns] init");
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   236
    return TRUE;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   237
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   238
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   239
/// \brief Shutdown an instantiated object
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   240
///
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   241
/// This shuts down an object, and is called for every movie that gets
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   242
/// played. This is where the movie playing specific shutdown code
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   243
/// goes.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   244
void
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   245
nsPluginInstance::shut()
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   246
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   247
	D("[ns] shut");
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   248
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   249
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   250
NPError
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   251
nsPluginInstance::SetWindow(NPWindow* aWindow)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   252
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   253
	D("[ns] SetWindow");
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   254
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   255
	if(!aWindow)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   256
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   257
		return NPERR_INVALID_PARAM;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   258
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   259
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   260
	return NPERR_NO_ERROR;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   261
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   262
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   263
NPError
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   264
nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   265
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   266
	return NS_PluginGetValue(aVariable, aValue);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   267
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   268
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   269
/// \brief Write a status message
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   270
///
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   271
/// This writes a status message to the status line at the bottom of
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   272
/// the browser window and the console firefox was started from.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   273
NPError
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   274
nsPluginInstance::WriteStatus(const char *msg) const
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   275
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   276
	NPN_Status(_instance, msg);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   277
	std::cout << msg << std::endl;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   278
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   279
	return NPERR_NO_ERROR;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   280
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   281
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   282
NPError
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   283
nsPluginInstance::NewStream(NPMIMEType /*type*/, NPStream* stream,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   284
                            NPBool /*seekable*/, uint16* /*stype*/)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   285
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   286
	D("[ns] NewStream");
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   287
	return NPERR_NO_ERROR;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   288
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   289
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   290
NPError
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   291
nsPluginInstance::DestroyStream(NPStream* /*stream*/, NPError /*reason*/)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   292
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   293
	D("[ns] DestroyStream");
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   294
	return NPERR_NO_ERROR;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   295
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   296
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   297
int32_t
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   298
nsPluginInstance::WriteReady(NPStream* /* stream */ )
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   299
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   300
	D("[ns] WriteReady");
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   301
	return 0x0fffffff;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   302
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   303
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   304
int32_t
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   305
nsPluginInstance::Write(NPStream* /*stream*/, int32_t /*offset*/, int32_t len,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   306
        void* buffer)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   307
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   308
	D("[ns] Write: len=" << len);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   309
	return len;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   310
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   311
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   312
typedef struct {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   313
	NPP instance;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   314
	TuioEventData data;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   315
} Event;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   316
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   317
void test(void* ev)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   318
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   319
	D("ev=" << ev);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   320
	Event* event = (Event*)ev;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   321
	D("event=" << event);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   322
	std::stringstream ss;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   323
	ss << "javascript:tuio_callback(";
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   324
	ss << event->data.type << ", ";
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   325
	ss << event->data.sid << ", ";
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   326
	ss << event->data.fid << ", ";
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   327
	ss << event->data.x << ", ";
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   328
	ss << event->data.y << ", ";
25
a7b0e40bcab0 Front IDILL :
bastiena
parents: 21
diff changeset
   329
	ss << event->data.z << ", ";
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   330
	ss << event->data.a << ");";
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   331
	NPN_GetURL(event->instance, ss.str().c_str(), "_self");
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   332
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   333
	delete event;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   334
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   335
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   336
void nsPluginInstance::event(TuioEventData data)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   337
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   338
	D("[event] callback: type=" << data.type
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   339
		<< ", sid=" << data.sid << ", fid=" << data.fid
25
a7b0e40bcab0 Front IDILL :
bastiena
parents: 21
diff changeset
   340
		<< ", x=" << data.x << ", y=" << data.y << ", z=" << data.z << ", a=" << data.a);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   341
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   342
	Event* ev = new Event();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   343
	ev->instance = _instance;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   344
	ev->data = data;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   345
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   346
	NPN_PluginThreadAsyncCall(_instance, test, ev);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   347
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   348
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   349
// Local Variables:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   350
// mode: C++
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   351
// indent-tabs-mode: t
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   352
// End: