Markdown使用 帮助


匿名


| 进程 | 第一次用时 | 第二次用时 | 第三次用时 |
| :-: | :-:  | :-:   | :-:  |
| 总计 | 10.68283712s | 10.71080211s | 10.33419029s |
| kwin_no_scale | 2.67882977s | 3.02675903s | 3.07661577s |
| dde-session-daemon | 950.63994ms | 601.67422ms | 748.44884ms |
| dde-dock | 705.80744ms | 1.30325458s | 959.24437ms |
| dde-desktop | 2.21790801s | 2.4759774s | 2.47460854s |
| dde-session-daemon part2 | 3.10374696s | 2.7527526s | 2.36620808s |
| startdde | 1.02590504s | 550.38428ms | 709.06469ms |

匿名

log1

```
2020年06月04日 星期四 10时41分15秒 850598576ns
6月 04 10:41:16 demo-PC startdde[2183]: main.go:80: startdde start on :  2020-06-04 10:41:16.096826816 +0800 CST m=+0.095012551
6月 04 10:41:16 demo-PC startdde[2183]: main.go:117: In wayland mode: false
6月 04 10:41:18 demo-PC startdde[2183]: sound_effect.go:64: key "autologin-user" not found
6月 04 10:41:19 demo-PC startdde[2183]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE kwin_no_scale] startup duration: 2.67882977s
6月 04 10:41:19 demo-PC startdde[2183]: startmanager.go:97: open /usr/lib/UIAppSched.hooks/launched: no such file or directory
6月 04 10:41:20 demo-PC startdde[2183]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/lib/deepin-daemon/dde-session-daemon] startup duration: 950.63994ms
6月 04 10:41:21 demo-PC startdde[2183]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/bin/dde-dock] startup duration: 705.80744ms
6月 04 10:41:23 demo-PC startdde[2183]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/bin/dde-desktop] startup duration: 2.21790801s
6月 04 10:41:26 demo-PC startdde[2183]: session_process.go:59: start dde-session-daemon part2 cost: 3.10374696s
6月 04 10:41:26 demo-PC startdde[2183]: main.go:154: iowait disabled
6月 04 10:41:26 demo-PC startdde[2183]: main.go:157: startdde total cost: 10.68283712s
```

log2

```
-- Logs begin at Thu 2020-06-04 10:06:46 CST, end at Thu 2020-06-04 10:48:54 CST. --
6月 04 10:48:05 demo-PC startdde[2182]: main.go:80: startdde start on :  2020-06-04 10:48:05.100126101 +0800 CST m=+0.070787631
6月 04 10:48:05 demo-PC startdde[2182]: main.go:117: In wayland mode: false
6月 04 10:48:07 demo-PC startdde[2182]: sound_effect.go:64: key "autologin-user" not found
6月 04 10:48:08 demo-PC startdde[2182]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE kwin_no_scale] startup duration: 3.02675903s
6月 04 10:48:08 demo-PC startdde[2182]: startmanager.go:97: open /usr/lib/UIAppSched.hooks/launched: no such file or directory
6月 04 10:48:09 demo-PC startdde[2182]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/lib/deepin-daemon/dde-session-daemon] startup duration: 601.67422ms
6月 04 10:48:10 demo-PC startdde[2182]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/bin/dde-dock] startup duration: 1.30325458s
6月 04 10:48:13 demo-PC startdde[2182]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/bin/dde-desktop] startup duration: 2.4759774s
6月 04 10:48:15 demo-PC startdde[2182]: session_process.go:59: start dde-session-daemon part2 cost: 2.7527526s
6月 04 10:48:15 demo-PC startdde[2182]: main.go:154: iowait disabled
6月 04 10:48:15 demo-PC startdde[2182]: main.go:157: startdde total cost: 10.71080211s
```

log3

```
2020年06月04日 星期四 10时52分25秒 937351765ns
6月 04 10:52:26 demo-PC startdde[2211]: main.go:80: startdde start on :  2020-06-04 10:52:26.172086735 +0800 CST m=+0.105281241
6月 04 10:52:26 demo-PC startdde[2211]: main.go:117: In wayland mode: false
6月 04 10:52:28 demo-PC startdde[2211]: sound_effect.go:64: key "autologin-user" not found
6月 04 10:52:29 demo-PC startdde[2211]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE kwin_no_scale] startup duration: 3.07661577s
6月 04 10:52:29 demo-PC startdde[2211]: startmanager.go:97: open /usr/lib/UIAppSched.hooks/launched: no such file or directory
6月 04 10:52:30 demo-PC startdde[2211]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/lib/deepin-daemon/dde-session-daemon] startup duration: 748.44884ms
6月 04 10:52:31 demo-PC startdde[2211]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/bin/dde-dock] startup duration: 959.24437ms
6月 04 10:52:34 demo-PC startdde[2211]: session_process.go:104: /usr/bin/cgexec [-g memory:2@dde/DE /usr/bin/dde-desktop] startup duration: 2.47460854s
6月 04 10:52:36 demo-PC startdde[2211]: session_process.go:59: start dde-session-daemon part2 cost: 2.36620808s
6月 04 10:52:36 demo-PC startdde[2211]: main.go:154: iowait disabled
6月 04 10:52:36 demo-PC startdde[2211]: main.go:157: startdde total cost: 10.33419029s

```

匿名

usage:
  

  
Produce output in the specified format.
  

  
   pprof <format> [options] [binary] <source> ...
  

  
Omit the format to get an interactive shell whose commands can be used
  
to generate various views of a profile
  

  
   pprof [options] [binary] <source> ...
  

  
Omit the format and provide the "-http" flag to get an interactive web
  
interface at the specified host:port that can be used to navigate through
  
various views of a profile.
  

  
   pprof -http [host]:[port] [options] [binary] <source> ...
  

  
Details:
  
  Output formats (select at most one):
  
    -callgrind       Outputs a graph in callgrind format
  
    -comments        Output all profile comments
  
    -disasm          Output assembly listings annotated with samples
  
    -dot             Outputs a graph in DOT format
  
    -eog             Visualize graph through eog
  
    -evince          Visualize graph through evince
  
    -gif             Outputs a graph image in GIF format
  
    -gv              Visualize graph through gv
  
    -kcachegrind     Visualize report in KCachegrind
  
    -list            Output annotated source for functions matching regexp
  
    -pdf             Outputs a graph in PDF format
  
    -peek            Output callers/callees of functions matching regexp
  
    -png             Outputs a graph image in PNG format
  
    -proto           Outputs the profile in compressed protobuf format
  
    -ps              Outputs a graph in PS format
  
    -raw             Outputs a text representation of the raw profile
  
    -svg             Outputs a graph in SVG format
  
    -tags            Outputs all tags in the profile
  
    -text            Outputs top entries in text form
  
    -top             Outputs top entries in text form
  
    -topproto        Outputs top entries in compressed protobuf format
  
    -traces          Outputs all profile samples in text form
  
    -tree            Outputs a text rendering of call graph
  
    -web             Visualize graph through web browser
  
    -weblist         Display annotated source in a web browser
  

  
  Options:
  
    -call_tree       Create a context-sensitive call tree
  
    -compact_labels  Show minimal headers
  
    -divide_by       Ratio to divide all samples before visualization
  
    -drop_negative   Ignore negative differences
  
    -edgefraction    Hide edges below <f>*total
  
    -focus           Restricts to samples going through a node matching regexp
  
    -hide            Skips nodes matching regexp
  
    -ignore          Skips paths going through any nodes matching regexp
  
    -mean            Average sample value over first value (count)
  
    -nodecount       Max number of nodes to show
  
    -nodefraction    Hide nodes below <f>*total
  
    -normalize       Scales profile based on the base profile.
  
    -output          Output filename for file-based outputs
  
    -prune_from      Drops any functions below the matched frame.
  
    -relative_percentages Show percentages relative to focused subgraph
  
    -sample_index    Sample value to report (0-based index or name)
  
    -show            Only show nodes matching regexp
  
    -show_from       Drops functions above the highest matched frame.
  
    -source_path     Search path for source files
  
    -tagfocus        Restricts to samples with tags in range or matched by regexp
  
    -taghide         Skip tags matching this regexp
  
    -tagignore       Discard samples with tags in range or matched by regexp
  
    -tagshow         Only consider tags matching this regexp
  
    -trim            Honor nodefraction/edgefraction/nodecount defaults
  
    -trim_path       Path to trim from source paths before search
  
    -unit            Measurement units to display
  

  
  Option groups (only set one per group):
  
    cumulative       
  
      -cum             Sort entries based on cumulative weight
  
      -flat            Sort entries based on own weight
  
    granularity      
  
      -addresses       Aggregate at the function level.
  
      -addressnoinlines Aggregate at the function level, including functions' addresses in the output.
  
      -files           Aggregate at the file level.
  
      -functions       Aggregate at the function level.
  
      -lines           Aggregate at the source code line level.
  
      -noinlines       Aggregate at the function level.
  

  
  Source options:
  
    -seconds              Duration for time-based profile collection
  
    -timeout              Timeout in seconds for profile collection
  
    -buildid              Override build id for main binary
  
    -add_comment          Free-form annotation to add to the profile
  
                          Displayed on some reports or with pprof -comments
  
    -base source          Source of profile to use as baseline
  
    profile.pb.gz         Profile in compressed protobuf format
  
    legacy_profile        Profile in legacy pprof format
  
    http://host/profile   URL for profile handler to retrieve
  
    -symbolize=           Controls source of symbol information
  
      none                  Do not attempt symbolization
  
      local                 Examine only local binaries
  
      fastlocal             Only get function names from local binaries
  
      remote                Do not examine local binaries
  
      force                 Force re-symbolization
  
    Binary                  Local path or build id of binary for symbolization
  

  

  
  Misc options:
  
   -http              Provide web based interface at host:port.
  
                      Host is optional and 'localhost' by default.
  
                      Port is optional and a randomly available port by default.
  
   -tools             Search path for object tools
  

  
  Legacy convenience options:
  
   -inuse_space           Same as -sample_index=inuse_space
  
   -inuse_objects         Same as -sample_index=inuse_objects
  
   -alloc_space           Same as -sample_index=alloc_space
  
   -alloc_objects         Same as -sample_index=alloc_objects
  
   -total_delay           Same as -sample_index=delay
  
   -contentions           Same as -sample_index=contentions
  
   -mean_delay            Same as -mean -sample_index=delay
  

  
  Environment Variables:
  
   PPROF_TMPDIR       Location for saved profiles (default $HOME/pprof)
  
   PPROF_TOOLS        Search path for object-level tools
  
   PPROF_BINARY_PATH  Search path for local binary files
  
                      default: $HOME/pprof/binaries
  
                      searches $name, $path, $buildid/$name, $path/$buildid
  
   * On Windows, %USERPROFILE% is used instead of $HOME
  

匿名

usage:

Produce output in the specified format.

   pprof <format> [options] [binary] <source> ...

Omit the format to get an interactive shell whose commands can be used
to generate various views of a profile

   pprof [options] [binary] <source> ...

Omit the format and provide the "-http" flag to get an interactive web
interface at the specified host:port that can be used to navigate through
various views of a profile.

   pprof -http [host]:[port] [options] [binary] <source> ...

Details:
  Output formats (select at most one):
    -callgrind       Outputs a graph in callgrind format
    -comments        Output all profile comments
    -disasm          Output assembly listings annotated with samples
    -dot             Outputs a graph in DOT format
    -eog             Visualize graph through eog
    -evince          Visualize graph through evince
    -gif             Outputs a graph image in GIF format
    -gv              Visualize graph through gv
    -kcachegrind     Visualize report in KCachegrind
    -list            Output annotated source for functions matching regexp
    -pdf             Outputs a graph in PDF format
    -peek            Output callers/callees of functions matching regexp
    -png             Outputs a graph image in PNG format
    -proto           Outputs the profile in compressed protobuf format
    -ps              Outputs a graph in PS format
    -raw             Outputs a text representation of the raw profile
    -svg             Outputs a graph in SVG format
    -tags            Outputs all tags in the profile
    -text            Outputs top entries in text form
    -top             Outputs top entries in text form
    -topproto        Outputs top entries in compressed protobuf format
    -traces          Outputs all profile samples in text form
    -tree            Outputs a text rendering of call graph
    -web             Visualize graph through web browser
    -weblist         Display annotated source in a web browser

  Options:
    -call_tree       Create a context-sensitive call tree
    -compact_labels  Show minimal headers
    -divide_by       Ratio to divide all samples before visualization
    -drop_negative   Ignore negative differences
    -edgefraction    Hide edges below <f>*total
    -focus           Restricts to samples going through a node matching regexp
    -hide            Skips nodes matching regexp
    -ignore          Skips paths going through any nodes matching regexp
    -mean            Average sample value over first value (count)
    -nodecount       Max number of nodes to show
    -nodefraction    Hide nodes below <f>*total
    -normalize       Scales profile based on the base profile.
    -output          Output filename for file-based outputs
    -prune_from      Drops any functions below the matched frame.
    -relative_percentages Show percentages relative to focused subgraph
    -sample_index    Sample value to report (0-based index or name)
    -show            Only show nodes matching regexp
    -show_from       Drops functions above the highest matched frame.
    -source_path     Search path for source files
    -tagfocus        Restricts to samples with tags in range or matched by regexp
    -taghide         Skip tags matching this regexp
    -tagignore       Discard samples with tags in range or matched by regexp
    -tagshow         Only consider tags matching this regexp
    -trim            Honor nodefraction/edgefraction/nodecount defaults
    -trim_path       Path to trim from source paths before search
    -unit            Measurement units to display

  Option groups (only set one per group):
    cumulative       
      -cum             Sort entries based on cumulative weight
      -flat            Sort entries based on own weight
    granularity      
      -addresses       Aggregate at the function level.
      -addressnoinlines Aggregate at the function level, including functions' addresses in the output.
      -files           Aggregate at the file level.
      -functions       Aggregate at the function level.
      -lines           Aggregate at the source code line level.
      -noinlines       Aggregate at the function level.

  Source options:
    -seconds              Duration for time-based profile collection
    -timeout              Timeout in seconds for profile collection
    -buildid              Override build id for main binary
    -add_comment          Free-form annotation to add to the profile
                          Displayed on some reports or with pprof -comments
    -base source          Source of profile to use as baseline
    profile.pb.gz         Profile in compressed protobuf format
    legacy_profile        Profile in legacy pprof format
    http://host/profile   URL for profile handler to retrieve
    -symbolize=           Controls source of symbol information
      none                  Do not attempt symbolization
      local                 Examine only local binaries
      fastlocal             Only get function names from local binaries
      remote                Do not examine local binaries
      force                 Force re-symbolization
    Binary                  Local path or build id of binary for symbolization


  Misc options:
   -http              Provide web based interface at host:port.
                      Host is optional and 'localhost' by default.
                      Port is optional and a randomly available port by default.
   -tools             Search path for object tools

  Legacy convenience options:
   -inuse_space           Same as -sample_index=inuse_space
   -inuse_objects         Same as -sample_index=inuse_objects
   -alloc_space           Same as -sample_index=alloc_space
   -alloc_objects         Same as -sample_index=alloc_objects
   -total_delay           Same as -sample_index=delay
   -contentions           Same as -sample_index=contentions
   -mean_delay            Same as -mean -sample_index=delay

  Environment Variables:
   PPROF_TMPDIR       Location for saved profiles (default $HOME/pprof)
   PPROF_TOOLS        Search path for object-level tools
   PPROF_BINARY_PATH  Search path for local binary files
                      default: $HOME/pprof/binaries
                      searches $name, $path, $buildid/$name, $path/$buildid
   * On Windows, %USERPROFILE% is used instead of $HOME

匿名

```
usage:

Produce output in the specified format.

   pprof <format> [options] [binary] <source> ...

Omit the format to get an interactive shell whose commands can be used
to generate various views of a profile

   pprof [options] [binary] <source> ...

Omit the format and provide the "-http" flag to get an interactive web
interface at the specified host:port that can be used to navigate through
various views of a profile.

   pprof -http [host]:[port] [options] [binary] <source> ...

Details:
  Output formats (select at most one):
    -callgrind       Outputs a graph in callgrind format
    -comments        Output all profile comments
    -disasm          Output assembly listings annotated with samples
    -dot             Outputs a graph in DOT format
    -eog             Visualize graph through eog
    -evince          Visualize graph through evince
    -gif             Outputs a graph image in GIF format
    -gv              Visualize graph through gv
    -kcachegrind     Visualize report in KCachegrind
    -list            Output annotated source for functions matching regexp
    -pdf             Outputs a graph in PDF format
    -peek            Output callers/callees of functions matching regexp
    -png             Outputs a graph image in PNG format
    -proto           Outputs the profile in compressed protobuf format
    -ps              Outputs a graph in PS format
    -raw             Outputs a text representation of the raw profile
    -svg             Outputs a graph in SVG format
    -tags            Outputs all tags in the profile
    -text            Outputs top entries in text form
    -top             Outputs top entries in text form
    -topproto        Outputs top entries in compressed protobuf format
    -traces          Outputs all profile samples in text form
    -tree            Outputs a text rendering of call graph
    -web             Visualize graph through web browser
    -weblist         Display annotated source in a web browser

  Options:
    -call_tree       Create a context-sensitive call tree
    -compact_labels  Show minimal headers
    -divide_by       Ratio to divide all samples before visualization
    -drop_negative   Ignore negative differences
    -edgefraction    Hide edges below <f>*total
    -focus           Restricts to samples going through a node matching regexp
    -hide            Skips nodes matching regexp
    -ignore          Skips paths going through any nodes matching regexp
    -mean            Average sample value over first value (count)
    -nodecount       Max number of nodes to show
    -nodefraction    Hide nodes below <f>*total
    -normalize       Scales profile based on the base profile.
    -output          Output filename for file-based outputs
    -prune_from      Drops any functions below the matched frame.
    -relative_percentages Show percentages relative to focused subgraph
    -sample_index    Sample value to report (0-based index or name)
    -show            Only show nodes matching regexp
    -show_from       Drops functions above the highest matched frame.
    -source_path     Search path for source files
    -tagfocus        Restricts to samples with tags in range or matched by regexp
    -taghide         Skip tags matching this regexp
    -tagignore       Discard samples with tags in range or matched by regexp
    -tagshow         Only consider tags matching this regexp
    -trim            Honor nodefraction/edgefraction/nodecount defaults
    -trim_path       Path to trim from source paths before search
    -unit            Measurement units to display

  Option groups (only set one per group):
    cumulative       
      -cum             Sort entries based on cumulative weight
      -flat            Sort entries based on own weight
    granularity      
      -addresses       Aggregate at the function level.
      -addressnoinlines Aggregate at the function level, including functions' addresses in the output.
      -files           Aggregate at the file level.
      -functions       Aggregate at the function level.
      -lines           Aggregate at the source code line level.
      -noinlines       Aggregate at the function level.

  Source options:
    -seconds              Duration for time-based profile collection
    -timeout              Timeout in seconds for profile collection
    -buildid              Override build id for main binary
    -add_comment          Free-form annotation to add to the profile
                          Displayed on some reports or with pprof -comments
    -base source          Source of profile to use as baseline
    profile.pb.gz         Profile in compressed protobuf format
    legacy_profile        Profile in legacy pprof format
    http://host/profile   URL for profile handler to retrieve
    -symbolize=           Controls source of symbol information
      none                  Do not attempt symbolization
      local                 Examine only local binaries
      fastlocal             Only get function names from local binaries
      remote                Do not examine local binaries
      force                 Force re-symbolization
    Binary                  Local path or build id of binary for symbolization


  Misc options:
   -http              Provide web based interface at host:port.
                      Host is optional and 'localhost' by default.
                      Port is optional and a randomly available port by default.
   -tools             Search path for object tools

  Legacy convenience options:
   -inuse_space           Same as -sample_index=inuse_space
   -inuse_objects         Same as -sample_index=inuse_objects
   -alloc_space           Same as -sample_index=alloc_space
   -alloc_objects         Same as -sample_index=alloc_objects
   -total_delay           Same as -sample_index=delay
   -contentions           Same as -sample_index=contentions
   -mean_delay            Same as -mean -sample_index=delay

  Environment Variables:
   PPROF_TMPDIR       Location for saved profiles (default $HOME/pprof)
   PPROF_TOOLS        Search path for object-level tools
   PPROF_BINARY_PATH  Search path for local binary files
                      default: $HOME/pprof/binaries
                      searches $name, $path, $buildid/$name, $path/$buildid
   * On Windows, %USERPROFILE% is used instead of $HOME
```

匿名

(7480.074|   9.580) D: [pulseaudio] protocol-native.c: Client pavucontrol changes volume of source alsa_input.usb-Generic_USB_Audio-00.analog-stereo-front-mic.
(7480.074|   0.000) D: [pulseaudio] source.c: The reference volume of source alsa_input.usb-Generic_USB_Audio-00.analog-stereo-front-mic changed from front-left: 59971 /  92% / -2.31 dB to front-left: 14550 /  22% / -39.22 dB.
(7480.074|   0.000) D: [alsa-source-USB Audio] alsa-source.c: Requested volume: front-left: 14550 /  22% / -39.22 dB
(7480.074|   0.000) D: [alsa-source-USB Audio] alsa-source.c: Got hardware volume: front-left: 33328 /  51% / -17.62 dB
(7480.074|   0.000) D: [alsa-source-USB Audio] alsa-source.c: Calculated software volume: front-left: 28611 /  44% / -21.60 dB (accurate-enough=no)
(7480.074|   0.000) D: [alsa-source-USB Audio] source.c: Volume going down to 33328 at 8142531019
(7480.074|   0.000) D: [alsa-source-USB Audio] source.c: Volume change to 33328 at 8142531019 was written 7311 usec late
(7480.074|   0.000) I: [pulseaudio] module-device-restore.c: Storing volume/mute for device+port source:alsa_input.usb-Generic_USB_Audio-00.analog-stereo-front-mic:analog-input-front-mic.

匿名

#deb [by-hash=force] http://pools.corp.deepin.com/ppa/dde-eagle eagle main contrib non-free

#deb-src [by-hash=force] http://pools.corp.deepin.com/ppa/dde-eagle eagle main

#deb [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free

#deb-src [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free

#deb http://pools.corp.deepin.com/ppa/dde-eagle experimental main

#deb-src http://pools.corp.deepin.com/ppa/dde-eagle experimental main


deb [by-hash=force] http://packages.chinauos.cn/uos eagle main contrib non-free

deb-src http://packages.chinauos.cn/uos eagle main contrib non-free

deb [trusted=yes] http://10.0.10.32:5000/cache/repos/eagle/release-candidate/VjIw5q2j5byP54mI56ys5LiA5rOi6ZuG5oiQ unstable main

#deb [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free

#deb http://pools.corp.deepin.com/debian-buster  buster main contrib non-free

deb [by-hash=force] http://pools.corp.deepin.com/ppa/dde-eagle eagle main contrib non-free

deb [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free

deb-src [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free

deb-src [by-hash=force] http://pools.corp.deepin.com/ppa/dde-eagle eagle main

deb http://pools.corp.deepin.com/ppa/dde-eagle experimental main

deb-src http://pools.corp.deepin.com/ppa/dde-eagle experimental main



##内网开发环境(vpn连接内网)

deb http://10.0.10.25/uos eagle main contrib non-free

deb http://pools.corp.deepin.com/ppa/dde-eagle eagle main contrib non-free

匿名

#deb [by-hash=force] http://pools.corp.deepin.com/ppa/dde-eagle eagle main contrib non-free
#deb-src [by-hash=force] http://pools.corp.deepin.com/ppa/dde-eagle eagle main
#deb [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free
#deb-src [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free
#deb http://pools.corp.deepin.com/ppa/dde-eagle experimental main
#deb-src http://pools.corp.deepin.com/ppa/dde-eagle experimental main

deb [by-hash=force] http://packages.chinauos.cn/uos eagle main contrib non-free

deb-src http://packages.chinauos.cn/uos eagle main contrib non-free
deb [trusted=yes] http://10.0.10.32:5000/cache/repos/eagle/release-candidate/VjIw5q2j5byP54mI56ys5LiA5rOi6ZuG5oiQ unstable main

#deb [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free
#deb http://pools.corp.deepin.com/debian-buster  buster main contrib non-free

deb [by-hash=force] http://pools.corp.deepin.com/ppa/dde-eagle eagle main contrib non-free
deb [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free
deb-src [by-hash=force] http://10.0.10.25/uos eagle main contrib non-free
deb-src [by-hash=force] http://pools.corp.deepin.com/ppa/dde-eagle eagle main
deb http://pools.corp.deepin.com/ppa/dde-eagle experimental main
deb-src http://pools.corp.deepin.com/ppa/dde-eagle experimental main


##内网开发环境(vpn连接内网)
deb http://10.0.10.25/uos eagle main contrib non-free
deb http://pools.corp.deepin.com/ppa/dde-eagle eagle main contrib non-free
STcmXIGpWQNAhaJC
nfCOEKHQdoX

匿名

# dbus 与 go

go 有 dbus 库,源码在 https://github.com/godbus/dbus/ 。我把这个仓库中的代码复制到了 go-lib 项目中,放在 dbus1 文件夹。go-lib 项目中之前的 dbus 文件夹是旧版本 dbus 库。

go-lib 项目地址:https://github.com/godbus/dbus/ 。go-lib 项目可以打成deb 包,软件包名 `golang-dlib-dev` 。 目前 go 语言代码库打包然后安装后,放在 `/usr/share/gocode/src` 文件夹下。这个 dbus1 就在 `/usr/share/gocode/src/pkg.deepin.io/lib/dbus1` 文件夹下。导入包时要 `import  "pkg.deepin.io/lib/dbus1"`

## 使用 dbus 包

### 连接 Bus

主要分为连接 Session Bus 和 System Bus。

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbus1"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	_ = sessionBus

	systemBus, err := dbus.SystemBus()
	if err != nil {
		log.Fatal(err)
	}
	_ = systemBus
}
```

### 调用方法

比如调用 dbus-daemon 提供的对象的一个方法,服务名: `org.freedesktop.DBus`, 路径: `/org/freedesktop/DBus`,接口名:`org.freedesktop.DBus`, 方法名:`GetNameOwner`, 此方法输入参数是一个字符串,返回参数也是一个字符串。


```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbus1"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	obj := sessionBus.Object("org.freedesktop.DBus", "/org/freedesktop/DBus")
	var ret string
	err = obj.Call("org.freedesktop.DBus.GetNameOwner", 0, "com.deepin.dde.daemon.Dock").Store(&ret)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("ret:", ret)
}
```

需要注意传给 `obj.Call` 方法的第一个参数 `method` 的值是接口名 + "." + 方法名。

在处理没有返回值的方法时,可以不调用 `Store` 方法,而直接检查 `Err` 字段。

```go
err = obj.Call("org.freedesktop.DBus.ReloadConfig", 0).Err
if err != nil {
	log.Fatal(err)
}
```

### 获取和设置属性

属性的获取和设置本质也是方法调用。


#### 获取属性

获取单个属性是调用对象的 `org.freedesktop.DBus.Properties` 接口的 `Get` 方法,此方法传入参数是接口名和属性名,返回值是属性值,类型为 `dbus.Variant` 。

下面的代码是要获取 `org.freedesktop.DBus` 接口的 `Features` 属性,此属性的类型是 `[]string` 。

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbus1"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	obj := sessionBus.Object("org.freedesktop.DBus", "/org/freedesktop/DBus")
	var ret dbus.Variant
	err = obj.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.DBus", "Features").Store(&ret)
	if err != nil {
		log.Fatal(err)
	}
	v := ret.Value().([]string)
	log.Println(v)
}
```

从 `ret` 中获取内部的值,需要调用 `Value` 方法,获取 `interface{}` 类型的内部值,再使用类型断言`.([]string)`。

一次获取对象在某个接口下的全部属性,可调用 `Get` 方法旁边的 `GetAll` 方法。

#### 设置属性

设置属性是调用对象的 `org.freedesktop.DBus.Properties` 接口的 `Set` 方法,此方法的传入参数是接口名、属性名、属性值,没有返回值。下面的代码是要设置 `org.freedesktop.DBus` 接口的 `Features` 属性。

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbus1"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	obj := sessionBus.Object("org.freedesktop.DBus", "/org/freedesktop/DBus")
	propVal := dbus.MakeVariant([]string{"abc"})
	err = obj.Call("org.freedesktop.DBus.Properties.Set", 0, "org.freedesktop.DBus", "Features", propVal).Err
	if err != nil {
		log.Fatal(err)
	}
}
```

传入参数中属性值是 `dbus.Variant` 类型,制造这种类型可用 `dbus.MakeVariant` 方法。

由于这个 `Features` 属性是只读的,程序会收到一个错误 `Property 'org.freedesktop.DBus.Features' cannot be set` 。

### 监听信号

调用 `AddMatch` 方法添加监听规则,如果不需要监听了,就调用 `RemoveMatch` 方法去掉监听规则。

go 的 dbus 库提供了方便的方法:`AddMatchSignal` 和 `RemoveMatchSignal`。

下面的代码是要监听 `Session Bus` 上的 `/org/freedesktop/Bus` 对象的 `org.freedesktop.DBus` 接口的 `NameOwnerChanged` 信号。

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbus1"
	"time"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	err = sessionBus.BusObject().AddMatchSignal("org.freedesktop.DBus", "NameOwnerChanged",
		dbus.WithMatchObjectPath("/org/freedesktop/DBus")).Err
	if err != nil {
		log.Fatal(err)
	}

	signalCh := make(chan  *dbus.Signal, 10)
	sessionBus.Signal(signalCh)
	go func() {
		log.Print("start")
		for {
			select {
			case sig := <-signalCh:
				log.Printf("sig: %#v\n", sig)
                if sig.Path == "/org/freedesktop/DBus" &&
                 sig.Name == "org.freedesktop.DBus.NameOwnerChanged" {
					var name string
					var oldOwner string
					var newOwner string
					err = dbus.Store(sig.Body, &name, &oldOwner, &newOwner)
					if err != nil {
						log.Println("WARN:", err)
					}
					log.Printf("%s %s %s\n", name, oldOwner, newOwner)
				}
			}
		}
	}()

	time.Sleep(100*time.Second)
	err = sessionBus.BusObject().RemoveMatchSignal("org.freedesktop.DBus", "NameOwnerChanged",
		dbus.WithMatchObjectPath("/org/freedesktop/Bus")).Err
	if err != nil {
		log.Fatal(err)
    }
    sessionBus.RemoveSignal(signalCh)
}
```

将调用 `sessionBus.Signal` 方法注册 `signalCh` 通道,以此来通过该通道接收信号,`go func ()` 中的代码是循环接收 `signalCh` 通道传来的数据并处理。如果不需要再从这个通道接收信号了,可以调用`sessionBus.RemoveSignal` 取消注册`signalCh` 通道,这样信号就不会再被发送到 `signalCh` 通道中了。

在处理信号时,可以先验证信号(`*dbus.Signal` 类型)的 `Path` 和 `Name` 字段,不必验证 `Sender` 字段。 处理信号的 `Body` 字段,它是 `[]interface{}` 类型,就可以用 `dbus.Store` 方法了。


### 导出对象

将自己代码中的一个变量作为对象的一个接口导出在 DBus 上,然后供其他人调用。

下面的代码是要把类型为 `Obj` 结构的 `obj` 变量作为对象的一个接口导出,它有一个 `GetString` 方法,路径 `/p1/p2/p3`,接口名 `p1.p2.p3`。

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbus1"
)

type Obj struct {
}

func (o *Obj) GetString() (string, *dbus.Error) {
	return "object", nil
}

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	obj := &Obj{}
	err = sessionBus.Export(obj, "/p1/p2/p3", "p1.p2.p3")
	if err != nil {
		log.Fatal(err)
	}
	log.Print("names:", sessionBus.Names())
	select {
	}
}
```

程序运行后会打印类似的输出:
```
names:[:1.4239 :1.4239]
```
这是此程序目前在 DBus 上的名字,冒号`:`开头的是唯一名。

使用如下命令检查:

```sh
$ gdbus call -e -d :1.4239 -o /p1/p2/p3 -m p1.p2.p3.GetString
('object',)
```

导出对象接口,可以调用 `sessionBus.Export` 方法,要停止导出,并没有一个专门的的方法,依旧要使用 `Export` 方法, 但是第一个参数(之前放 `obj` 的位置)要换成 `nil`。

自动导出的方法有如下要求:

1. 公开的,方法名第一字母是大写的。
2. 最后一个返回值是 *dbus.Error 类型。


### 注册服务名

下面的代码是要申请一个服务名 `p1.p2.p3`, 不是完整代码,可以插在前一份代码的 `sessionBus.Export` 方法调用之后。现有的各个项目里也一般是先导出主要对象,然后再申请服务名。

```
_, err = sessionBus.RequestName("p1.p2.p3", 0)
```

程序运行后,使用如下命令检查:

```
$ gdbus call -e -d p1.p2.p3 -o /p1/p2/p3 -m p1.p2.p3.GetString
('object',)
```

### 发送信号

下面的代码是要发送信号,路径 `/p1/p2/p3`, 接口名 `p1.p2.p3`, 信号名 `Signal1`, 参数是字符串和数字。

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbus1"
	"time"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	log.Print("names:", sessionBus.Names())
	for {
		err = sessionBus.Emit("/p1/p2/p3", "p1.p2.p3.Signal1", "arg1", 2)
		if err != nil {
			log.Print("WARN:", err)
		}
		time.Sleep(2*time.Second)
	}
}
```


程序运行后会打印类似的输出:
```
names:[:1.4317 :1.4317]
```

这是此程序目前在 DBus 上的名字,冒号`:`开头的是唯一名。

程序每2秒发送一次信号,使用如下命令监听信号:

```sh
$ gdbus monitor -e -d :1.4317 -o /p1/p2/p3

Monitoring signals from all objects owned by :1.4317
The name :1.4317 is owned by :1.4317
/p1/p2/p3: p1.p2.p3.Signal1 ('arg1', 2)
/p1/p2/p3: p1.p2.p3.Signal1 ('arg1', 2)
/p1/p2/p3: p1.p2.p3.Signal1 ('arg1', 2
```

可以发现发送信号时,不要求对象是否已经导出。

-------------

## 使用 go-dbus-factory 项目

此项目实现了根据 dbus 服务的自省 XML 文件和一点配置文件,自动生成访问 dbus 服务的 go 代码。

项目地址:https://gitlab.deepin.io/dde-v20/go-dbus-factory ,可以打成 deb 包,软件包名 `golang-github-linuxdeepin-go-dbus-factory-dev` ,每个服务放在不同的包中,包名的前缀是 `github.com/linuxdeepin/go-dbus-factory/`。

### 方法调用

下面的代码要调用 `com.deepin.dde.daemon.Dock` 服务的 `/com/deepin/dde/daemon/Dock` 对象的 `RequestDock` 方法。

```go
package main

import (
	"github.com/linuxdeepin/go-dbus-factory/com.deepin.dde.daemon.dock"
	"log"
	"pkg.deepin.io/lib/dbus1"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	dockObj := dock.NewDock(sessionBus)
	ok, err := dockObj.RequestDock(0, "/usr/share/applications/deepin-editor.desktop", -1)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("ok:", ok)
}
```

要点是使用 `dock.NewDock` 创建 DBus 上 `Dock` 对象的本地映射,然后直接调用它的 `RequestDock` 方法。


### 获取和设置属性

下面的代码是要获取之前说过的 `Dock` 对象的 `Entires` 属性,然后在获取每个 `Entry` 对象的 `Name` 属性。

#### 获取属性

```go
package main

import (
	"github.com/linuxdeepin/go-dbus-factory/com.deepin.dde.daemon.dock"
	"log"
	"pkg.deepin.io/lib/dbus1"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	dockObj := dock.NewDock(sessionBus)
	entries, err := dockObj.Entries().Get(0)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Entries:", entries)
	for i, entryPath := range entries {
		entryObj, err := dock.NewEntry(sessionBus, entryPath)
		if err != nil {
			log.Fatal(err)
		}
		name, err := entryObj.Name().Get(0)
		if err != nil {
			log.Fatal(err)
		}
		log.Println(i, name)
	}
}
```

要点是 `dockObj.Entries().Get(0)`, 注意 `Entries` 是 dockObj 的一个方法,要加 `()` 来调用。
然后是 `dock.NewEntry` , 这个方法不同于 `dock.NewDock` 方法,支持传入对象路径,是因为用于自动生成代码的配置文件指定了 `Entry` 是可以有不同路径的,而 `Dock` 是只能有确定的路径。

#### 设置属性

下面的代码是要设置之前说过的 `Dock` 对象的 `DisplayMode` 属性。

```go
package main

import (
	"github.com/linuxdeepin/go-dbus-factory/com.deepin.dde.daemon.dock"
	"log"
	"pkg.deepin.io/lib/dbus1"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	dockObj := dock.NewDock(sessionBus)
	err = dockObj.DisplayMode().Set(0, 1)
	if err != nil {
		log.Fatal(err)
	}
}
```

要点是 `dockObj.DisplayMode().Set(0, 1)`。

### 监听信号

下面的代码是要监听之前说过的 `Dock` 对象的 `EntryAdded` 信号。

```go
package main

import (
	"github.com/linuxdeepin/go-dbus-factory/com.deepin.dde.daemon.dock"
	"log"
	"pkg.deepin.io/lib/dbus1"
	"pkg.deepin.io/lib/dbusutil"
	"time"
)

func main() {
	sessionBus, err := dbus.SessionBus()
	if err != nil {
		log.Fatal(err)
	}
	dockObj := dock.NewDock(sessionBus)
	sigLoop := dbusutil.NewSignalLoop(sessionBus, 10)
	sigLoop.Start()
	dockObj.InitSignalExt(sigLoop, true)
	sigHid, err := dockObj.ConnectEntryAdded(func(entryPath dbus.ObjectPath, index int32) {
		log.Println(entryPath, index)
	})

	time.Sleep(100*time.Second)
	sigLoop.Stop()
	dockObj.RemoveHandler(sigHid)
}
```

程序运行后,从启动器打开一个任务栏上之前没有的应用,然后程序就能收到 `EntryAdded` 信号并打印参数值出来。 

这部分代码用到了新的包 `pkg.deepin.io/lib/dbusutil` 包,使用它的 `SignalLoop` 功能来处理信号。调用 `dbusutil.NewSignalLoop` 创建一个信号循环,然后调用`Start` 方法开始,当不需要时调用 `Stop` 结束。
`dockObj` 默认是不支持监听信号的,直接调用 `dockObj.ConnectXXX` 方法会崩溃,必须先调用 `InitSignalExt` 方法,传入 SignalLoop。

----------------

## 使用 dbusutil 包

之前介绍了使用 dbus1 包,现在介绍使用更多的 dbusutil 包,它是对 dbus1 包的功能的一次包装,更加偏向于导出服务。

### 导出对象

下面的代码是使用 dbusutil 包重写了之前用 dbus1 包实现的导出对象的代码。 

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbus1"
	"pkg.deepin.io/lib/dbusutil"
)

type Obj struct {
	methods *struct {
		GetString func() `out:"result"`
	}
}

func (o *Obj) GetString() (string, *dbus.Error) {
	return "object", nil
}

func (o *Obj) GetInterfaceName() string {
	return "p1.p2.p3"
}

func main() {
	service, err := dbusutil.NewSessionService()
	if err != nil {
		log.Fatal(err)
	}
	obj := &Obj{
	}
	err = service.Export("/p1/p2/p3", obj)
	if err != nil {
		log.Fatal(err)
	}
	err = service.RequestName("p1.p2.p3")
	if err != nil {
		log.Fatal(err)
	}
	service.Wait()
}
```

程序运行后,使用如下命令测试:

```
$ gdbus call -e -d p1.p2.p3 -o /p1/p2/p3 -m p1.p2.p3.GetString
('object',)
```

在 `main` 方法中,使用 `dbusutil.NewSessionService` 创建 `*dbusutil.Service` 类型的变量 `service`,然后调用 `service.Export` 方法导出 `obj` 变量。要导出 `obj `变量,就得让它的类型 `*Obj` 实现 `GetInterfaceName` 方法,此方法要返回接口名。

使用如下的命令查看此程序在 DBus 上提供服务的自省信息:
```
$ gdbus introspect -e -d p1.p2.p3 -o / -r
node / {
  node /p1 {
    node /p1/p2 {
      node /p1/p2/p3 {
        interface p1.p2.p3 {
          methods:
            GetString(out s result);
          signals:
          properties:
        };
        interface org.freedesktop.DBus.Introspectable {
          methods:
            Introspect(out s out);
          signals:
          properties:
        };
        interface org.freedesktop.DBus.Properties {
          methods:
            Get(in  s interface,
                in  s property,
                out v value);
            GetAll(in  s interface,
                   out a{sv} props);
            Set(in  s interface,
                in  s property,
                in  v value);
          signals:
            PropertiesChanged(s interface,
                              a{sv} changed_properties,
                              as invalidates_properties);
          properties:
        };
        interface org.freedesktop.DBus.Peer {
          methods:
            Ping();
            GetMachineId(out s machine_uuid);
          signals:
          properties:
        };
      };
    };
  };
};

```

看这个 `/p1/p2/p3` 路径下的对象,不仅有 `p1.p2.p3` 接口,还有其他的接口 `org.freedesktop.DBus.Introspectable` 和 `org.freedesktop.DBus.Properties` ,这是 `dbusutil` 包自动导出的。

### 定义属性

定义一个属性的简单方式是,给导出的结构增加公开字段,比如想要导出 `Obj` 结构,导出的接口`p1.p2.p3`中会有一个 `Name` 属性,类型为字符串,就要有如下定义:

```go
type Obj struct {
    Name string
}
```

这个 `Name` 属性是只读的,如果要让它可以写、设置,就要给 `Name` 字段加上结构字段`tag`:`prop:"access:rw"`, 如下:

```go
type Obj struct {
    Name string `prop:"access:rw"`
}
```


### 发送信号

下面的代码是要发送信号,路径 `/p1/p2/p3`, 接口名 `p1.p2.p3`, 信号名 `Signal1`, 参数是字符串和数字。

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbusutil"
	"time"
)

type Obj struct {
	signals *struct {
		Added struct {
            arg0 string
            arg1 int32
		}
	}
}

func (o *Obj) GetInterfaceName() string {
	return "p1.p2.p3"
}

func main() {
	service, err := dbusutil.NewSessionService()
	if err != nil {
		log.Fatal(err)
	}
	obj := &Obj{
	}
	err = service.Export("/p1/p2/p3", obj)
	if err != nil {
		log.Fatal(err)
	}
	err = service.RequestName("p1.p2.p3")
	if err != nil {
		log.Fatal(err)
	}
	for {
		err = service.Emit(obj, "Added", "val0", 11)
		if err != nil {
			log.Println("WARN:", err)
		}
		time.Sleep(2*time.Second)
	}
}
```

运行程序后,使用如下命令监听信号:
```
$ gdbus monitor -e -d p1.p2.p3 -o /p1/p2/p3
Monitoring signals on object /p1/p2/p3 owned by p1.p2.p3
The name p1.p2.p3 is owned by :1.4551
/p1/p2/p3: p1.p2.p3.Added ('val0',11,)
/p1/p2/p3: p1.p2.p3.Added ('val0',11,)
```

要点是在定义 Obj 结构时,加上 `signals` 字段,并在 `signals` 字段类型定义结构中加上 `Added` 字段 ,然后调用 `service.Emit` 方法发送信号。

### 发送属性改变信号

下面的代码是要发送属性改变信号,路径 `/p1/p2/p3`, 接口名 `p1.p2.p3`, 属性名 `Name`,类型字符串。

```go
package main

import (
	"log"
	"pkg.deepin.io/lib/dbusutil"
	"time"
)

type Obj struct {
	Name string
}

func (o *Obj) GetInterfaceName() string {
	return "p1.p2.p3"
}

func main() {
	service, err := dbusutil.NewSessionService()
	if err != nil {
		log.Fatal(err)
	}
	obj := &Obj{
	}
	err = service.Export("/p1/p2/p3", obj)
	if err != nil {
		log.Fatal(err)
	}
	err = service.RequestName("p1.p2.p3")
	if err != nil {
		log.Fatal(err)
	}
	for {
		err = service.EmitPropertyChanged(obj, "Name", "name1")
		if err != nil {
			log.Println("WARN:", err)
		}
		time.Sleep(2*time.Second)
	}
}
```

要点是先在 Obj 结构中定义一个属性 `Name`,然后调用 `service.EmitPropertyChanged` 方法发送属性改变信号。

程序每隔2秒会发送一次 `Name` 属性改变信号,使用如下命令监听信号:

```
$ gdbus monitor -e -d p1.p2.p3 -o /p1/p2/p3
Monitoring signals on object /p1/p2/p3 owned by p1.p2.p3
The name p1.p2.p3 is owned by :1.4574
/p1/p2/p3: org.freedesktop.DBus.Properties.PropertiesChanged ('p1.p2.p3', {'Name': <'name1'>}, @as [])
/p1/p2/p3: org.freedesktop.DBus.Properties.PropertiesChanged ('p1.p2.p3', {'Name': <'name1'>}, @as [])
```

有关更多请查看 [dbusutil 的文档](https://gitlab.deepin.io/dde-v20/go-lib/blob/master/doc/dbusutil.md)。

## 更多更详细信息请参考
- [D-Bus Specification](https://dbus.freedesktop.org/doc/dbus-specification.html)
- [godoc dbus](https://godoc.org/github.com/godbus/dbus)

匿名

# gsettings 与 go

gsettings 是 gio 提供的功能,go 语言要用就得用 cgo 包装一下,这部分代码是由 `go-gir-generator` 工具自动生成的,软件包 `golang-gir-gio-2.0-dev` 提供了源码文件,安装之后放在 `/usr/share/gocode/src/pkg.deepin.io/gir/gio-2.0` 文件夹下。

项目地址: https://gitlab.deepin.io/github-linuxdeepin-mirror/go-gir-generator

## 简单使用

下面的代码是要获取和设置gsettings `ca.desrt.dconf-editor.Demo` 的几个设置项。

```go
package main

import (
	"log"
	"pkg.deepin.io/gir/gio-2.0"
)

func main() {
	gs := gio.NewSettings("ca.desrt.dconf-editor.Demo")
	str := gs.GetString("string")
	log.Println("str:", str)

	gs.SetString("string", str)

	int0 := gs.GetInt("integer-32-signed")
	log.Println("int:", int0)

    gs.SetInt("integer-32-signed", int0)
    gs.Unref()
}
```

`NewSettings` 方法,创建 Settings 对象。
`GetString` 方法获取字符串类型的设置项的值,`SetString` 方法设置字符串类型的设置项的值。
`GetInt` 方法获取整数 int32 类型的设置项的值,`SetInt` 方法设置整数 int32 类型的设置项的值。
`Unref` 方法,在不再需要 gs 对象时,减少引用计数的值。

## 监听改变信号(原生)

下面的代码是要监听 gsettings `ca.desrt.dconf-editor.Demo` 的 `boolean` 设置项的值改变事件。
```go
package main

import (
	"log"
	"pkg.deepin.io/gir/gio-2.0"
	"pkg.deepin.io/gir/glib-2.0"
)

func main() {
	gs := gio.NewSettings("ca.desrt.dconf-editor.Demo")
	gs.Connect("changed::boolean", func(gs *gio.Settings, key string) {
		boolean := gs.GetBoolean(key)
		log.Println(boolean)
	})
	glib.StartLoop()
}
```
调用 `Connect` 方法注册事件监听处理函数,第一个参数为事件名,第二个参数为事件处理函数。

`glib.StartLoop()` 开始一个 Main Loop 事件循环。

## 监听改变信号(dbus 实现)

由于原生的信号监听方式之前在一种特殊架构上偶尔出现发生了改变事件但不触发处理函数的问题,于是写了另外一种信号监听方式,来规避这种问题。

下面的代码使用了另外一个包 `pkg.deepin.io/lib/gsettings` 也实现了监听 `boolean` 设置项的值改变事件。

```go
package main

import (
	"log"
	"pkg.deepin.io/gir/gio-2.0"
	"pkg.deepin.io/lib/gsettings"
)

func main() {
	gs := gio.NewSettings("ca.desrt.dconf-editor.Demo")
    gsettings.ConnectChanged("ca.desrt.dconf-editor.Demo", "boolean",
     func(key string) {
			boolean := gs.GetBoolean(key)
			log.Println(boolean)
	})
	err := gsettings.StartMonitor()
	if err != nil {
		log.Fatal(err)
	}
	select {
	}
}
```

`ConnectChanged` 方法注册改变事件的处理函数,第一个参数是 `schema id`, 第二个参数是设置项名,第三个参数是事件处理函数。

`StartMonitor` 方法开始监听循环。

## dbus 服务中作为属性

下面的代码是要导出 DBus 服务,服务名 `p1.p2.p3`, 对象路径 `/p1/p2/p3`, 接口名 `p1.p2.p3`,把 gsettings `ca.desrt.dconf-editor.Demo` 的 `boolean` 设置项当作接口的属性。

```go
package main

import (
	"log"
	"pkg.deepin.io/gir/gio-2.0"
	"pkg.deepin.io/lib/dbusutil"
	"pkg.deepin.io/lib/dbusutil/gsprop"
	"pkg.deepin.io/lib/gsettings"
)

type Obj struct {
	Boolean gsprop.Bool `prop:"access:rw"`
}

func (o *Obj) GetInterfaceName() string {
	return "p1.p2.p3"
}

func main() {
	gs := gio.NewSettings("ca.desrt.dconf-editor.Demo")

	service, err := dbusutil.NewSessionService()
	if err != nil {
		log.Fatal(err)
	}

	obj := &Obj{}
	obj.Boolean.Bind(gs, "boolean")
	log.Println("get result:", obj.Boolean.Get())

	err = service.Export("/p1/p2/p3", obj)
	if err != nil {
		log.Fatal(err)
	}
	err = service.RequestName("p1.p2.p3")
	if err != nil {
		log.Fatal(err)
	}
	err = gsettings.StartMonitor()
	if err != nil {
		log.Fatal(err)
	}
	service.Wait()
}
```

这算是 gsettings 与 dbusutil 包知识相结合的内容。

要点是 Obj 结构定义了一个公开字段 `Name`,类型为 `gsprop.Bool`, 然后调用 `Bind` 方法绑定了 「 `gs` 的 `boolean` 设置项」 和 「 `obj` 的 `Name` 属性」 的关联,使得对 `Name` 属性的读写即是对 `gs` 的 `boolean` 设置项的读写, 如果 `gs` 的 `boolean` 设置项的值改变会自动发出 `Name` 属性改变信号。

gsprop 包中还有其他的类型,来支持各种数据类型,比如 `String`,`Int`,`Uint` 等。

同样要记得调用 `StartMonitor` 方法开始监听循环。

匿名

https://www.cnblogs.com/mrhonest/p/12418188.html

匿名

新年快乐,万事如意!

匿名

新年快乐,万事如意!

匿名

新年快乐,万事如意!

匿名

新年快乐,万事如意!

匿名

新年快乐,万事如意!

匿名

新年快乐,万事如意!

匿名

新年快乐,万事如意!