Mir

Merge lp:~vanvugt/mir/mirout-save-load into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 4026
Proposed branch: lp:~vanvugt/mir/mirout-save-load
Merge into: lp:mir
Diff against target: 170 lines (+108/-5)
1 file modified
src/utils/out.c (+108/-5)
To merge this branch: bzr merge lp:~vanvugt/mir/mirout-save-load
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Approve
Cemil Azizoglu (community) Approve
Kevin DuBois (community) Needs Information
Daniel van Vugt Abstain
Review via email: mp+316676@code.launchpad.net

Commit message

mirout: Add load and save options for keeping display configs
on disk.

Description of the change

The intention was to try and reproduce bug 1661295, but no luck yet.

Still a nice feature to have...

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:4019
https://mir-jenkins.ubuntu.com/job/mir-ci/2952/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/3912
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3998
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3988
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3988
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/3988
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3939
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3939/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3939
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3939/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3939
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3939/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3939
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3939/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3939
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3939/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3939
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3939/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2952/rebuild

review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Got a better idea...

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) :
review: Abstain
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:4022
https://mir-jenkins.ubuntu.com/job/mir-ci/2960/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/3928
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4014
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/4004
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/4004
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4004
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3955
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3955/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3955
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3955/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3955
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3955/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3955
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3955/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3955
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3955/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3955
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3955/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2960/rebuild

review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

alright as is, although I've forgotten why we need MirBlob as part of the client api at all. Seems it would be be better for this client to come up with its own data format (csv? xml?) than rely on mirblob.

Suppose, needs discussion on that point, otherwise lgtm

review: Needs Information
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I wondered that myself. Why does MirBlob exist?...

MirBlob has one benefit in that it is a single object with data and length fields. If MirBlob did not exist then the only real alternative is to pass around two variables instead:
   void *data;
   size_t size;
Which is basically what MirBlob is.

Your question however is also around data formats. That's a different question and the answer is that MirBlob is not a data format. The data format of the files here is from the Protobuf serialization function:
   https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message_lite#MessageLite.SerializeWithCachedSizes

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> alright as is, although I've forgotten why we need MirBlob as part of the
> client api at all. Seems it would be be better for this client to come up with
> its own data format (csv? xml?) than rely on mirblob.
>
> Suppose, needs discussion on that point, otherwise lgtm

The requirement comes from a compromise at a sprint a couple of years ago.

Downstream didn't want to deal with tracking any changes to the display configuration information or backward compatibility for the serialized form. So we had to provided one.

Despite the urgency and shouting I don't think they ever got around to using it. So we could probably drop it for 1.0.

Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Ok by me

review: Approve
Revision history for this message
Kevin DuBois (kdub) wrote :

> Despite the urgency and shouting I don't think they ever got around to using
> it. So we could probably drop it for 1.0.

Sure, would be fine by me as well.

Revision history for this message
Kevin DuBois (kdub) wrote :

> I wondered that myself. Why does MirBlob exist?...
>
> MirBlob has one benefit in that it is a single object with data and length
> fields. If MirBlob did not exist then the only real alternative is to pass
> around two variables instead:
> void *data;
> size_t size;
> Which is basically what MirBlob is.
>
> Your question however is also around data formats. That's a different question
> and the answer is that MirBlob is not a data format. The data format of the
> files here is from the Protobuf serialization function:
> https://developers.google.com/protocol-buffers/docs/reference/cpp/google.pr
> otobuf.message_lite#MessageLite.SerializeWithCachedSizes

Well, its more of compatibility of the file this utility produces.

If a user produces a file with this utility against mir 1.0.0
Then we change the internal structure of MirBlob in mir 1.x (as the internal structure isn't mirclient abi, this is something we could do)
Then the user tries to load the file with the mir 1.x utility, seems that this has a chance for breakage.

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/1090/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/3960/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/1151/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4046
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/4036
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/4036
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4036
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3987/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3987
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3987/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3987/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3987
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3987/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3987
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3987/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3987/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

^^^
Ongoing network/infrastructure problems today. But also bug 1646375.

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/1092/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/3962/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/1153/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4048
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/4038
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/4038
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4038
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3989/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3989
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3989/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3989/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3989
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3989/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3989
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3989/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3989
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3989/artifact/output/*zip*/output.zip

review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

^^^
More network failures

Revision history for this message
Mir CI Bot (mir-ci-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/utils/out.c'
2--- src/utils/out.c 2017-01-18 02:29:37 +0000
3+++ src/utils/out.c 2017-02-09 07:47:02 +0000
4@@ -17,10 +17,12 @@
5 */
6
7 #include "mir_toolkit/mir_client_library.h"
8+#include "mir_toolkit/mir_blob.h"
9 #include <stdio.h>
10 #include <math.h>
11 #include <string.h>
12 #include <stdbool.h>
13+#include <stdlib.h>
14
15 static const char *power_mode_name(MirPowerMode m)
16 {
17@@ -88,6 +90,79 @@
18 : "out-of-range";
19 }
20
21+static bool save(MirDisplayConfig* conf, char const* path)
22+{
23+ MirBlob* blob = mir_blob_from_display_config(conf);
24+ if (!blob)
25+ {
26+ fprintf(stderr, "mir_blob_from_display_config failed\n");
27+ return false;
28+ }
29+ bool ret = false;
30+ FILE* file = !strcmp(path, "-") ? stdout : fopen(path, "wb");
31+ if (!file)
32+ {
33+ perror("save:fopen");
34+ }
35+ else
36+ {
37+ if (1 == fwrite(mir_blob_data(blob), mir_blob_size(blob), 1, file))
38+ ret = true;
39+ else
40+ perror("save:fwrite");
41+
42+ if (file != stdout)
43+ fclose(file);
44+ }
45+ mir_blob_release(blob);
46+ return ret;
47+}
48+
49+static MirDisplayConfig* load(char const* path)
50+{
51+ MirDisplayConfig* conf = NULL;
52+ FILE* file = !strcmp(path, "-") ? stdin : fopen(path, "rb");
53+ if (!file)
54+ {
55+ perror("load:fopen");
56+ }
57+ else
58+ {
59+ fseek(file, 0, SEEK_END);
60+ long size = ftell(file);
61+ fseek(file, 0, SEEK_SET);
62+ void* data = malloc(size);
63+ if (!data)
64+ {
65+ perror("load:malloc");
66+ }
67+ else
68+ {
69+ if (1 != fread(data, size, 1, file))
70+ {
71+ perror("load:fread");
72+ }
73+ else
74+ {
75+ MirBlob* blob = mir_blob_onto_buffer(data, size);
76+ if (!blob)
77+ {
78+ fprintf(stderr, "mir_blob_onto_buffer failed with %ld bytes\n", size);
79+ }
80+ else
81+ {
82+ conf = mir_blob_to_display_config(blob);
83+ mir_blob_release(blob);
84+ }
85+ }
86+ free(data);
87+ }
88+ if (file != stdin)
89+ fclose(file);
90+ }
91+ return conf;
92+}
93+
94 static bool modify(MirDisplayConfig* conf, int actionc, char** actionv)
95 {
96 int const max_targets = 256;
97@@ -332,6 +407,8 @@
98 int main(int argc, char *argv[])
99 {
100 char const* server = NULL;
101+ char const* infile = NULL;
102+ char const* outfile = NULL;
103 char** actionv = NULL;
104 int actionc = 0;
105 bool verbose = false;
106@@ -349,13 +426,33 @@
107 case 'v':
108 verbose = true;
109 break;
110+ case 'i':
111+ ++a;
112+ if (a >= argc)
113+ {
114+ fprintf(stderr, "%s requires a file path\n", arg);
115+ return 1;
116+ }
117+ infile = argv[a];
118+ break;
119+ case 'o':
120+ ++a;
121+ if (a >= argc)
122+ {
123+ fprintf(stderr, "%s requires a file path\n", arg);
124+ return 1;
125+ }
126+ outfile = argv[a];
127+ break;
128 case 'h':
129 default:
130 printf("Usage: %s [OPTIONS] [/path/to/mir/socket] [[output OUTPUTID] ACTION ...]\n"
131 "Options:\n"
132- " -h Show this help information.\n"
133- " -v Show verbose information.\n"
134- " -- Ignore the rest of the command line.\n"
135+ " -h Show this help information.\n"
136+ " -i PATH Load display configuration from a file instead of the server.\n"
137+ " -o PATH Save resulting configuration to a file.\n"
138+ " -v Show verbose information.\n"
139+ " -- Ignore the rest of the command line.\n"
140 "Actions:\n"
141 " off | suspend | standby | on\n"
142 " disable | enable\n"
143@@ -387,12 +484,13 @@
144 }
145
146 int ret = 0;
147- MirDisplayConfig* conf = mir_connection_create_display_configuration(conn);
148+ MirDisplayConfig* conf = infile ? load(infile) :
149+ mir_connection_create_display_configuration(conn);
150 if (conf == NULL)
151 {
152 fprintf(stderr, "Failed to get display configuration (!?)\n");
153 }
154- else if (actionc)
155+ else if (actionc || infile)
156 {
157 if (modify(conf, actionc, actionv))
158 {
159@@ -520,7 +618,12 @@
160 if (num_modes)
161 printf("\n");
162 }
163+ }
164
165+ if (conf)
166+ {
167+ if (outfile && !ret)
168+ ret = save(conf, outfile) ? 0 : 1;
169 mir_display_config_release(conf);
170 }
171

Subscribers

People subscribed via source and target branches