This URL has Read-Only access.

Statistics
| Branch: | Tag: | Revision:

root / src / spin / libloUtil.cpp @ 9d70071e

History | View | Annotate | Download (3.9 kB)

1
// -----------------------------------------------------------------------------
2
// |    ___  ___  _  _ _     ___                                        _      |
3
// |   / __>| . \| || \ |   | __>_ _  ___ ._ _ _  ___  _ _ _  ___  _ _ | |__   |
4
// |   \__ \|  _/| ||   |   | _>| '_><_> || ' ' |/ ._>| | | |/ . \| '_>| / /   |
5
// |   <___/|_|  |_||_\_|   |_| |_|  <___||_|_|_|\___.|__/_/ \___/|_|  |_\_\   |
6
// |                                                                           |
7
// |---------------------------------------------------------------------------|
8
//
9
// http://spinframework.sourceforge.net
10
// Copyright (C) 2009 Mike Wozniewski, Zack Settel
11
//
12
// Developed/Maintained by:
13
//    Mike Wozniewski (http://www.mikewoz.com)
14
//    Zack Settel (http://www.sheefa.net/zack)
15
// 
16
// Principle Partners:
17
//    Shared Reality Lab, McGill University (http://www.cim.mcgill.ca/sre)
18
//    La Societe des Arts Technologiques (http://www.sat.qc.ca)
19
//
20
// Funding by:
21
//    NSERC/Canada Council for the Arts - New Media Initiative
22
//    Heritage Canada
23
//    Ministere du Developpement economique, de l'Innovation et de l'Exportation
24
//
25
// -----------------------------------------------------------------------------
26
//  This file is part of the SPIN Framework.
27
//
28
//  SPIN Framework is free software: you can redistribute it and/or modify
29
//  it under the terms of the GNU Lesser General Public License as published by
30
//  the Free Software Foundation, either version 3 of the License, or
31
//  (at your option) any later version.
32
//
33
//  SPIN Framework is distributed in the hope that it will be useful,
34
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
35
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36
//  GNU Lesser General Public License for more details.
37
//
38
//  You should have received a copy of the GNU Lesser General Public License
39
//  along with SPIN Framework. If not, see <http://www.gnu.org/licenses/>.
40
// -----------------------------------------------------------------------------
41

    
42
#include "libloUtil.h"
43
#include <string.h>
44
#include <string>
45

    
46
void lo_server_del_method_with_userdata(lo_server lo_serv, const char *path, const char *typespec, void *userdata)
47
{
48
    internal_lo_server s = (internal_lo_server) (lo_serv);
49
    int pattern = 0;
50

    
51
    if (path)
52
    {
53
        if (strpbrk(path, " #*,?[]{}") != 0)
54
            pattern = 1;
55
        else
56
            pattern = 0;
57
    }
58

    
59
    if (! s->first)
60
    {
61
    // The server has no registered callbacks, so nothing to be done
62
        return;
63
    }
64

    
65
    internal_lo_method it, prev, next;
66
    it = (internal_lo_method) s->first;
67
    prev = it;
68

    
69
    while (it)
70
    {
71
        // in case we free it:
72
        next = it->next;
73

    
74
        // If paths match or handler is wildcard:
75
        if ((it->path == path) ||
76
            (path && it->path && !strcmp(path, it->path)) ||
77
            (pattern && it->path && lo_pattern_match(it->path, path))) {
78

    
79
            // If types match or handler is wildcard:
80
            if ((it->typespec == typespec) || (typespec && it->typespec && !strcmp(typespec, it->typespec)))
81
            {
82
                // If the user_data points to the user data provided:
83
                if (it->user_data == (char*)userdata)
84
                {
85
                    // Take care when removing the head:
86
                    if (it == s->first)
87
                    {
88
                        s->first = it->next;
89
                    }
90
                    else
91
                    {
92
                        prev->next = it->next;
93
                    }
94
                    next = it->next;
95
                    free((char *)it->path);
96
                    free((char *)it->typespec);
97
                    free(it);
98
                    it = prev;
99
                }
100
            }
101
        }
102
        prev = it;
103
        if (it)
104
            it = next;
105
    }
106

    
107
    // if no remaining methods are registered, we could return a message or
108
    // destroy the server... TODO?
109
    if (! s->first)
110
    {
111
        // TODO
112
    }
113
}
114