143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
1 |
/*
|
2 |
Quick litte lack to generate the ordering ID.
|
|
3 |
||
4 |
Copyright 2010 Canonical Ltd.
|
|
5 |
||
6 |
Authors:
|
|
7 |
Ted Gould <ted@canonical.com>
|
|
8 |
||
9 |
This program is free software: you can redistribute it and/or modify it
|
|
10 |
under the terms of the GNU General Public License version 3, as published
|
|
11 |
by the Free Software Foundation.
|
|
12 |
||
13 |
This program is distributed in the hope that it will be useful, but
|
|
14 |
WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
15 |
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
16 |
PURPOSE. See the GNU General Public License for more details.
|
|
17 |
||
18 |
You should have received a copy of the GNU General Public License along
|
|
19 |
with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 |
*/
|
|
21 |
||
143.2.5
by Ted Gould
Brining generate-id into the fold |
22 |
#include "generate-id.h" |
23 |
||
143.2.28
by Ted Gould
Making the categories a case statement. |
24 |
#define MULTIPLIER 32
|
25 |
||
143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
26 |
guint32
|
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
27 |
generate_id (const AppIndicatorCategory catenum, const gchar * id) |
143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
28 |
{
|
225.1.1
by Charles Kerr
change local guint8 fields that get left-shifted to guint32 to prevent overflow, as reported by coverity in lp bug #944234 |
29 |
guint32 category = 0; |
30 |
guint32 first = 0; |
|
31 |
guint32 second = 0; |
|
32 |
guint32 third = 0; |
|
143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
33 |
|
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
34 |
switch (catenum) { |
143.2.28
by Ted Gould
Making the categories a case statement. |
35 |
case APP_INDICATOR_CATEGORY_OTHER: |
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
36 |
category = MULTIPLIER * 5; |
143.2.28
by Ted Gould
Making the categories a case statement. |
37 |
break; |
38 |
case APP_INDICATOR_CATEGORY_APPLICATION_STATUS: |
|
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
39 |
category = MULTIPLIER * 4; |
143.2.28
by Ted Gould
Making the categories a case statement. |
40 |
break; |
41 |
case APP_INDICATOR_CATEGORY_COMMUNICATIONS: |
|
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
42 |
category = MULTIPLIER * 3; |
143.2.28
by Ted Gould
Making the categories a case statement. |
43 |
break; |
44 |
case APP_INDICATOR_CATEGORY_SYSTEM_SERVICES: |
|
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
45 |
category = MULTIPLIER * 2; |
143.2.28
by Ted Gould
Making the categories a case statement. |
46 |
break; |
47 |
case APP_INDICATOR_CATEGORY_HARDWARE: |
|
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
48 |
category = MULTIPLIER * 1; |
143.2.28
by Ted Gould
Making the categories a case statement. |
49 |
break; |
50 |
default: |
|
51 |
g_warning("Got an undefined category: %d", category); |
|
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
52 |
category = 0; |
143.2.28
by Ted Gould
Making the categories a case statement. |
53 |
break; |
54 |
}
|
|
143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
55 |
|
56 |
if (id != NULL) { |
|
57 |
if (id[0] != '\0') { |
|
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
58 |
first = id[0]; |
143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
59 |
if (id[1] != '\0') { |
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
60 |
second = id[1]; |
143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
61 |
if (id[2] != '\0') { |
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
62 |
third = id[2]; |
143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
63 |
}
|
64 |
}
|
|
65 |
}
|
|
66 |
}
|
|
67 |
||
143.2.29
by Ted Gould
Instead of using a struct just using multiply, which in all reality, is more clear and the compiler will optimize it for us. |
68 |
return (((((category * 256) + first) * 256) + second) * 256) + third; |
143.2.4
by Ted Gould
Writing a small little function to generate the ID. |
69 |
}
|