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