~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to extern/verse/dist/v_func_storage.c

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * 
 
3
*/
 
4
 
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
#include "verse_header.h"
 
8
#include "v_pack.h"
 
9
#include "v_cmd_gen.h"
 
10
#include "v_connection.h"
 
11
#if !defined(V_GENERATE_FUNC_MODE)
 
12
#include "verse.h"
 
13
#include "v_cmd_buf.h"
 
14
#include "v_network_out_que.h"
 
15
 
 
16
#define V_FS_MAX_CMDS   256
 
17
 
 
18
extern void init_pack_and_unpack(void);
 
19
 
 
20
static struct {
 
21
        unsigned int    (*unpack_func[V_FS_MAX_CMDS])(const char *data, size_t length);
 
22
        void            *pack_func[V_FS_MAX_CMDS];
 
23
        void            *user_func[V_FS_MAX_CMDS];
 
24
        void            *user_data[V_FS_MAX_CMDS];
 
25
        void            *alias_pack_func[V_FS_MAX_CMDS];
 
26
        void            *alias_user_func[V_FS_MAX_CMDS];
 
27
        void            *alias_user_data[V_FS_MAX_CMDS];
 
28
        boolean         call;
 
29
} VCmdData;
 
30
 
 
31
static boolean v_fs_initialized = FALSE;
 
32
 
 
33
extern void verse_send_packet_ack(uint32 packet_id);
 
34
extern void callback_send_packet_ack(void *user, uint32 packet_id);
 
35
extern void verse_send_packet_nak(uint32 packet_id);
 
36
extern void callback_send_packet_nak(void *user, uint32 packet_id);
 
37
 
 
38
void v_fs_init(void)
 
39
{
 
40
        unsigned int i;
 
41
        if(v_fs_initialized)
 
42
                return;
 
43
        for(i = 0; i < V_FS_MAX_CMDS; i++)
 
44
        {
 
45
                VCmdData.unpack_func[i] = NULL;
 
46
                VCmdData.pack_func[i] = NULL;
 
47
                VCmdData.user_func[i] = NULL;
 
48
                VCmdData.user_data[i] = NULL;
 
49
                VCmdData.alias_pack_func[i] = NULL;
 
50
                VCmdData.alias_user_func[i] = NULL;
 
51
                VCmdData.alias_user_data[i] = NULL;
 
52
        }
 
53
        #if !defined(V_GENERATE_FUNC_MODE)
 
54
        init_pack_and_unpack();
 
55
        #endif
 
56
        for(i = 0; i < V_FS_MAX_CMDS && VCmdData.pack_func[i] != verse_send_packet_ack; i++);
 
57
        VCmdData.user_func[i] = callback_send_packet_ack;
 
58
        for(i = 0; i < V_FS_MAX_CMDS && VCmdData.pack_func[i] != verse_send_packet_nak; i++);
 
59
        VCmdData.user_func[i] = callback_send_packet_nak;
 
60
 
 
61
        v_fs_initialized = TRUE;
 
62
}
 
63
 
 
64
 
 
65
void v_fs_add_func(unsigned int cmd_id, unsigned int (*unpack_func)(const char *data, size_t length), void *pack_func, void *alias_func)
 
66
{
 
67
        VCmdData.unpack_func[cmd_id] = unpack_func;
 
68
        VCmdData.pack_func[cmd_id] = pack_func;
 
69
        VCmdData.alias_pack_func[cmd_id] = alias_func;
 
70
}
 
71
 
 
72
void *v_fs_get_user_func(unsigned int cmd_id)
 
73
{
 
74
/*      if(VCmdData.call)*/
 
75
                return VCmdData.user_func[cmd_id];
 
76
        return NULL;
 
77
}
 
78
 
 
79
void *v_fs_get_user_data(unsigned int cmd_id)
 
80
{
 
81
        return VCmdData.user_data[cmd_id];
 
82
}
 
83
 
 
84
void *v_fs_get_alias_user_func(unsigned int cmd_id)
 
85
{
 
86
/*      if(VCmdData.call)*/
 
87
                return VCmdData.alias_user_func[cmd_id];
 
88
        return NULL;
 
89
}
 
90
 
 
91
void *v_fs_get_alias_user_data(unsigned int cmd_id)
 
92
{
 
93
        return VCmdData.alias_user_data[cmd_id];
 
94
}
 
95
 
 
96
void verse_callback_set(void *command, void *callback, void *user)
 
97
{
 
98
        unsigned int i;
 
99
        if(!v_fs_initialized)
 
100
                v_fs_init();
 
101
 
 
102
        for(i = 0; i < V_FS_MAX_CMDS; i++)
 
103
        {
 
104
                if(VCmdData.pack_func[i] == command)
 
105
                {
 
106
                        VCmdData.user_data[i] = user;
 
107
                        VCmdData.user_func[i] = callback;
 
108
                        return;
 
109
                }
 
110
                if(VCmdData.alias_pack_func[i] == command)
 
111
                {
 
112
                        VCmdData.alias_user_data[i] = user;
 
113
                        VCmdData.alias_user_func[i] = callback;
 
114
                        return;
 
115
                }
 
116
        }
 
117
}
 
118
 
 
119
/* Do we accept incoming connections, i.e. are we a host implementation? */
 
120
boolean v_fs_func_accept_connections(void)
 
121
{
 
122
        return VCmdData.user_func[0] != NULL;
 
123
}
 
124
 
 
125
/* Inspect beginning of packet, looking for ACK or NAK commands. */
 
126
void v_fs_unpack_beginning(const uint8 *data, unsigned int length)
 
127
{
 
128
        uint32 id, i = 4;
 
129
        uint8 cmd_id;
 
130
 
 
131
        i += vnp_raw_unpack_uint8(&data[i], &cmd_id);
 
132
        while(i < length && (cmd_id == 7 || cmd_id == 8))
 
133
        {
 
134
                i += vnp_raw_unpack_uint32(&data[i], &id);
 
135
                if(cmd_id == 7)
 
136
                        callback_send_packet_ack(NULL, id);
 
137
                else
 
138
                        callback_send_packet_nak(NULL, id);
 
139
                i += vnp_raw_unpack_uint8(&data[i], &cmd_id);
 
140
        }
 
141
}
 
142
 
 
143
void v_fs_unpack(uint8 *data, unsigned int length)
 
144
{
 
145
        uint32 i, output, pack_id;
 
146
        uint8 cmd_id, last = 255;
 
147
 
 
148
        i = vnp_raw_unpack_uint32(data, &pack_id); /* each packet starts with a 32 bit id */
 
149
        vnp_raw_unpack_uint8(&data[i], &cmd_id);
 
150
        while(i < length && (cmd_id == 7 || cmd_id == 8))
 
151
        {
 
152
                i += 5;
 
153
                vnp_raw_unpack_uint8(&data[i], &cmd_id);
 
154
        }
 
155
        while(i < length)
 
156
        {
 
157
                i += vnp_raw_unpack_uint8(&data[i], &cmd_id);
 
158
                if(VCmdData.unpack_func[cmd_id] != NULL)
 
159
                {
 
160
                        VCmdData.call = TRUE;
 
161
                        output = VCmdData.unpack_func[cmd_id](&data[i], length - i);
 
162
                        if(output == (unsigned int) -1) /* Can this happen? Should be size_t or int, depending. */
 
163
                        {
 
164
                                printf("** Aborting decode, command %u unpacker returned failure\n", cmd_id);
 
165
/*                              verse_send_packet_nak(pack_id);*/
 
166
                                return;
 
167
                        }
 
168
                        last = cmd_id;
 
169
                        i += output;
 
170
                }
 
171
                else    /* If unknown command byte was found, complain loudly and stop parsing packet. */
 
172
                {
 
173
                        size_t  j;
 
174
 
 
175
                        printf("\n** Unknown command ID %u (0x%02X) encountered--aborting packet decode len=%u pos=%u last=%u\n", cmd_id, cmd_id, length, i, last);
 
176
                        printf(" decoded %u bytes: ", --i);
 
177
                        for(j = 0; j < i; j++)
 
178
                                printf("%02X ", data[j]);
 
179
                        printf("\n (packet id=%u)", pack_id);
 
180
                        printf(" remaining %u bytes: ", length - i);
 
181
                        for(j = i; j < length; j++)
 
182
                                printf("%02X ", data[j]);
 
183
                        printf("\n");
 
184
/*                      *(char *) 0 = 0;*/
 
185
                        break;
 
186
                }
 
187
        }
 
188
/*      if(expected != NULL)
 
189
                verse_send_packet_ack(pack_id);*/
 
190
}
 
191
 
 
192
extern unsigned int v_unpack_connection(const char *data, size_t length);
 
193
 
 
194
#endif