~fboucault/platform-api/crossbuild_fixes

« back to all changes in this revision

Viewing changes to android/hybris/test_session_c_api.cpp

  • Committer: CI Train Bot
  • Author(s): Alberto Aguirre, Robert Carr, robert.carr at canonical
  • Date: 2015-07-06 17:52:56 UTC
  • mfrom: (300.1.16 delete-deprecations)
  • Revision ID: ci-train-bot@canonical.com-20150706175256-a7bzbvy0sfifa0fm
Delete deprecated mir functions.

Why now? https://code.launchpad.net/~mir-team/mir/privatize-event/+merge/254149

The old mir-event is being made private and the new event does not have many fields corresponding to legacy in the UbuntuEvent (i.e. "is_system_key"). Thus it seems like rather than update unused code (qtubuntu is already ported) to build but be broken its a good time to delete it all.

Update major version to 3.
Approved by: PS Jenkins bot, Ricardo Mendoza, Gerry Boland, Alberto Aguirre

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2012 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License version 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17
 
 */
18
 
 
19
 
#include <ubuntu/ui/ubuntu_ui_session_service.h>
20
 
 
21
 
#include <getopt.h>
22
 
 
23
 
#include <stdio.h>
24
 
#include <stdint.h>
25
 
#include <string.h>
26
 
#include <time.h>
27
 
 
28
 
typedef union
29
 
{
30
 
    struct Components
31
 
    {
32
 
        uint8_t r;
33
 
        uint8_t g;
34
 
        uint8_t b;
35
 
        uint8_t a;
36
 
    } components;
37
 
    uint32_t value;
38
 
} Pixel;
39
 
 
40
 
struct Config
41
 
{
42
 
    Config() : take_screencast_flag(0),
43
 
               take_screenshot_flag(0)
44
 
    {
45
 
    }
46
 
    
47
 
    int take_screencast_flag;
48
 
    int take_screenshot_flag;
49
 
};
50
 
 
51
 
void on_snapshot_completed(const void* pixel_data, unsigned int width, unsigned int height, unsigned int x, unsigned int y, unsigned int source_width, unsigned int source_height, unsigned int stride, void* context)
52
 
{
53
 
    static unsigned int counter = 0;
54
 
    
55
 
    printf("%s: (%p, %d, %d, %d) \n",
56
 
           __PRETTY_FUNCTION__,
57
 
           pixel_data,
58
 
           width,
59
 
           height,
60
 
           stride);
61
 
 
62
 
    static const char snapshot_pattern[] = "./snapshot_%I_%M_%S.ppm";
63
 
    static const char frame_pattern[] = "./frame_%I_%M_%S.raw";
64
 
  
65
 
    char fn[256];
66
 
 
67
 
    int take_screenshot = 1;
68
 
    int take_screencast = 0;
69
 
 
70
 
    if (context != NULL)
71
 
    {
72
 
        Config* config = (Config*) context;
73
 
 
74
 
        take_screenshot = config->take_screenshot_flag;
75
 
        take_screencast = config->take_screencast_flag;
76
 
    }
77
 
    
78
 
    time_t curtime;
79
 
    struct tm *loctime;
80
 
    
81
 
    curtime = time (NULL);        
82
 
    loctime = localtime (&curtime);    
83
 
    
84
 
    static const char screenshot_file_mode[] = "w+";
85
 
    static const char screencast_file_mode[] = "wb+";
86
 
    
87
 
    FILE* f = NULL;
88
 
    if (take_screenshot)
89
 
    {
90
 
        strftime(fn, 256, snapshot_pattern, loctime);
91
 
        f = fopen(fn, screenshot_file_mode);
92
 
    } else if (take_screencast)
93
 
    {
94
 
        strftime(fn, 256, frame_pattern, loctime);
95
 
        f = fopen(fn, screencast_file_mode);
96
 
    }
97
 
 
98
 
    if (!f)
99
 
    {
100
 
        printf("Problem opening file: %s \n", fn);
101
 
        return;
102
 
    }
103
 
     
104
 
    if (take_screenshot)
105
 
    {
106
 
        const unsigned int* p = static_cast<const unsigned int*>(pixel_data);
107
 
        
108
 
        fprintf(f, "P3\n%d %d\n%d\n\n", width, height, 255);
109
 
        for(unsigned int i = 0; i < height; i++)
110
 
        {
111
 
            for(unsigned int j = 0; j < width; j++)
112
 
            {
113
 
                Pixel pixel; pixel.value = *p; ++p;
114
 
                fprintf(
115
 
                    f, "%d %d %d\t", 
116
 
                    pixel.components.r,
117
 
                    pixel.components.g,
118
 
                    pixel.components.b);
119
 
            }
120
 
        }
121
 
    }
122
 
    else if (take_screencast)
123
 
    {
124
 
        fwrite(pixel_data, sizeof(unsigned int), width*height, f);
125
 
        ubuntu_ui_session_snapshot_running_session_with_id(
126
 
            -1,
127
 
            on_snapshot_completed,
128
 
            context);
129
 
    }
130
 
}
131
 
 
132
 
void on_session_born(ubuntu_ui_session_properties props, void*)
133
 
{
134
 
    printf("%s:\n\t Id: %d \n\t Desktop file hint: %s \n",
135
 
           __PRETTY_FUNCTION__,
136
 
           ubuntu_ui_session_properties_get_application_instance_id(props),
137
 
           ubuntu_ui_session_properties_get_desktop_file_hint(props));
138
 
 
139
 
    ubuntu_ui_session_snapshot_running_session_with_id(
140
 
        ubuntu_ui_session_properties_get_application_instance_id(props),
141
 
        on_snapshot_completed,
142
 
        NULL);
143
 
}
144
 
 
145
 
void on_session_focused(ubuntu_ui_session_properties props, void*)
146
 
{
147
 
    printf("%s:\n\t Id: %d \n\t Desktop file hint: %s \n",
148
 
           __PRETTY_FUNCTION__,
149
 
           ubuntu_ui_session_properties_get_application_instance_id(props),
150
 
           ubuntu_ui_session_properties_get_desktop_file_hint(props));
151
 
}
152
 
 
153
 
void on_session_died(ubuntu_ui_session_properties props, void*)
154
 
{
155
 
    printf("%s:\n\t Id: %d \n\t Desktop file hint: %s \n",
156
 
           __PRETTY_FUNCTION__,
157
 
           ubuntu_ui_session_properties_get_application_instance_id(props),
158
 
           ubuntu_ui_session_properties_get_desktop_file_hint(props));
159
 
}
160
 
 
161
 
 
162
 
 
163
 
Config parse_cmd_line(int argc, char** argv)
164
 
{
165
 
    Config config;
166
 
    static struct option long_options[] = {
167
 
        {"take-screencast", no_argument, &config.take_screencast_flag, 1},
168
 
        {"take-screenshot", no_argument, &config.take_screenshot_flag, 1}
169
 
    };
170
 
 
171
 
    while (true)
172
 
    {
173
 
        int option_index = 0;
174
 
        
175
 
        int c = getopt_long(
176
 
            argc, 
177
 
            argv, 
178
 
            "",
179
 
            long_options, 
180
 
            &option_index);
181
 
 
182
 
        if (c == -1)
183
 
            break;
184
 
 
185
 
        switch (c)
186
 
        {
187
 
            case 0:
188
 
                // No need to do anything here: Flag is set automatically.
189
 
                break;
190
 
            default:
191
 
                break;
192
 
        }
193
 
    }
194
 
 
195
 
    return config;
196
 
}
197
 
 
198
 
int main(int argc, char** argv)
199
 
{
200
 
    static const int complete_session_id = -1;
201
 
 
202
 
    Config config = parse_cmd_line(argc, argv);
203
 
 
204
 
    if (config.take_screenshot_flag || config.take_screencast_flag)
205
 
    {
206
 
        ubuntu_ui_session_snapshot_running_session_with_id(
207
 
            complete_session_id,
208
 
            on_snapshot_completed,
209
 
            &config);
210
 
 
211
 
        return 0;
212
 
    }
213
 
 
214
 
    ubuntu_ui_session_lifecycle_observer observer;
215
 
 
216
 
    memset(&observer, 0, sizeof(observer));
217
 
    observer.on_session_born = on_session_born;
218
 
    observer.on_session_focused = on_session_focused;
219
 
    observer.on_session_died = on_session_died;
220
 
 
221
 
    ubuntu_ui_session_install_session_lifecycle_observer(&observer);
222
 
 
223
 
    while(true)
224
 
    {
225
 
    }
226
 
 
227
 
    return 0;
228
 
}
229