Import Upstream version 1.0.3

This commit is contained in:
Xie Wei 2022-05-06 18:29:20 +08:00
commit 0fd8394397
262 changed files with 55142 additions and 0 deletions

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
liuhao <liuhao@kylinos.cn>

674
COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

0
ChangeLog Normal file
View File

2
Makefile.am Normal file
View File

@ -0,0 +1,2 @@
SUBDIRS = src data po
EXTRA_DIST = autogen.sh

0
NEWS Normal file
View File

142
README Normal file
View File

@ -0,0 +1,142 @@
# ukui interface
## API结构
初步计划API结构如下所示
```
ukui interface结构
├── 操作系统(OS)
│   ├── 操作系统信息
│   │   ├── 版本大版本号、小版本号、补丁集编号、build日期
│   │   ├── 授权:授权用户、授权时间
│   │   └── 桌面环境UKUI、DDE、GNOME之类
│   ├── 文件浏览历史记录
│   │   ├── 是否记录文件打开历史
│   │   └── 开始菜单是否记录常用软件
│   ├── 备份还原
│   ├── 磁盘、分区管理
│   │   └── 分区管理器
│   └── 其他系统管理工具
│      ├── 系统服务:获取服务列表,禁用、启用服务,运行、停止、重启服务等
│      └── 打开其他各种图形化系统管理工具
├── 用户账户(Accounts)
│   ├── 用户(User)
│   │   └── 添加、修改、删除用户,包括以下信息
│   │      ├── 用户名
│   │      ├── 密码
│   │      ├── 用户组(账户类型)
│   │      ├── 自动登录
│   │      └── 语言
│   └── 用户组(Group)
│      └── 添加、修改、删除用户组,包括以下信息
│         ├── 组名
│         └── 组用户
├── 个性化(Personal)
│   ├── 个性化(Personal)
│   │   ├── 主题
│   │   ├── 屏幕保护程序
│   │   ├── 桌面壁纸
│   │   └── 桌面图标大小
│   ├── 显示(Display)
│   │   ├── 分辨率
│   │   ├── 多屏设置
│   │   └── 屏幕方向
│   └── 字体设置(Fonts)
│      ├── 添加删除字体
│      └── 设置字体大小
├── 时间(Date)
│   ├── 日期(Date)和时间(Time)
│   │   ├── 设置日期、时间
│   │   ├── 系统时间显示格式
│   │   ├── 禁用/启用时间同步
│   │   └── 时间同步服务器设置
│   ├── 语言(Language)
│   │   └── 设置语言
│   │   └── 设置输入法
│   └── 区域(Region)
│      └── 设置时区
├── 语言(Language)
│   ├── 设置语言
│   └── 输入法(Input)
├── 安全管理(Security)
│   ├── 安全概况(SecurityInfo)
│   │   ├── 获取安全等级及状态
│   │   ├── 更改安全等级
│   │   └── 安全策略设置
│   └── 防火墙(Firewall)
│      ├── 防火墙状态
│      ├── 防火墙禁用/启用
│      └── 防火墙规则设置
├── 软件管理(Software)
│   └── 默认应用程序(DefaultPrograms)
│      ├── 设置默认浏览器
│      ├── 设置默认文档编辑器
│      └── 设置默认图片查看器
├── 系统更新(Updates)
│   ├── 包版本
│   ├── 系统升级
│   ├── 包升级
│   └── 软件源(SoftwareSources)
│      ├── 添加、修改、移除、更新系统软件源
│      └── 添加、修改、移除、更新第三方软件源
├── 网络管理(Network)
│   ├── 网络设置(Network)
│   │   ├── 禁用启用网络接口;
│   │   ├── 设置以太网网络接口IP、子网掩码、网关、DNS
│   │   └── 设置WiFi接口SSID、密码、IP、子网掩码、网关、DNS
│   ├── 网络状态(Network)
│   │   ├── 接口
│   │   ├── MAC地址
│   │   ├── 驱动
│   │   ├── 链接速度
│   │   ├── IP地址、子网掩码、广播地址、网关、DNS
│   │   ├── 上传下载速率
│   │   ├── 总计上传下载数据包
│   │   ├── 总计上传下载数据量
│   │   └── 错误、丢弃、过载数据包数量
│   └── 网络共享(NetworkSharing)
│      └── samba、NFS之类服务
├── 硬件管理(Hardware)
│   ├── 硬件信息(HardwareInfo)
│   │   ├── CPU厂商、体系结构、型号、主频
│   │   ├── 内存:厂商、内存数量、单根内存大小、内存总大小
│   │   ├── 磁盘:厂商、磁盘数量、磁盘大小
│   │   ├── 主板:厂商、主板型号
│   │   ├── 显卡:厂商、显卡型号
│   │   ├── 以太网厂商、型号、MAC地址
│   │   ├── WiFi厂商、型号、MAC地址
│   │   └── 蓝牙厂商、型号、MAC地址
│   ├── 电源管理(Power)
│   │   ├── 电池设置:是否在菜单栏显示电池状态
│   │   ├── 关闭显示器时间
│   │   ├── 唤醒是否需要输入密码
│   │   └── 睡眠时间
│   ├── 打印机(Printers)
│   │   ├── 添加、删除打印机
│   │   └── 打印机测试
│   ├── 鼠标(Mouse)和触摸板(Touchpad)
│   │   ├── 左右手习惯
│   │   ├── 双击速度
│   │   ├── 指针图标
│   │   ├── 指针移动速度
│   │   ├── 滚轮滚动行数
│   │   └── 触摸板行为(这项可能需要与硬件匹配)
│   ├── 键盘(Keyboard)
│   │   ├── 打开/关闭按住某一键时重复该键:重复延时、重复速度
│   │   ├── 打开/关闭光标闪烁:光标闪烁速度
│   │   └── 快捷键:获取系统预设快捷键、设置自定义快捷键、删除自定义快捷键
│   ├── 声音管理(Sound)
│   │   ├── 输出管理:音量大小、静音、左右声道、输出源选择
│   │   ├── 输入管理:音量大小、静音、输出源选择
│   │   ├── 声音效果:警告音量、警告静音、选择警告声音
│   │   ├── 应用程序:应用音量设置
│   │   └── 菜单栏是否显示音量
│   ├── 显示器设置(Display)
│   │   ├── 分辨率
│   │   ├── 多屏设置
│   │   └── 屏幕方向
│   └── 蓝牙(Bluetooth)
│      ├── 打开关闭蓝牙
│      ├── 蓝牙设备列表
│      └── 菜单栏显示蓝牙状态
└── 其他功能
```

9
autogen.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
#aclocal
#autoconf
#autoheader
#libtoolize --copy
#automake --copy --add-missing
echo "Regenerating autotools files"
autoreconf --force --install || exit 1

72
configure.ac Normal file
View File

@ -0,0 +1,72 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(ukui-interface,1.0,liuhao@kylinos.cn)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_LIBTOOL
# Checks for libraries.
PKG_CHECK_MODULES(GLIB_2, glib-2.0 >= 1.00)
PKG_CHECK_MODULES(GIO_2, gio-2.0 >= 1.00)
PKG_CHECK_MODULES(GIO_UNIX_2, gio-unix-2.0 >= 1.00)
PKG_CHECK_MODULES(QT5CORE, Qt5Core >= 5.6.1)
# FIXME: Replace `main' with a function in `-lgsettings':
AC_CHECK_LIB([gsettings], [main])
# FIXME: Replace `main' with a function in `-lprint':
AC_CHECK_LIB([print], [main])
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
# Checks for library functions.
AC_CHECK_FUNCS([strerror])
AC_CONFIG_FILES([Makefile
data/Makefile
po/Makefile
src/Makefile
src/accounts/Makefile
src/accounts/user/Makefile
src/common/Makefile
src/date/Makefile
src/date/dttm/Makefile
src/hardware/Makefile
src/hardware/keyboard/Makefile
src/hardware/mouse/Makefile
src/hardware/touchpad/Makefile
src/hardware/power/Makefile
src/language/Makefile
src/network/Makefile
src/network/network/Makefile
src/os/Makefile
src/os/subversion/Makefile
src/os/sysinfo/Makefile
src/other/Makefile
src/personal/Makefile
src/personal/background/Makefile
src/personal/desktop/Makefile
src/personal/font/Makefile
src/personal/marcogeneral/Makefile
src/security/Makefile
src/software/Makefile
src/software/defaultprograms/Makefile
src/updates/Makefile])
AC_OUTPUT

9
data/Makefile.am Normal file
View File

@ -0,0 +1,9 @@
dbusdir = /usr/share/dbus-1/services
dist_dbus_DATA = cn.kylinos.font.service \
cn.kylinos.mouse.service cn.kylinos.touchpad.service \
cn.kylinos.desktop.service \
cn.kylinos.background.service \
cn.kylinos.marcogeneral.service \
cn.kylinos.xkbgeneral.service cn.kylinos.interface.service cn.kylinos.keyboard.service \
cn.kylinos.power.service cn.kylinos.screensaver.service cn.kylinos.session.service \
$(NULL)

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.background
Exec=/usr/libexec/ukui-backgroundserver

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.background">
<method name="TransferBoolValue">
<arg name="InArg" direction="in" type="(sb)"/>
</method>
<method name="TransferStringValue">
<arg name="InArg" direction="in" type="(ss)"/>
</method>
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.desktop
Exec=/usr/libexec/ukui-desktopserver

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.desktop">
<method name="TransferBoolValue">
<arg name="InArg" direction="in" type="(sb)"/>
</method>
<method name="TransferStringValue">
<arg name="InArg" direction="in" type="(ss)"/>
</method>
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
</method>
</interface>
</node>

3
data/cn.kylinos.font.service Executable file
View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.font
Exec=/usr/libexec/ukui-fontserver

14
data/cn.kylinos.font.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.font">
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
</method>
<method name="TransferDoubleValue">
<arg name="InArg" direction="in" type="(sd)"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.interface
Exec=/usr/libexec/ukui-interfaceserver

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.interface">
<method name="TransferBoolValue">
<arg name="InArg" direction="in" type="(sb)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetBoolValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetIntValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="i"/>
</method>
<method name="TransferStringValue">
<arg name="InArg" direction="in" type="(ss)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetStringValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="s"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.keyboard
Exec=/usr/libexec/ukui-keyboardserver

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.keyboard">
<method name="TransferBoolValue">
<arg name="InArg" direction="in" type="(sb)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetBoolValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetIntValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="i"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.marcogeneral
Exec=/usr/libexec/ukui-marcogeneralserver

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.marcogeneral">
<method name="TransferStringValue">
<arg name="InArg" direction="in" type="(ss)"/>
</method>
</interface>
</node>

3
data/cn.kylinos.mouse.service Executable file
View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.mouse
Exec=/usr/libexec/ukui-mouseserver

47
data/cn.kylinos.mouse.xml Normal file
View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.mouse">
<method name="TransferBoolValue">
<arg name="InArg" direction="in" type="(sb)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetBoolValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="TransferStringValue">
<arg name="InArg" direction="in" type="(ss)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetStringValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="s"/>
</method>
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetIntValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="i"/>
</method>
<method name="TransferDoubleValue">
<arg name="InArg" direction="in" type="(sd)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetDoubleValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="d"/>
</method>
</interface>
</node>

3
data/cn.kylinos.power.service Executable file
View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.power
Exec=/usr/libexec/ukui-powerserver

11
data/cn.kylinos.power.xml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.power">
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.screensaver
Exec=/usr/libexec/ukui-screensaverserver

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.screensaver">
<method name="TransferBoolValue">
<arg name="InArg" direction="in" type="(sb)"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.session
Exec=/usr/libexec/ukui-sessionserver

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.session">
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.touchpad
Exec=/usr/libexec/ukui-touchpadserver

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.touchpad">
<method name="TransferBoolValue">
<arg name="InArg" direction="in" type="(sb)"/>
</method>
<method name="TransferIntValue">
<arg name="InArg" direction="in" type="(si)"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=cn.kylinos.xkbgeneral
Exec=/usr/libexec/ukui-xkbgeneralserver

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node>
<interface name="cn.kylinos.xkbgeneral">
<method name="TransferBoolValue">
<arg name="InArg" direction="in" type="(sb)"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
<method name="GetBoolValue">
<arg name="InArg" direction="in" type="s"/>
<arg name="OutArg" direction="out" type="b"/>
</method>
</interface>
</node>

2
po/LINGUAS Normal file
View File

@ -0,0 +1,2 @@
bo
zh_CN

0
po/Makefile.am Normal file
View File

41
po/Makevars Normal file
View File

@ -0,0 +1,41 @@
# Makefile variables for PO directory in any package using GNU gettext.
# Usually the message domain is the same as the package name.
DOMAIN = $(PACKAGE)
# These two variables depend on the location of this directory.
subdir = po
top_builddir = ..
# These options get passed to xgettext.
XGETTEXT_OPTIONS = --keyword=_ --keyword=N_
# This is the copyright holder that gets inserted into the header of the
# $(DOMAIN).pot file. Set this to the copyright holder of the surrounding
# package. (Note that the msgstr strings, extracted from the package's
# sources, belong to the copyright holder of the package.) Translators are
# expected to transfer the copyright for their translations to this person
# or entity, or to disclaim their copyright. The empty string stands for
# the public domain; in this case the translators are expected to disclaim
# their copyright.
COPYRIGHT_HOLDER = Kylin Teams
# This is the email address or URL to which the translators shall report
# bugs in the untranslated strings:
# - Strings which are not entire sentences, see the maintainer guidelines
# in the GNU gettext documentation, section 'Preparing Strings'.
# - Strings which use unclear terms or require additional context to be
# understood.
# - Strings which make invalid assumptions about notation of date, time or
# money.
# - Pluralisation problems.
# - Incorrect English spelling.
# - Incorrect formatting.
# It can be your email address, or a mailing list address where translators
# can write to without being subscribed, or the URL of a web page through
# which the translators can contact you.
MSGID_BUGS_ADDRESS = $(PACKAGE_BUGREPORT)
# This is the list of locale categories, beyond LC_MESSAGES, for which the
# message catalogs shall be used. It is usually empty.
EXTRA_LOCALE_CATEGORIES =

0
po/POTFILES.in Normal file
View File

18
po/zh_CN.po Normal file
View File

@ -0,0 +1,18 @@
# Chinese translations for ukui-interface package.
# Copyright (C) 2017 THE ukui-interface'S COPYRIGHT HOLDER
# This file is distributed under the same license as the ukui-interface package.
# droiing <droiing@dro-op>, 2017.
#
msgid ""
msgstr ""
"Project-Id-Version: ukui-interface 0.0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-11-28 15:00+0800\n"
"PO-Revision-Date: 2017-11-28 11:57+0800\n"
"Last-Translator: droiing <jianglinxuan@kylinos.cn>\n"
"Language-Team: Chinese (simplified)\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

5
src/Makefile.am Normal file
View File

@ -0,0 +1,5 @@
NULL =
SUBDIRS = accounts common hardware language network \
other personal security updates \
$(NULL)

1
src/accounts/Makefile.am Normal file
View File

@ -0,0 +1 @@
SUBDIRS=user

View File

@ -0,0 +1,25 @@
#Generata binary file
lib_LTLIBRARIES = libukui-usersetting.la
#gcc -wall: displays all the errors and warning information when compiling
#gcc -g: add the debugging code when compiling
COMM_CFS = -Wall -g
#Add the dependent source file for libukui-usersetting.la
libukui_usersetting_la_SOURCES = kylin-user-interface.c \
$(NULL)
#The header files that need to be installed
include_HEADERS= kylin-user-interface.h \
$(NULL)
#Additional C compiler flags
libukui_usersetting_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_usersetting_la_LDFLAGS= -lcrypt \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)

View File

@ -0,0 +1,316 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include<stdio.h>
#include<glib-2.0/gio/gio.h>
#include<glib-2.0/glib.h>
#include<stdbool.h>
#include<stdlib.h>
#include<string.h>
#include <crypt.h>
#include"kylin-user-interface.h"
static gchar
salt_char (GRand *rand)
{
gchar salt[] = "ABCDEFGHIJKLMNOPQRSTUVXYZ"
"abcdefghijklmnopqrstuvxyz"
"./0123456789";
return salt[g_rand_int_range (rand, 0, G_N_ELEMENTS (salt))];
}
static gchar *
make_crypted (const char *plain)
{
GString *salt;
gchar *result;
GRand *rand;
gint i;
rand = g_rand_new ();
salt = g_string_sized_new (21);
/* SHA 256 */
g_string_append (salt, "$6$");
for (i = 0; i < 16; i++) {
g_string_append_c (salt, salt_char (rand));
}
g_string_append_c (salt, '$');
result = g_strdup ((const gchar *)crypt(plain, salt->str));
g_string_free (salt, TRUE);
g_rand_free (rand);
return result;
}
//获取用户对象路径
static gchar *getpath(char *username)
{
GDBusProxy *account_proxy;
GVariant *result;
account_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
"/org/freedesktop/Accounts",
"org.freedesktop.Accounts", NULL, NULL);
result=g_dbus_proxy_call_sync(account_proxy, "FindUserByName",
g_variant_new("(s)", username),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
if(result!=NULL){
gchar *path = (char *)g_variant_get_data(result);
if (account_proxy){
g_object_unref(account_proxy);
}
return path;
}
else{
return NULL;
}
}
//添加新用户
void kylin_accounts_user_createuser(char *username, int accounttype, char *password, char *iconfile)
{
GError *error = NULL;
GError *pProxyError = NULL;
GVariant *result;
GDBusProxy *account_proxy;
account_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
"/org/freedesktop/Accounts",
"org.freedesktop.Accounts", NULL, &error);
if (error != NULL)
{
g_error("Could not connect to org.freedesktop.Accounts:%s\n",error->message);
if (account_proxy)
g_object_unref(account_proxy);
return;
}
//设置用户名
result=g_dbus_proxy_call_sync(account_proxy, "CreateUser",
g_variant_new("(ssi)", username, "", accounttype),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &pProxyError);
if (result != NULL)
{
char *crypted = make_crypted(password);
if(iconfile==NULL)
iconfile = "/usr/share/pixmaps/faces/stock_person.svg";
GDBusProxy *proxy;
GError * err = NULL;
char *path = (char *)g_variant_get_data(result);
proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
path,
"org.freedesktop.Accounts.User", NULL, &err);
//设置用户头像
g_dbus_proxy_call_sync(proxy, "SetIconFile",
g_variant_new("(s)", iconfile),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
//设置用户密码
g_dbus_proxy_call_sync(proxy, "SetPassword",
g_variant_new("(ss)", crypted, ""),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
//设置用户类型
g_dbus_proxy_call_sync(proxy, "SetAccountType",
g_variant_new("(i)", accounttype),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
if (proxy){
g_object_unref(proxy);
}
}
else{
g_warning("-----------%s had already existed----------",username);
}
if (account_proxy){
g_object_unref(account_proxy);
}
}
//设置自动登录
void kylin_accounts_user_autologin(char *username, bool login)
{
GError * err = NULL;
gchar *path=getpath(username);
if(path!=NULL){
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
path,
"org.freedesktop.Accounts.User", NULL, &err);
g_dbus_proxy_call_sync(proxy, "SetAutomaticLogin",
g_variant_new("(b)", login),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
if (proxy){
g_object_unref(proxy);
}
}
else{
g_warning("-----------%s does not existed----------",username);
}
}
//更改用户头像
void kylin_accounts_user_chgusericon(char *username, char *iconfile)
{
GError * err = NULL;
gchar *path=getpath(username);
if(path!=NULL){
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
path,
"org.freedesktop.Accounts.User", NULL, &err);
g_dbus_proxy_call_sync(proxy, "SetIconFile",
g_variant_new("(s)", iconfile),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
if (proxy){
g_object_unref(proxy);
}
}
else{
g_warning("-----------%s does not existed----------",username);
}
}
//更改用户密码
void kylin_accounts_user_chguserpasswd(char *username, char *password)
{
GError * err = NULL;
gchar *path=getpath(username);
if(path!=NULL){
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
path,
"org.freedesktop.Accounts.User", NULL, &err);
char *crypted = make_crypted(password);
g_dbus_proxy_call_sync(proxy, "SetPassword",
g_variant_new("(ss)", crypted, ""),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
if (proxy){
g_object_unref(proxy);
}
}
else{
g_warning("-----------%s does not existed----------",username);
}
}
//更改账户类型
void kylin_accounts_user_chgusertype(char *username, int accounttype)
{
GError * err = NULL;
gchar *path=getpath(username);
if(path!=NULL){
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
path,
"org.freedesktop.Accounts.User", NULL, &err);
g_dbus_proxy_call_sync(proxy, "SetAccountType",
g_variant_new("(i)", accounttype),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
if (proxy){
g_object_unref(proxy);
}
}
else{
g_warning("-----------%s does not existed----------",username);
}
}
//删除用户
void kylin_accounts_user_deleteuser(char *username, bool removefile)
{
GDBusProxy *account_proxy;
GDBusProxy *proxy;
GError * err = NULL;
gchar *path = getpath(username);
if(path!=NULL){
proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
path,
"org.freedesktop.Accounts.User", NULL, &err);
//获取用户账户的UID
GVariant *value = g_dbus_proxy_get_cached_property(proxy, "Uid");
gint uid = (gint)g_variant_get_uint64(value);
g_warning("-----------%d----------",uid);
account_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
NULL, "org.freedesktop.Accounts",
"/org/freedesktop/Accounts",
"org.freedesktop.Accounts", NULL, NULL);
//删除用户账户
g_dbus_proxy_call_sync(account_proxy, "DeleteUser",
g_variant_new("(xb)", uid, removefile),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
if (account_proxy){
g_object_unref(account_proxy);
}
if (proxy){
g_object_unref(proxy);
}
}
else{
g_warning("-----------%s does not existed----------",username);
}
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __USER_ACCOUNTS_H__
#define __USER_ACCOUNTS_H__
#include<stdbool.h>
#ifdef __cplusplus
extern "C"{
#endif
/*
* create new user.
* @username is the login name.
* @accounttype is the user type, "0" is the standard user, and "1" is the administrators.
* @password is the login password.
* @iconfile is the path of the user image.
*/
void kylin_accounts_user_createuser(char *username,
int accounttype,
char *password,
char *iconfile);
/*
* set to login automatically.
* @login can be set to true, indicating automatic login.
*/
void kylin_accounts_user_autologin(char *username, bool login);
/*
* change the user image.
* @iconfile is the path of the user image.
*/
void kylin_accounts_user_chgusericon(char *username,
char *iconfile);
/*
* change the user password.
* @password is the login password.
*/
void kylin_accounts_user_chguserpasswd(char *username,
char *password);
/*
* change the user type.
* @accounttype is the user type, "0" is the standard user, and "1" is the administrators.
*/
void kylin_accounts_user_chgusertype(char *username,
int accounttype);
/*
* delete the user.
* @remove represents whether to delete the user directory.
*/
void kylin_accounts_user_deleteuser(char *username,
bool removefile);
#ifdef __cplusplus
}
#endif
#endif

64
src/common/Makefile.am Normal file
View File

@ -0,0 +1,64 @@
#Generata binary file
lib_LTLIBRARIES = libukui-print.la libukui-gsettings.la libukui-com4c.la libukui-com4cxx.la
#gcc -wall: displays all the errors and warning information when compiling
#gcc -g: add the debugging code when compiling
COMM_CFS = -Wall -g
#Add the dependent source file for libukui-com4c.la
libukui_com4c_la_SOURCES = kylin-com4c.c \
kylin-ini.c \
$(NULL)
#Additional C compiler flags
libukui_com4c_la_CFLAGS= $(COMM_CFS) \
-liniparser \
$(NULL)
#Additional link objects
libukui_com4c_la_LDFLAGS= \
$(NULL)
#Add the dependent source file for libukui-com4cxx.la
libukui_com4cxx_la_SOURCES = kylin-com4cxx.cpp \
kylin-ini.c \
$(NULL)
#Additional CXX compiler flags
libukui_com4cxx_la_CXXFLAGS= $(COMM_CFS) \
-liniparser \
$(NULL)
#Additional C compiler flags
libukui_com4cxx_la_CFLAGS= $(COMM_CFS) \
$(NULL)
#Additional link objects
libukui_com4cxx_la_LDFLAGS= \
$(NULL)
#Add the dependent source file for libukui-print.la
libukui_print_la_SOURCES = kylin-print.c \
$(NULL)
#Add the dependent source file for libukui-gsettings.la
libukui_gsettings_la_SOURCES = kylin-gsettings-set.c \
$(NULL)
#The header files that need to be installed
include_HEADERS= \
kylin-com4c.h \
kylin-com4cxx.h \
kylin-print.h \
kylin-gsettings-set.h \
$(NULL)
#Additional C compiler flags
libukui_gsettings_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_gsettings_la_LDFLAGS= \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)

220
src/common/kylin-com4c.c Normal file
View File

@ -0,0 +1,220 @@
/*
* Copyright (C) 2021 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "kylin-com4c.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <iniparser/iniparser.h>
#include "kylin-ini.h"
#define LSB_RELEASE_FILE "/etc/lsb-release" /* lsb-release文件路径 */
#define OS_RELEASE_FILE "/etc/os-release" /* os-release文件路径 */
#define KYINFO_FILE "/etc/.kyinfo" /* kyinfo文件路径 */
#define CPUINFO_FILE "/proc/cpuinfo" /* cpuinfo文件路径 */
#define RELEASEFILE_LINE_MAX 256 /* 最大解析行行数 */
#define RELEASEFILE_LINE_MAX_LEN 256 /* 最大解析行长度 */
#define RELEASEFILE_KEY_MAX_LEN 128 /* 最大key长度 */
#define RELEASEFILE_VALUE_MAX_LEN 256 /* 最大value长度 预留'\0', '='*/
#define RELEASEFILE_SPLIT_EQUAL '=' /* key和value的分隔符 */
#define RELEASEFILE_SPLIT_COLON ':' /* key和value的分隔符 */
#define PROJECT_CODENAME "PROJECT_CODENAME"
#define CPUINFO_MODELNAME "model name"
// 根据key获取value成功返回 >0 否则 返回 <= 0
static int file_get_keyvalue(const char *path, const char *key, char *value, int value_max_len, const char chSplit)
{
if (path == NULL || key == NULL || value == NULL || value_max_len <= 0) {
return -1;
}
int ret = 0;
int cnt = 0;
int key_len = 0;
int line_len = 0;
int value_len = 0;
FILE *fp = NULL;
char line_buf[RELEASEFILE_LINE_MAX_LEN] = {0};
/* 合法性判断 */
if (NULL == path || NULL == key || NULL == value || 0 >= value_max_len) {
return -1;
}
key_len = strlen(key);
if (0 >= key_len || RELEASEFILE_KEY_MAX_LEN < key_len) {
return -2;
}
if (F_OK != access(path, F_OK)) {
return -3;
}
/* 打开文件 */
fp = fopen(path, "r");
if (NULL == fp) {
return -4;
}
/* 遍历行匹配Key */
while(NULL != fgets(line_buf, RELEASEFILE_LINE_MAX_LEN-1, fp)) {
line_len = strlen(line_buf);
if (line_len > key_len) {
/* 找到key */
//找到非空格的首字符
char *pStart = line_buf;
int nSplitIndex = 0;
while(pStart != (line_buf+line_len) && isspace(*pStart)) {
++pStart; ++nSplitIndex;
}
if (0 == strncmp(pStart, key, key_len)) {
pStart = pStart + key_len;
nSplitIndex = nSplitIndex + key_len;
//跳过空格字符
while(pStart != (line_buf+line_len) && isspace(*pStart)) {
++pStart; ++nSplitIndex;
}
if (pStart != (line_buf+line_len) && *pStart == chSplit) {
ret = 1;
key_len = nSplitIndex;
break;
}
}
}
memset(line_buf, 0, sizeof(line_buf));
/* 最大查找行限制 */
cnt++;
if (RELEASEFILE_LINE_MAX < cnt) {
break;
}
}
/* 关闭文件 */
fclose(fp);
fp = NULL;
/* 找到key返回value */
if (1 == ret) {
value_len = line_len - key_len - 1;
if (0 < value_len) {
if (value_len > value_max_len) {
value_len = value_max_len;
}
/* 拷贝value */
snprintf(value, value_max_len, "%s", &line_buf[key_len + 1]);
value[value_len] = '\0';
/* 去掉结尾的换行符 */
strstrip(value, 1);
} else {
value[0] = '\0';
}
}
return ret;
}
/**
* @fn kdk_get_xdgsessiontype
* @brief x11与wayland的环境变量值
* @retval char* !NULL
*/
char* kdk_get_xdgsessiontype()
{
return getenv("XDG_SESSION_TYPE");
}
int kdk_get_lsbrelease(const char *key, char *value, int value_max_len)
{
int nRet = -1;
if (NULL == key || NULL == value || 0 >= value_max_len)
return nRet;
dictionary *iniHandle = iniparser_load(LSB_RELEASE_FILE);
if (iniHandle) {
char sessionKey[256] = {0};
snprintf(sessionKey, 256, ":%s", key);
const char *tempValue = iniparser_getstring(iniHandle, sessionKey, "");
snprintf(value, value_max_len, "%s", tempValue);
iniparser_freedict(iniHandle);
iniHandle = NULL;
nRet = strlen(value);
}
return nRet;
}
int kdk_get_osrelease(const char *key, char *value, int value_max_len)
{
int nRet = -1;
if (NULL == key || NULL == value || 0 >= value_max_len)
return nRet;
dictionary *iniHandle = iniparser_load(OS_RELEASE_FILE);
if (iniHandle) {
char sessionKey[256] = {0};
snprintf(sessionKey, 256, ":%s", key);
const char *tempValue = iniparser_getstring(iniHandle, sessionKey, "");
snprintf(value, value_max_len, "%s", tempValue);
iniparser_freedict(iniHandle);
iniHandle = NULL;
nRet = strlen(value);
}
return nRet;
}
int kdk_get_prjcodename(char *value, int value_max_len)
{
int nResult = kdk_get_lsbrelease(PROJECT_CODENAME, value, value_max_len);
if (nResult <= 0) {
nResult = kdk_get_osrelease(PROJECT_CODENAME, value, value_max_len);
}
return nResult;
}
int kdk_get_kyinfo(const char *session, const char *key, char *value, int value_max_len)
{
int nRet = -1;
if (NULL == session || NULL == key || NULL == value || 0 >= value_max_len)
return nRet;
dictionary *iniHandle = iniparser_load(KYINFO_FILE);
if (iniHandle) {
char sessionKey[256] = {0};
snprintf(sessionKey, 256, "%s:%s", session, key);
const char *tempValue = iniparser_getstring(iniHandle, sessionKey, "");
snprintf(value, value_max_len, "%s", tempValue);
iniparser_freedict(iniHandle);
iniHandle = NULL;
nRet = strlen(value);
}
return nRet;
}
int kdk_get_cpumodelname(char *modelName, int max_len)
{
return file_get_keyvalue(CPUINFO_FILE, CPUINFO_MODELNAME, modelName, max_len, RELEASEFILE_SPLIT_COLON);
}
int kdk_get_spechdplatform(char *platformName, int max_len)
{
if (platformName == NULL || max_len <= 0)
return -1;
char strDefault[128] = "default";
int validLen = strlen(strDefault);
validLen = validLen > max_len ? max_len : validLen;
snprintf(platformName, max_len, "%s", strDefault);
return validLen;
}

90
src/common/kylin-com4c.h Normal file
View File

@ -0,0 +1,90 @@
/*
* Copyright (C) 2021 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINCOMM4C_H__
#define __KYLINCOMM4C_H__
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @fn kdk_get_lsbrelease
* @brief lsbrelease信息的键获取值
* @param[in] key lsbrelease信息的键
* @param[out] value lsbrelease信息的值
* @param[in] value_max_len
* @retval int > 0
*/
int kdk_get_lsbrelease(const char *key, char *value, int value_max_len);
/**
* @fn kdk_get_osrelease
* @brief osrelease信息的键获取值
* @param[in] key osrelease信息的键
* @param[out] value osrelease信息的值
* @param[in] value_max_len
* @retval int > 0
*/
int kdk_get_osrelease(const char *key, char *value, int value_max_len);
/**
* @fn kdk_get_kyinfo
* @brief kyinfo的键获取值
* @param[in] session kyinfo的session值
* @param[in] key kyinfo的键
* @param[out] value kyinfo的值
* @param[in] value_max_len
* @retval int >= 0
*/
int kdk_get_kyinfo(const char *session, const char *key, char *value, int value_max_len);
/**
* @fn kdk_get_prjcodename
* @brief PROJECT_CODENAME字段的值
* @param[out] value PROJECT_CODENAME字段的值
* @param[in] value_max_len
* @retval int > 0
*/
int kdk_get_prjcodename(char *value, int value_max_len);
/**
* @fn kdk_get_cpumodelname
* @brief CPU型号
* @param[out] modelName CPU型号信息
* @param[in] max_len CPU型号缓存区的大小
* @retval int > 0
*/
int kdk_get_cpumodelname(char *modelName, int max_len);
/**
* @fn kdk_get_spechdplatform
* @brief
* @param[out] platformName
* @param[in] max_len
* @retval int > 0
*/
int kdk_get_spechdplatform(char *platformName, int max_len);
#ifdef __cplusplus
}
#endif
#endif // __KYLINCOMM4C_H__

View File

@ -0,0 +1,223 @@
/*
* Copyright (C) 2021 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "kylin-com4cxx.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <iniparser/iniparser.h>
#include "kylin-ini.h"
#define LSB_RELEASE_FILE "/etc/lsb-release" /* lsb-release文件路径 */
#define OS_RELEASE_FILE "/etc/os-release" /* os-release文件路径 */
#define KYINFO_FILE "/etc/.kyinfo" /* kyinfo文件路径 */
#define CPUINFO_FILE "/proc/cpuinfo" /* cpuinfo文件路径 */
#define RELEASEFILE_LINE_MAX 256 /* 最大解析行行数 */
#define RELEASEFILE_LINE_MAX_LEN 256 /* 最大解析行长度 */
#define RELEASEFILE_KEY_MAX_LEN 128 /* 最大key长度 */
#define RELEASEFILE_VALUE_MAX_LEN 256 /* 最大value长度 预留'\0', '='*/
#define RELEASEFILE_SPLIT_EQUAL '=' /* key和value的分隔符 */
#define RELEASEFILE_SPLIT_COLON ':' /* key和value的分隔符 */
#define PROJECT_CODENAME "PROJECT_CODENAME"
#define CPUINFO_MODELNAME "model name"
// 根据key获取value成功返回 >0 否则 返回 <= 0
static int file_get_keyvalue(const char *path, const char *key, char *value, int value_max_len, const char chSplit)
{
if (path == NULL || key == NULL || value == NULL || value_max_len <= 0) {
return -1;
}
int ret = 0;
int cnt = 0;
int key_len = 0;
int line_len = 0;
int value_len = 0;
FILE *fp = NULL;
char line_buf[RELEASEFILE_LINE_MAX_LEN] = {0};
/* 合法性判断 */
if (NULL == path || NULL == key || NULL == value || 0 >= value_max_len) {
return -1;
}
key_len = strlen(key);
if (0 >= key_len || RELEASEFILE_KEY_MAX_LEN < key_len) {
return -2;
}
if (F_OK != access(path, F_OK)) {
return -3;
}
/* 打开文件 */
fp = fopen(path, "r");
if (NULL == fp) {
return -4;
}
/* 遍历行匹配Key */
while(NULL != fgets(line_buf, RELEASEFILE_LINE_MAX_LEN-1, fp)) {
line_len = strlen(line_buf);
if (line_len > key_len) {
/* 找到key */
//找到非空格的首字符
char *pStart = line_buf;
int nSplitIndex = 0;
while(pStart != (line_buf+line_len) && isspace(*pStart)) {
++pStart; ++nSplitIndex;
}
if (0 == strncmp(pStart, key, key_len)) {
pStart = pStart + key_len;
nSplitIndex = nSplitIndex + key_len;
//跳过空格字符
while(pStart != (line_buf+line_len) && isspace(*pStart)) {
++pStart; ++nSplitIndex;
}
if (pStart != (line_buf+line_len) && *pStart == chSplit) {
ret = 1;
key_len = nSplitIndex;
break;
}
}
}
memset(line_buf, 0, sizeof(line_buf));
/* 最大查找行限制 */
cnt++;
if (RELEASEFILE_LINE_MAX < cnt) {
break;
}
}
/* 关闭文件 */
fclose(fp);
fp = NULL;
/* 找到key返回value */
if (1 == ret) {
value_len = line_len - key_len - 1;
if (0 < value_len) {
if (value_len > value_max_len) {
value_len = value_max_len;
}
/* 拷贝value */
snprintf(value, value_max_len, "%s", &line_buf[key_len + 1]);
value[value_len] = '\0';
/* 去掉结尾的换行符 */
strstrip(value, 1);
} else {
value[0] = '\0';
}
}
return ret;
}
/**
* @fn KDKGetXdgSessionType
* @brief x11与wayland的环境变量值
* @param None
* @retval string xdg会话类型字符串,empty
*/
string KDKGetXdgSessionType()
{
char *strSessionType = getenv("XDG_SESSION_TYPE");
if (!strSessionType) {
return "";
}
return string(strSessionType);
}
string KDKGetLSBRelease(const string key)
{
if (key.empty()) {
return "";
}
dictionary *iniHandle = iniparser_load(LSB_RELEASE_FILE);
if (iniHandle) {
string sessionKey = ":"+key;
string strValue = "";
strValue = iniparser_getstring(iniHandle, sessionKey.c_str(), "");
iniparser_freedict(iniHandle);
iniHandle = NULL;
return strValue;
}
return "";
}
string KDKGetOSRelease(const string key)
{
if (key.empty()) {
return "";
}
dictionary *iniHandle = iniparser_load(OS_RELEASE_FILE);
if (iniHandle) {
string sessionKey = ":"+key;
string strValue = "";
strValue = iniparser_getstring(iniHandle, sessionKey.c_str(), "");
iniparser_freedict(iniHandle);
iniHandle = NULL;
return strValue;
}
return "";
}
string KDKGetPrjCodeName()
{
string strValue = KDKGetLSBRelease(PROJECT_CODENAME);
if (strValue.empty()) {
strValue = KDKGetOSRelease(PROJECT_CODENAME);
}
return strValue;
}
string KDKGetKYInfo(const string session, const string key)
{
if (session.empty() || key.empty()) {
return "";
}
dictionary *iniHandle = iniparser_load(KYINFO_FILE);
if (iniHandle) {
string sessionKey = session+":"+key;
string strValue = "";
strValue = iniparser_getstring(iniHandle, sessionKey.c_str(), "");
iniparser_freedict(iniHandle);
iniHandle = NULL;
return strValue;
}
return "";
}
string KDKGetCpuModelName()
{
char strValue[256] = {0};
int nRet = file_get_keyvalue(CPUINFO_FILE, CPUINFO_MODELNAME, strValue, 256, RELEASEFILE_SPLIT_COLON);
if (nRet > 0) {
return string(strValue);
} else {
return "";
}
}
string KDKGetSpecHDPlatform()
{
string strDefaultValue = "default";
return strDefaultValue;
}

View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2021 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINCOMM4CXX_H__
#define __KYLINCOMM4CXX_H__
#include <string>
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
/**
* @fn KDKGetLsbRelease
* @brief lsbrelease信息的键获取值
* @param[in] key lsbrelease信息的键
* @param[out] value lsbrelease信息的值
* @param[in] value_max_len
* @retval string lsbrelease信息的值,empty
*/
string KDKGetLSBRelease(const string key);
/**
* @fn KDKGetOSRelease
* @brief osrelease信息的键获取值
* @param[in] key osrelease信息的键
* @retval string osrelease信息的值,empty
*/
string KDKGetOSRelease(const string key);
/**
* @fn KDKGetKYInfo
* @brief kyinfo的键获取值
* @param[in] session kyinfo的session值
* @param[in] key kyinfo的键
* @retval string kyinfo信息的键值,empty
*/
string KDKGetKYInfo(const string session, const string key);
/**
* @fn KDKGetPrjCodeName
* @brief PROJECT_CODENAME字段的值
* @param None
* @retval string PROJECT_CODENAME字段的值,empty
*/
string KDKGetPrjCodeName();
/**
* @fn KDKGetCpuModelName
* @brief CPU型号
* @param None
* @retval string CPU型号信息,empty
*/
string KDKGetCpuModelName();
/**
* @fn KDKGetSpecHDPlatform
* @brief
* @param None
* @retval string ,empty
*/
string KDKGetSpecHDPlatform();
#ifdef __cplusplus
}
#endif
#endif // __KYLINCOMM4C_H__

View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include "kylin-gsettings-set.h"
#include <gio/gio.h>
#include <stdbool.h>
//Creates a new GSsetting object with the schema specified by schema_id
GSettings *gsettings_get_schemaID(const gchar *schemaID)
{
GSettings *settings = g_settings_new(schemaID);
return settings;
}
//Sets int_key in settings to value
bool gsettings_set_int(GSettings *settings, const gchar *key, gint value)
{
bool ret=g_settings_set_int(settings, key, value);
return ret;
}
//Sets boolean_key in settings to value
bool gsettings_set_boolean(GSettings *settings, const gchar *key, gboolean value)
{
bool ret=g_settings_set_boolean(settings,key,value);
return ret;
}
//Sets double_key in settings to value
bool gsettings_set_double(GSettings *settings, const gchar *key, gdouble value)
{
bool ret=g_settings_set_double(settings, key, value);
return ret;
}
//Sets string_key in settings to value
bool gsettings_set_string(GSettings *settings, const gchar *key, const gchar *value)
{
bool ret=g_settings_set_string(settings, key, value);
return ret;
}
//Sets enum_key in settings to value
bool gsettings_set_enum(GSettings *settings, const gchar *key, gint value)
{
bool ret=g_settings_set_enum(settings, key, value);
return ret;
}
//Decreases the reference count of setting
void Dec_ref(GSettings *setting)
{
g_object_unref(setting);
}
//fix library-not-linked-against-libc by lintian
void fun()
{
printf("fun\n");
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINGSETTINGSSET_H__
#define __KYLINGSETTINGSSET_H__
#include <stdio.h>
#include <gio/gio.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
//Creates a new GSsetting object with the schema specified by schema_id
GSettings *gsettings_get_schemaID(const gchar *schemaID);
//Sets int_key in settings to value
bool gsettings_set_int(GSettings *settings, const gchar *key, gint value);
//Sets boolean_key in settings to value
bool gsettings_set_boolean(GSettings *settings, const gchar *key, gboolean value);
//Sets double_key in settings to value
bool gsettings_set_double(GSettings *settings, const gchar *key, gdouble value);
//Sets string_key in settings to value
bool gsettings_set_string(GSettings *settings, const gchar *key, const gchar *value);
//Sets enum_key in settings to value
bool gsettings_set_enum(GSettings *settings, const gchar *key, gint value);
//Decreases the reference count of setting
void Dec_ref(GSettings *setting);
#ifdef __cplusplus
}
#endif
#endif

83
src/common/kylin-ini.c Normal file
View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2021 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "kylin-ini.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
//去除尾部空白字符 包括\t \n \r
/*
' ' (0x20) space (SPC)
'\t' (0x09) horizontal tab (TAB)
'\n' (0x0a) newline (LF)
'\v' (0x0b) vertical tab (VT)
'\f' (0x0c) feed (FF)
'\r' (0x0d) carriage return (CR)
//windows \r\n linux \n mac \r
*/
char *strstripr(char *str, int containQuot)
{
if(str == NULL || *str == '\0') {
return str;
}
int len = strlen(str);
char *p = str + len - 1;
if (containQuot) {
while(p >= str && (isspace(*p) || *p == '\"')) {
*p = '\0'; --p;
}
} else {
while(p >= str && isspace(*p)) {
*p = '\0'; --p;
}
}
return str;
}
//去除首部空格
char *strstripl(char *str, int containQuot)
{
if(str == NULL || *str == '\0') {
return str;
}
int len = 0;
char *p = str;
if (containQuot) {
while(*p != '\0' && (isspace(*p) || *p == '\"')) {
++p; ++len;
}
} else {
while(*p != '\0' && isspace(*p)) {
++p; ++len;
}
}
memmove(str, p, strlen(str) - len + 1);
return str;
}
//去除首尾空格
char *strstrip(char *str, int containQuot)
{
str = strstripr(str, containQuot);
str = strstripl(str, containQuot);
return str;
}

42
src/common/kylin-ini.h Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright (C) 2021 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLININI_H__
#define __KYLININI_H__
#include <stdio.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
// 去除尾部空格
char *strstripr(char *str, int containQuot);
// 去除头部空格
char *strstripl(char *str, int containQuot);
// 去除前后空格
char *strstrip(char *str, int containQuot);
#ifdef __cplusplus
}
#endif
#endif //__KYLININI_H__

174
src/common/kylin-print.c Normal file
View File

@ -0,0 +1,174 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include<stdio.h>
#include "kylin-print.h"
#include <stdarg.h>
#include<stdlib.h>
int vprint_by_level(int print_level, FILE * __restrict stream,
char * __restrict format, va_list args)
{
int ret = 0;
int level_int = 0;
level_int = PRINT_LEVEL_DEFAULT;
if (print_level <= level_int)
{
switch (print_level)
{
case PRINT_LEVEL_EMERG:
case PRINT_LEVEL_ALERT:
case PRINT_LEVEL_CRIT:
case PRINT_LEVEL_ERROR:
fprintf(stderr, "%s", PRINT_COLOR_RED);
break;
case PRINT_LEVEL_WARN:
fprintf(stdout, "%s", PRINT_COLOR_PURPLE);
break;
case PRINT_LEVEL_NOTICE:
fprintf(stdout, "%s", PRINT_COLOR_BLUE);
break;
case PRINT_LEVEL_INFO:
fprintf(stdout, "%s", PRINT_COLOR_CYAN);
break;
case PRINT_LEVEL_DEBUG:
fprintf(stdout, "%s", PRINT_COLOR_YELLOW);
break;
default:
fprintf(stdout, "%s", PRINT_COLOR_WHITE);
}
switch (print_level)
{
case PRINT_LEVEL_EMERG:
fprintf(stderr, "[EMERG] ");
break;
case PRINT_LEVEL_ALERT:
fprintf(stderr, "[ALERT] ");
break;
case PRINT_LEVEL_CRIT:
fprintf(stderr, "[CRIT] ");
break;
case PRINT_LEVEL_ERROR:
fprintf(stderr, "[ERROR] ");
break;
case PRINT_LEVEL_WARN:
fprintf(stdout, "[WARN] ");
break;
case PRINT_LEVEL_NOTICE:
fprintf(stdout, "[NOTE] ");
break;
case PRINT_LEVEL_INFO:
fprintf(stdout, "[INFO] ");
break;
case PRINT_LEVEL_DEBUG:
fprintf(stdout, "[DEBUG] ");
break;
default:
fprintf(stdout, "[UKNOW] ");
}
ret = vfprintf(stream, format, args);
if (print_level <= PRINT_LEVEL_ERROR && print_level >= 0)
fprintf(stderr, "%s", PRINT_COLOR_END);
else
fprintf(stdout, "%s", PRINT_COLOR_END);
}
return ret;
}
int print_by_level(int print_level, FILE * stream, char * format, ...)
{
int ret = 0;
va_list args;
va_start(args, format);
ret = vprint_by_level(print_level, stream, format, args);
va_end(args);
return ret;
}
int print_debug(char * format, ...)
{
int ret = 0;
va_list args;
va_start(args, format);
ret = vprint_by_level(PRINT_LEVEL_DEBUG, stdout, format, args);
va_end(args);
return ret;
}
int print_info(char * format, ...)
{
int ret = 0;
va_list args;
va_start(args, format);
ret = vprint_by_level(PRINT_LEVEL_INFO, stdout, format, args);
va_end(args);
return ret;
}
int print_notice(char * format, ...)
{
int ret = 0;
va_list args;
va_start(args, format);
ret = vprint_by_level(PRINT_LEVEL_NOTICE, stdout, format, args);
va_end(args);
return ret;
}
int print_warning(char * format, ...)
{
int ret = 0;
va_list args;
va_start(args, format);
ret = vprint_by_level(PRINT_LEVEL_WARN, stdout, format, args);
va_end(args);
return ret;
}
int print_error(char * format, ...)
{
int ret = 0;
va_list args;
va_start(args, format);
ret = vprint_by_level(PRINT_LEVEL_ERROR, stderr, format, args);
va_end(args);
return ret;
}

66
src/common/kylin-print.h Normal file
View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINPRINT_H__
#define __KYLINPRINT_H__
#include<stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define PRINT_LEVEL_EMERG 0
#define PRINT_LEVEL_ALERT 1
#define PRINT_LEVEL_CRIT 2
#define PRINT_LEVEL_ERROR 3 // 错误信息
#define PRINT_LEVEL_WARN 4 // 警告信息
#define PRINT_LEVEL_NOTICE 5 // 提示信息
#define PRINT_LEVEL_INFO 6 // 运行时信息
#define PRINT_LEVEL_DEBUG 7 // 调试信息
//#define PRINT_LEVEL_DEFAULT PRINT_LEVEL_NOTICE // 默认输出信息等级
#define PRINT_LEVEL_DEFAULT PRINT_LEVEL_DEBUG
//#define PRINT_LEVEL_ENV "PRINT_LEVEL" // 控制信息等级的环境变量
#define PRINT_LEVEL_COLOR "PRINT_COLOR" // 控制信息颜色的环境变量
#define PRINT_COLOR_BLACK "\033[01;30m"
#define PRINT_COLOR_RED "\033[01;31m"
#define PRINT_COLOR_GREEN "\033[01;32m"
#define PRINT_COLOR_YELLOW "\033[01;33m"
#define PRINT_COLOR_BLUE "\033[01;34m"
#define PRINT_COLOR_PURPLE "\033[01;35m"
#define PRINT_COLOR_CYAN "\033[01;36m"
#define PRINT_COLOR_WHITE "\033[01;36m"
#define PRINT_COLOR_END "\033[0m"
int vprint_by_level(int print_level, FILE * __restrict stream,
char * __restrict format, va_list args);
int print_by_level(int print_level, FILE * stream, char * format, ...);
int print_debug(char * format, ...);
int print_info(char * format, ...);
int print_notice(char * format, ...);
int print_warning(char * format, ...);
int print_error(char * format, ...);
#ifdef __cplusplus
}
#endif
#endif

1
src/date/Makefile.am Normal file
View File

@ -0,0 +1 @@
SUBDIRS=dttm

25
src/date/dttm/Makefile.am Normal file
View File

@ -0,0 +1,25 @@
#Generata binary file
lib_LTLIBRARIES = libukui-datesetting.la
#gcc -wall: displays all the errors and warning information when compiling
#gcc -g: add the debugging code when compiling
COMM_CFS = -Wall -g
#Add the dependent source file for libukui-datesetting.la
libukui_datesetting_la_SOURCES = kylin-date-interface.c \
$(NULL)
#The header files that need to be installed
include_HEADERS= kylin-date-interface.h \
$(NULL)
#Additional C compiler flags
libukui_datesetting_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_datesetting_la_LDFLAGS= \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)

View File

@ -0,0 +1,198 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include <glib-2.0/gio/gio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <glib-2.0/glib.h>
#include "kylin-date-interface.h"
#include<stdbool.h>
#define USE_24_FORMAT "use-24h-format"
#define schemaID "org.mate.panel.indicator.calendar"
#define TZ_DATA_FILE "/usr/share/zoneinfo/zone_utc"
typedef struct _TimeDate TimeDate;
typedef struct _TzDB TzDB;
//typedef struct _TzLocation TzLocation;
typedef struct _TzUTC TzUTC;
TimeDate timedata;
struct _TzUTC{
GPtrArray *tz_rtc;
gchar *tz_utc;
};
struct _TzDB {
GPtrArray *locations;
};
struct _TimeDate {
TzDB *tzdb;
};
//Initialize the time zone database.
TzDB *init_timedb (){
gchar *tz_data_file;
TzDB *tz_db;
FILE *tzfile;
char buf[4096];
tz_data_file = TZ_DATA_FILE;
if (!tz_data_file){
g_warning("Could not get timedb source\n");
return NULL;
}
tzfile = fopen(tz_data_file, "r");
if (!tzfile) {
g_warning("Could not open tzfile *%s*\n",tz_data_file);
// g_free(tz_data_file);
return NULL;
}
tz_db = g_new0(TzDB, 1);
tz_db->locations = g_ptr_array_new();
while(fgets(buf, sizeof(buf), tzfile)){
gchar **tmpstrarr;
TzUTC *loc;
loc = g_new0(TzUTC, 1);
loc->tz_rtc = g_ptr_array_new();
g_strchomp(buf);
tmpstrarr = g_strsplit(buf, "\t",2);
gchar ***tmp_rtc = g_strsplit(tmpstrarr[0], " ", 6);
for(int i =0; i!=6; ++i){
if(tmp_rtc[i] != NULL){
g_ptr_array_add (loc->tz_rtc, (gpointer)g_strdup(tmp_rtc[i]));
}
else
break;
}
loc->tz_utc = g_strdup(tmpstrarr[1]);
g_ptr_array_add (tz_db->locations, loc);
g_strfreev(tmp_rtc);
g_strfreev(tmpstrarr);
}
fclose(tzfile);
return tz_db;
}
//Modify the time zone
void kylin_date_dt_settz(char * location){
gchar *rtc;
TzUTC *tmp;
GPtrArray *translate;
timedata.tzdb= init_timedb();
translate = timedata.tzdb->locations;
if(!strcmp(getenv("LANG"), "en_US.UTF-8"))
rtc = location;
else{
for(int i=0; i != timedata.tzdb->locations->len; ++i){
tmp = g_ptr_array_index(timedata.tzdb->locations, i);
if(tmp->tz_utc && strcmp(tmp->tz_utc, location) == 0){
rtc = g_ptr_array_index(tmp->tz_rtc,0);
break;
}
}
}
GError *error=NULL;
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,NULL,
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
NULL,&error);
if (error !=NULL) {
g_warning("Error :%s\n",error->message);
}
g_dbus_proxy_call_sync(proxy, "SetTimezone", g_variant_new("(sb)", rtc, TRUE),
G_DBUS_CALL_FLAGS_NONE, -1,NULL, NULL);
// g_free(location);
return;
}
//Change the system date and time.
void kylin_date_dt_chgdt(unsigned year,unsigned month,unsigned day, unsigned hour, unsigned minute, unsigned second){
GDateTime *now;
gint64 newtime;
if(hour>23)
hour = hour -12;
now = g_date_time_new_local(year,month,day,hour,minute,(gdouble)second);
newtime = g_date_time_to_unix(now);
GError *error=NULL;
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,NULL, "org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
NULL,&error);
if (error !=NULL) {
g_warning("Error :%s\n",error->message);
}
g_dbus_proxy_call_sync(proxy, "SetTime", g_variant_new("(xbb)", (newtime * G_TIME_SPAN_SECOND), FALSE,TRUE),
G_DBUS_CALL_FLAGS_NONE,-1,NULL,NULL);
}
//Whether to enable network time synchronization.
void kylin_date_dt_setnetsync(int timesetting)
{
GError *error=NULL;
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,NULL,
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
NULL,&error);
if (error !=NULL) {
g_warning("Error :%s\n",error->message);
}
if (timesetting == 0){
g_dbus_proxy_call_sync(proxy, "SetNTP", g_variant_new("(bb)", FALSE, TRUE),
G_DBUS_CALL_FLAGS_NONE, -1,NULL, NULL);
}else {
g_dbus_proxy_call_sync(proxy, "SetNTP", g_variant_new("(bb)", TRUE, TRUE),
G_DBUS_CALL_FLAGS_NONE, -1,NULL, NULL);
}
}
//Whether to enable time format.
void kylin_date_dt_sethrfmt(bool value)
{
GSettings *setting=g_settings_new(schemaID);
g_settings_set_boolean(setting,USE_24_FORMAT,value);
g_object_unref(setting);
g_settings_sync();
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINDATEINTERFACE_H__
#define __KYLINDATEINTERFACE_H__
#include<stdbool.h>
#ifdef __cplusplus
extern "C"{
#endif
/*
* Modify the time zone.
* @location is the time zone.Referring to the file "/usr/share/zoneinfo/zone_utc".
* e.g. gchar *location="(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐";
*/
void kylin_date_dt_settz(char *location);
/*
* Change the system date and time.
* @Parameter represents the date and time you want to set.
*/
void kylin_date_dt_chgdt(unsigned year,
unsigned month,
unsigned day,
unsigned hour,
unsigned minute,
unsigned second);
/*
* Whether to enable network time synchronization.
* @timesetting can be equal to 1 or 0.
*/
void kylin_date_dt_setnetsync(int timesetting);
/*
* Whether to enable time format.
*/
void kylin_date_dt_sethrfmt(bool value);
#ifdef __cplusplus
}
#endif
#endif

1
src/hardware/Makefile.am Executable file
View File

@ -0,0 +1 @@
SUBDIRS=mouse keyboard power touchpad

View File

@ -0,0 +1,115 @@
COMM_PRINT= -L$(top_srcdir)/src/common -lukui-print
COMM_GSETTINGS= -L$(top_srcdir)/src/common -lukui-gsettings
#generate the .c and .h file which used by client and server side by XML file
#$(top_srcdir) represents the top-level directory of the project
GENE_XML = $(top_srcdir)/data/cn.kylinos.xkbgeneral.xml
INTE_XML = $(top_srcdir)/data/cn.kylinos.interface.xml
KEY_XML = $(top_srcdir)/data/cn.kylinos.keyboard.xml
GENERATED_GENE = xkbgeneral-generated
GENERATED_INTE = interface-generated
GENERATED_KEY = keyboard-generated
xkbgeneral-generated.h xkbgeneral-generated.c: $(GENE_XML)
gdbus-codegen --interface-prefix cn.kylinos --generate-c-code $(GENERATED_GENE) $(GENE_XML)
interface-generated.h interface-generated.c: $(INTE_XML)
gdbus-codegen --interface-prefix cn.kylinos. --generate-c-code $(GENERATED_INTE) $(INTE_XML)
keyboard-generated.h keyboard-generated.c: $(KEY_XML)
gdbus-codegen --interface-prefix cn.kylinos. --generate-c-code $(GENERATED_KEY) $(KEY_XML)
#Generata binary file
lib_LTLIBRARIES = libukui-interfaceclient.la libukui-keyboardclient.la
#gcc -wall: displays all the errors and warning information when compiling
#gcc -g: add the debugging code when compiling
COMM_CFS = -Wall -g
#The header files that need to be installed
include_HEADERS= kylin-interface-interface.h \
kylin-keyboard-interface.h \
$(NULL)
#Add the dependent source file for libinterfaceclient.la
#interface-generated.c must be front of kylin-interface-interface.c
libukui_interfaceclient_la_SOURCES = interface-generated.c kylin-interface-interface.c \
$(NULL)
#Additional C compiler flags
libukui_interfaceclient_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_interfaceclient_la_LDFLAGS= $(COMM_PRINT) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Add the dependent source file for libkeyboardclient.la
#keyboard-generated.c must be front of kylin-keyboard-interface.c
libukui_keyboardclient_la_SOURCES = keyboard-generated.c kylin-keyboard-interface.c \
$(NULL)
#Additional C compiler flags
libukui_keyboardclient_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_keyboardclient_la_LDFLAGS= $(COMM_PRINT) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Generata binary file
bin_PROGRAMS =ukui-xkbgeneralserver ukui-interfaceserver ukui-keyboardserver
#Add the dependent source file for xkbgeneralserver
ukui_xkbgeneralserver_SOURCES = \
xkbgeneral-generated.h xkbgeneral-generated.c \
kylin-xkbgeneral-server.c \
$(NULL)
#Additional C compiler flags
ukui_xkbgeneralserver_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
ukui_xkbgeneralserver_LDFLAGS= $(COMM_PRINT) $(COMM_GSETTINGS) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Add the dependent source file for interfaceserver
ukui_interfaceserver_SOURCES = \
interface-generated.h interface-generated.c \
kylin-interface-server.c \
$(NULL)
#Additional C compiler flags
ukui_interfaceserver_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
ukui_interfaceserver_LDFLAGS= $(COMM_PRINT) $(COMM_GSETTINGS) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Add the dependent source file for keyboardserver
ukui_keyboardserver_SOURCES = \
keyboard-generated.h keyboard-generated.c \
kylin-keyboard-server.c \
$(NULL)
#Additional C compiler flags
ukui_keyboardserver_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
ukui_keyboardserver_LDFLAGS= $(COMM_PRINT) $(COMM_GSETTINGS) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __INTERFACEDBUS_H__
#define __INTERFACEDBUS_H__
#include <gio/gio.h> /* Bus define */
#ifdef __cplusplus
extern "C" {
#endif
#define INTERFACE_BUS G_BUS_TYPE_SESSION
#define INTERFACE_BUS_NAME "cn.kylinos.interface"
#define INTERFACE_OBJECT_PATH "/cn/kylinos/interface"
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,343 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __INTERFACE_GENERATED_H__
#define __INTERFACE_GENERATED_H__
#include <gio/gio.h>
G_BEGIN_DECLS
/* ------------------------------------------------------------------------ */
/* Declarations for cn.kylinos.interface */
#define TYPE_INTERFACE (interface_get_type ())
#define INTERFACE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_INTERFACE, Interface))
#define IS_INTERFACE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_INTERFACE))
#define INTERFACE_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), TYPE_INTERFACE, InterfaceIface))
struct _Interface;
typedef struct _Interface Interface;
typedef struct _InterfaceIface InterfaceIface;
struct _InterfaceIface
{
GTypeInterface parent_iface;
gboolean (*handle_get_bool_value) (
Interface *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_get_int_value) (
Interface *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_get_string_value) (
Interface *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_transfer_bool_value) (
Interface *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
gboolean (*handle_transfer_int_value) (
Interface *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
gboolean (*handle_transfer_string_value) (
Interface *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
};
GType interface_get_type (void) G_GNUC_CONST;
GDBusInterfaceInfo *interface_interface_info (void);
guint interface_override_properties (GObjectClass *klass, guint property_id_begin);
/* D-Bus method call completion functions: */
void interface_complete_transfer_bool_value (
Interface *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void interface_complete_get_bool_value (
Interface *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void interface_complete_transfer_int_value (
Interface *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void interface_complete_get_int_value (
Interface *object,
GDBusMethodInvocation *invocation,
gint OutArg);
void interface_complete_transfer_string_value (
Interface *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void interface_complete_get_string_value (
Interface *object,
GDBusMethodInvocation *invocation,
const gchar *OutArg);
/* D-Bus method calls: */
void interface_call_transfer_bool_value (
Interface *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean interface_call_transfer_bool_value_finish (
Interface *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean interface_call_transfer_bool_value_sync (
Interface *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void interface_call_get_bool_value (
Interface *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean interface_call_get_bool_value_finish (
Interface *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean interface_call_get_bool_value_sync (
Interface *proxy,
const gchar *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void interface_call_transfer_int_value (
Interface *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean interface_call_transfer_int_value_finish (
Interface *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean interface_call_transfer_int_value_sync (
Interface *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void interface_call_get_int_value (
Interface *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean interface_call_get_int_value_finish (
Interface *proxy,
gint *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean interface_call_get_int_value_sync (
Interface *proxy,
const gchar *arg_InArg,
gint *out_OutArg,
GCancellable *cancellable,
GError **error);
void interface_call_transfer_string_value (
Interface *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean interface_call_transfer_string_value_finish (
Interface *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean interface_call_transfer_string_value_sync (
Interface *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void interface_call_get_string_value (
Interface *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean interface_call_get_string_value_finish (
Interface *proxy,
gchar **out_OutArg,
GAsyncResult *res,
GError **error);
gboolean interface_call_get_string_value_sync (
Interface *proxy,
const gchar *arg_InArg,
gchar **out_OutArg,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_INTERFACE_PROXY (interface_proxy_get_type ())
#define INTERFACE_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_INTERFACE_PROXY, InterfaceProxy))
#define INTERFACE_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_INTERFACE_PROXY, InterfaceProxyClass))
#define INTERFACE_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_INTERFACE_PROXY, InterfaceProxyClass))
#define IS_INTERFACE_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_INTERFACE_PROXY))
#define IS_INTERFACE_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_INTERFACE_PROXY))
typedef struct _InterfaceProxy InterfaceProxy;
typedef struct _InterfaceProxyClass InterfaceProxyClass;
typedef struct _InterfaceProxyPrivate InterfaceProxyPrivate;
struct _InterfaceProxy
{
/*< private >*/
GDBusProxy parent_instance;
InterfaceProxyPrivate *priv;
};
struct _InterfaceProxyClass
{
GDBusProxyClass parent_class;
};
GType interface_proxy_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (InterfaceProxy, g_object_unref)
#endif
void interface_proxy_new (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Interface *interface_proxy_new_finish (
GAsyncResult *res,
GError **error);
Interface *interface_proxy_new_sync (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
void interface_proxy_new_for_bus (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Interface *interface_proxy_new_for_bus_finish (
GAsyncResult *res,
GError **error);
Interface *interface_proxy_new_for_bus_sync (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_INTERFACE_SKELETON (interface_skeleton_get_type ())
#define INTERFACE_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_INTERFACE_SKELETON, InterfaceSkeleton))
#define INTERFACE_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_INTERFACE_SKELETON, InterfaceSkeletonClass))
#define INTERFACE_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_INTERFACE_SKELETON, InterfaceSkeletonClass))
#define IS_INTERFACE_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_INTERFACE_SKELETON))
#define IS_INTERFACE_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_INTERFACE_SKELETON))
typedef struct _InterfaceSkeleton InterfaceSkeleton;
typedef struct _InterfaceSkeletonClass InterfaceSkeletonClass;
typedef struct _InterfaceSkeletonPrivate InterfaceSkeletonPrivate;
struct _InterfaceSkeleton
{
/*< private >*/
GDBusInterfaceSkeleton parent_instance;
InterfaceSkeletonPrivate *priv;
};
struct _InterfaceSkeletonClass
{
GDBusInterfaceSkeletonClass parent_class;
};
GType interface_skeleton_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (InterfaceSkeleton, g_object_unref)
#endif
Interface *interface_skeleton_new (void);
G_END_DECLS
#endif /* __INTERFACE_GENERATED_H__ */

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KEYBOARDDBUS_H__
#define __KEYBOARDDBUS_H__
#include <gio/gio.h> /* Bus define */
#ifdef __cplusplus
extern "C" {
#endif
#define KEYBOARD_BUS G_BUS_TYPE_SESSION
#define KEYBOARD_BUS_NAME "cn.kylinos.keyboard"
#define KEYBOARD_OBJECT_PATH "/cn/kylinos/keyboard"
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,283 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KEYBOARD_GENERATED_H__
#define __KEYBOARD_GENERATED_H__
#include <gio/gio.h>
G_BEGIN_DECLS
/* ------------------------------------------------------------------------ */
/* Declarations for cn.kylinos.keyboard */
#define TYPE_KEYBOARD (keyboard_get_type ())
#define KEYBOARD(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_KEYBOARD, Keyboard))
#define IS_KEYBOARD(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_KEYBOARD))
#define KEYBOARD_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), TYPE_KEYBOARD, KeyboardIface))
struct _Keyboard;
typedef struct _Keyboard Keyboard;
typedef struct _KeyboardIface KeyboardIface;
struct _KeyboardIface
{
GTypeInterface parent_iface;
gboolean (*handle_get_bool_value) (
Keyboard *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_get_int_value) (
Keyboard *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_transfer_bool_value) (
Keyboard *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
gboolean (*handle_transfer_int_value) (
Keyboard *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
};
GType keyboard_get_type (void) G_GNUC_CONST;
GDBusInterfaceInfo *keyboard_interface_info (void);
guint keyboard_override_properties (GObjectClass *klass, guint property_id_begin);
/* D-Bus method call completion functions: */
void keyboard_complete_transfer_bool_value (
Keyboard *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void keyboard_complete_get_bool_value (
Keyboard *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void keyboard_complete_transfer_int_value (
Keyboard *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void keyboard_complete_get_int_value (
Keyboard *object,
GDBusMethodInvocation *invocation,
gint OutArg);
/* D-Bus method calls: */
void keyboard_call_transfer_bool_value (
Keyboard *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean keyboard_call_transfer_bool_value_finish (
Keyboard *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean keyboard_call_transfer_bool_value_sync (
Keyboard *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void keyboard_call_get_bool_value (
Keyboard *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean keyboard_call_get_bool_value_finish (
Keyboard *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean keyboard_call_get_bool_value_sync (
Keyboard *proxy,
const gchar *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void keyboard_call_transfer_int_value (
Keyboard *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean keyboard_call_transfer_int_value_finish (
Keyboard *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean keyboard_call_transfer_int_value_sync (
Keyboard *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void keyboard_call_get_int_value (
Keyboard *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean keyboard_call_get_int_value_finish (
Keyboard *proxy,
gint *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean keyboard_call_get_int_value_sync (
Keyboard *proxy,
const gchar *arg_InArg,
gint *out_OutArg,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_KEYBOARD_PROXY (keyboard_proxy_get_type ())
#define KEYBOARD_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_KEYBOARD_PROXY, KeyboardProxy))
#define KEYBOARD_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_KEYBOARD_PROXY, KeyboardProxyClass))
#define KEYBOARD_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_KEYBOARD_PROXY, KeyboardProxyClass))
#define IS_KEYBOARD_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_KEYBOARD_PROXY))
#define IS_KEYBOARD_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_KEYBOARD_PROXY))
typedef struct _KeyboardProxy KeyboardProxy;
typedef struct _KeyboardProxyClass KeyboardProxyClass;
typedef struct _KeyboardProxyPrivate KeyboardProxyPrivate;
struct _KeyboardProxy
{
/*< private >*/
GDBusProxy parent_instance;
KeyboardProxyPrivate *priv;
};
struct _KeyboardProxyClass
{
GDBusProxyClass parent_class;
};
GType keyboard_proxy_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (KeyboardProxy, g_object_unref)
#endif
void keyboard_proxy_new (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Keyboard *keyboard_proxy_new_finish (
GAsyncResult *res,
GError **error);
Keyboard *keyboard_proxy_new_sync (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
void keyboard_proxy_new_for_bus (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Keyboard *keyboard_proxy_new_for_bus_finish (
GAsyncResult *res,
GError **error);
Keyboard *keyboard_proxy_new_for_bus_sync (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_KEYBOARD_SKELETON (keyboard_skeleton_get_type ())
#define KEYBOARD_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_KEYBOARD_SKELETON, KeyboardSkeleton))
#define KEYBOARD_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_KEYBOARD_SKELETON, KeyboardSkeletonClass))
#define KEYBOARD_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_KEYBOARD_SKELETON, KeyboardSkeletonClass))
#define IS_KEYBOARD_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_KEYBOARD_SKELETON))
#define IS_KEYBOARD_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_KEYBOARD_SKELETON))
typedef struct _KeyboardSkeleton KeyboardSkeleton;
typedef struct _KeyboardSkeletonClass KeyboardSkeletonClass;
typedef struct _KeyboardSkeletonPrivate KeyboardSkeletonPrivate;
struct _KeyboardSkeleton
{
/*< private >*/
GDBusInterfaceSkeleton parent_instance;
KeyboardSkeletonPrivate *priv;
};
struct _KeyboardSkeletonClass
{
GDBusInterfaceSkeletonClass parent_class;
};
GType keyboard_skeleton_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (KeyboardSkeleton, g_object_unref)
#endif
Keyboard *keyboard_skeleton_new (void);
G_END_DECLS
#endif /* __KEYBOARD_GENERATED_H__ */

View File

@ -0,0 +1,250 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "interface-dbus.h"
#include "kylin-interface-interface.h"
#include "src/common/kylin-print.h"
#include "interface-generated.h"
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include<stdbool.h>
#define CB "cursor-blink"
#define CBT "cursor-blink-time"
#define FN "font-name"
#define DFN "document-font-name"
#define MFN "monospace-font-name"
static GMainLoop *pLoop = NULL;
static GDBusConnection *pConnection = NULL;
static Interface *pProxy = NULL;
bool kylin_hardware_keyboard_set_cursorblink(const bool in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=CB;
gboolean retv;
arg=g_variant_new("(sb)", key, in_arg);
interface_call_transfer_bool_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_keyboard_cursorblink. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
bool kylin_hardware_keyboard_get_cursorblink()
{
gchar *key=CB;
gboolean value;
GError* pError=NULL;
interface_call_get_bool_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
bool kylin_hardware_keyboard_set_cursorblinktime(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=CBT;
gboolean retv;
arg=g_variant_new("(si)",key,in_arg);
interface_call_transfer_int_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_keyboard_cursorblinktime. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
int kylin_hardware_keyboard_get_cursorblinktime()
{
gchar *key=CBT;
int value;
GError* pError=NULL;
interface_call_get_int_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
bool kylin_personal_fonts_set_fontname(const char *in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=FN;
gboolean retv;
arg=g_variant_new("(ss)", key, in_arg);
interface_call_transfer_string_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_personal_fonts_fontname. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
char *kylin_personal_fonts_get_fontname()
{
gchar *key=FN;
char *value;
GError* pError=NULL;
interface_call_get_string_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
bool kylin_personal_fonts_set_documentfont(const char *in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=DFN;
gboolean retv;
arg=g_variant_new("(ss)", key, in_arg);
interface_call_transfer_string_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_personal_fonts_documentfont. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
char *kylin_personal_fonts_get_documentfont()
{
gchar *key=DFN;
char *value;
GError* pError=NULL;
interface_call_get_string_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
bool kylin_personal_fonts_set_monospacefont(const char *in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=MFN;
gboolean retv;
arg=g_variant_new("(ss)", key, in_arg);
interface_call_transfer_string_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_personal_fonts_monospacefont. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
char *kylin_personal_fonts_get_monospacefont()
{
gchar *key=MFN;
char *value;
GError* pError=NULL;
interface_call_get_string_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
void *run(void* arg)
{
/** start the main event loop which manages all available sources of events */
g_main_loop_run(pLoop);
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if(0 != err){
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusInterface(void)
{
bool bRet = TRUE;
GError *pConnError = NULL;
GError *pProxyError = NULL;
do{
bRet = TRUE;
pLoop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
/** First step: get a connection */
pConnection = g_bus_get_sync(INTERFACE_BUS, NULL, &pConnError);
if (NULL == pConnError){
/** Second step: try to get a connection to the given bus.*/
pProxy = interface_proxy_new_sync(pConnection,
G_DBUS_PROXY_FLAGS_NONE,
INTERFACE_BUS_NAME,
INTERFACE_OBJECT_PATH,
NULL,
&pProxyError);
if (0 == pProxy){
print_error("InitDBusCommunication: Failed to create proxy. Reason: %s.\n", pProxyError->message);
g_error_free(pProxyError);
bRet = FALSE;
}
}
else{
print_error("InitDBusCommunication: Failed to connect to dbus. Reason: %s.\n", pConnError->message);
g_error_free(pConnError);
bRet = FALSE;
}
}while(FALSE == bRet);
thread_create();
return bRet;
}
bool DeInitDBusInterface(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}

View File

@ -0,0 +1,120 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLININTERFACEINTERFACE_H__
#define __KYLININTERFACEINTERFACE_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initialize the DBus Communication.
*/
bool InitDBusInterface(void);
/**
* Delete the DBus Communication.
*/
bool DeInitDBusInterface(void);
/**
* Set cursor blink.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_keyboard_set_cursorblink(const bool in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
bool kylin_hardware_keyboard_get_cursorblink();
/**
* Set cursor blink time.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_keyboard_set_cursorblinktime(const int in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
int kylin_hardware_keyboard_get_cursorblinktime();
/**
* Set the name of the default font used by gtk+.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_personal_fonts_set_fontname(const char *in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
char *kylin_personal_fonts_get_fontname();
/**
* Set the name of the default font used for reading documents.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_personal_fonts_set_documentfont(const char *in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
char *kylin_personal_fonts_get_documentfont();
/**
* Set the name of a monospaced (fixed-width) font for use in locations like terminals.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_personal_fonts_set_monospacefont(const char *in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
char *kylin_personal_fonts_get_monospacefont();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,267 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "interface-dbus.h"
#include "src/common/kylin-print.h"
#include "interface-generated.h"
#include <string.h>
#include <stdbool.h>
#define schemaID "org.mate.interface"
static GMainLoop *pLoop = NULL;
static Interface *pSkeleton = NULL;
static gboolean kylin_set_bool(Interface* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gboolean value;
gint i;
g_variant_get(in_arg, "(sb)", &key, &value);
if(value==false)i=0;
else i=1;
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_boolean(setting,key,value);
g_object_unref(setting);
g_settings_sync();
interface_complete_transfer_bool_value(object, invocation, retv);
print_info("(%s, %d)\n", key, i);
return TRUE;
}
static gboolean kylin_get_bool(Interface* object,
GDBusMethodInvocation* invocation,
gchar *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gboolean ret=g_settings_get_boolean(setting, in_arg);
g_object_unref(setting);
interface_complete_get_bool_value(object, invocation, ret);
return TRUE;
}
static gboolean kylin_set_int(Interface* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gint value;
g_variant_get(in_arg, "(si)", &key, &value);
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_int(setting,key,value);
g_object_unref(setting);
g_settings_sync();
interface_complete_transfer_int_value(object, invocation, retv);
print_info("(%s, %d)\n", key, value);
return TRUE;
}
static gboolean kylin_get_int(Interface* object,
GDBusMethodInvocation* invocation,
gchar *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gint ret=g_settings_get_int(setting, in_arg);
g_object_unref(setting);
interface_complete_get_int_value(object, invocation, ret);
return TRUE;
}
static gboolean kylin_set_char(Interface* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gchar *value=NULL;
g_variant_get(in_arg, "(ss)", &key, &value);
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_string(setting,key,value);
g_object_unref(setting);
g_settings_sync();
interface_complete_transfer_string_value(object, invocation, retv);
print_info("(%s, %s)\n", key, value);
return TRUE;
}
static gboolean kylin_get_char(Interface* object,
GDBusMethodInvocation* invocation,
gchar *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gchar *ret=g_settings_get_string(setting, in_arg);
g_object_unref(setting);
interface_complete_get_string_value(object, invocation, ret);
return TRUE;
}
static void bus_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
GError *pError = NULL;
/** Second step: Try to get a connection to the given bus. */
pSkeleton = interface_skeleton_new();
/** Third step: Attach to dbus signals. */
(void) g_signal_connect(pSkeleton, "handle-transfer-bool-value", G_CALLBACK(kylin_set_bool), NULL);
(void) g_signal_connect(pSkeleton, "handle-transfer-int-value", G_CALLBACK(kylin_set_int), NULL);
(void) g_signal_connect(pSkeleton, "handle-transfer-string-value", G_CALLBACK(kylin_set_char), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-bool-value", G_CALLBACK(kylin_get_bool), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-int-value", G_CALLBACK(kylin_get_int), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-string-value", G_CALLBACK(kylin_get_char), NULL);
/** Fourth step: Export interface skeleton. */
(void)g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(pSkeleton),
connection,
INTERFACE_OBJECT_PATH,
&pError);
if(pError != NULL){
print_error("Error: Failed to export object. Reason: %s.\n", pError->message);
g_error_free(pError);
g_main_loop_quit(pLoop);
}
}
static void name_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
print_info("name_acquired_cb call, Acquired bus name: %s.\n", INTERFACE_BUS_NAME);
}
static void name_lost_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
if(connection == NULL)
{
print_error("name_lost_cb call, Error: Failed to connect to dbus.\n");
}
else
{
print_error("name_lost_cb call, Error: Failed to obtain bus name: %s.\n", INTERFACE_BUS_NAME);
}
g_main_loop_quit(pLoop);
}
void* run(void* para)
{
/** Start the Main Event Loop which manages all available sources of events */
g_main_loop_run( pLoop );
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if (err != 0)
{
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusCommunicationServer(void)
{
bool bRet = TRUE;
g_print("InitDBusCommunicationServer: Server started.\n");
/** create main loop, but do not start it. */
pLoop = g_main_loop_new(NULL, FALSE);
/** first step: connect to dbus */
(void)g_bus_own_name(INTERFACE_BUS,
INTERFACE_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
&bus_acquired_cb,
&name_acquired_cb,
&name_lost_cb,
NULL,
NULL);
thread_create();
return bRet;
}
bool DeinitDBusCommunicationServer(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}
int main(void)
{
InitDBusCommunicationServer();
sleep(100);
DeinitDBusCommunicationServer();
return 0;
}

View File

@ -0,0 +1,196 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "keyboard-dbus.h"
#include "kylin-keyboard-interface.h"
#include "src/common/kylin-print.h"
#include "keyboard-generated.h"
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdbool.h>
#define REP "repeat"
#define RAT "rate"
#define DEL "delay"
static GMainLoop *pLoop = NULL;
static GDBusConnection *pConnection = NULL;
static Keyboard *pProxy = NULL;
bool kylin_hardware_keyboard_set_repeat(const bool in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=REP;
gboolean retv;
arg=g_variant_new("(sb)", key, in_arg);
keyboard_call_transfer_bool_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_keyboard_repeat. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
bool kylin_hardware_keyboard_get_repeat()
{
GError* pError=NULL;
gchar *key=REP;
gboolean value;
keyboard_call_get_bool_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
bool kylin_hardware_keyboard_set_rate(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=RAT;
gboolean retv;
arg=g_variant_new("(si)",key,in_arg);
keyboard_call_transfer_int_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_keyboard_rate. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
int kylin_hardware_keyboard_get_rate()
{
gchar *key=RAT;
GError* pError=NULL;
gint value;
keyboard_call_get_int_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
bool kylin_hardware_keyboard_set_delay(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=DEL;
gboolean retv;
arg=g_variant_new("(si)",key,in_arg);
keyboard_call_transfer_int_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_keyboard_delay. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
int kylin_hardware_keyboard_get_delay()
{
gchar *key=DEL;
GError* pError=NULL;
gint value;
keyboard_call_get_int_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
void *run(void* arg)
{
/** start the main event loop which manages all available sources of events */
g_main_loop_run(pLoop);
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if(0 != err){
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusKeyboard(void)
{
bool bRet = TRUE;
GError *pConnError = NULL;
GError *pProxyError = NULL;
do{
bRet = TRUE;
pLoop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
/** First step: get a connection */
pConnection = g_bus_get_sync(KEYBOARD_BUS, NULL, &pConnError);
if (NULL == pConnError){
/** Second step: try to get a connection to the given bus.*/
pProxy = keyboard_proxy_new_sync(pConnection,
G_DBUS_PROXY_FLAGS_NONE,
KEYBOARD_BUS_NAME,
KEYBOARD_OBJECT_PATH,
NULL,
&pProxyError);
if (0 == pProxy){
print_error("InitDBusCommunication: Failed to create proxy. Reason: %s.\n", pProxyError->message);
g_error_free(pProxyError);
bRet = FALSE;
}
}
else{
print_error("InitDBusCommunication: Failed to connect to dbus. Reason: %s.\n", pConnError->message);
g_error_free(pConnError);
bRet = FALSE;
}
}while(FALSE == bRet);
thread_create();
return bRet;
}
bool DeInitDBusKeyboard(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}

View File

@ -0,0 +1,95 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINKEYBOARDINTERFACE_H__
#define __KYLINKEYBOARDINTERFACE_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initialize the DBus Communication
*/
bool InitDBusKeyboard(void);
/**
* Delete the DBus Communication.
*/
bool DeInitDBusKeyboard(void);
/**
* Repeat the key when holding down a key.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_keyboard_set_repeat(const bool in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
bool kylin_hardware_keyboard_get_repeat();
/**
* Set key speed.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_keyboard_set_rate(const int in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
int kylin_hardware_keyboard_get_rate();
/**
* Set time delay.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_keyboard_set_delay(const int in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
int kylin_hardware_keyboard_get_delay();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,229 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "keyboard-dbus.h"
#include "src/common/kylin-print.h"
#include "keyboard-generated.h"
#include <string.h>
#include <stdbool.h>
#define schemaID "org.mate.peripherals-keyboard"
static GMainLoop *pLoop = NULL;
static Keyboard *pSkeleton = NULL;
static gboolean kylin_set_bool(Keyboard* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gboolean value;
gint i;
g_variant_get(in_arg, "(sb)", &key, &value);
if(value==false)i=0;
else i=1;
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_boolean(setting,key,value);
g_object_unref(setting);
g_settings_sync();
keyboard_complete_transfer_bool_value(object, invocation, retv);
print_info("(%s, %d)\n", key, i);
return TRUE;
}
static gboolean kylin_get_bool(Keyboard* object,
GDBusMethodInvocation* invocation,
gchar *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gboolean ret=g_settings_get_boolean(setting, in_arg);
g_object_unref(setting);
keyboard_complete_get_bool_value(object, invocation, ret);
return TRUE;
}
static gboolean kylin_set_int(Keyboard* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gint value;
g_variant_get(in_arg, "(si)", &key, &value);
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_int(setting,key,value);
g_object_unref(setting);
g_settings_sync();
keyboard_complete_transfer_int_value(object, invocation, retv);
print_info("(%s, %d)\n", key, value);
return TRUE;
}
static gboolean kylin_get_int(Keyboard* object,
GDBusMethodInvocation* invocation,
gchar *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gint ret=g_settings_get_int(setting, in_arg);
g_object_unref(setting);
keyboard_complete_get_int_value(object, invocation, ret);
return TRUE;
}
static void bus_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
GError *pError = NULL;
/** Second step: Try to get a connection to the given bus. */
pSkeleton = keyboard_skeleton_new();
/** Third step: Attach to dbus signals. */
(void) g_signal_connect(pSkeleton, "handle-transfer-bool-value", G_CALLBACK(kylin_set_bool), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-bool-value", G_CALLBACK(kylin_get_bool), NULL);
(void) g_signal_connect(pSkeleton, "handle-transfer-int-value", G_CALLBACK(kylin_set_int), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-int-value", G_CALLBACK(kylin_get_int), NULL);
/** Fourth step: Export interface skeleton. */
(void)g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(pSkeleton),
connection,
KEYBOARD_OBJECT_PATH,
&pError);
if(pError != NULL){
print_error("Error: Failed to export object. Reason: %s.\n", pError->message);
g_error_free(pError);
g_main_loop_quit(pLoop);
}
}
static void name_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
print_info("name_acquired_cb call, Acquired bus name: %s.\n", KEYBOARD_BUS_NAME);
}
static void name_lost_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
if(connection == NULL)
{
print_error("name_lost_cb call, Error: Failed to connect to dbus.\n");
}
else
{
print_error("name_lost_cb call, Error: Failed to obtain bus name: %s.\n", KEYBOARD_BUS_NAME);
}
g_main_loop_quit(pLoop);
}
void* run(void* para)
{
/** Start the Main Event Loop which manages all available sources of events */
g_main_loop_run( pLoop );
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if (err != 0)
{
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusCommunicationServer(void)
{
bool bRet = TRUE;
g_print("InitDBusCommunicationServer: Server started.\n");
/** create main loop, but do not start it. */
pLoop = g_main_loop_new(NULL, FALSE);
/** first step: connect to dbus */
(void)g_bus_own_name(KEYBOARD_BUS,
KEYBOARD_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
&bus_acquired_cb,
&name_acquired_cb,
&name_lost_cb,
NULL,
NULL);
thread_create();
return bRet;
}
bool DeinitDBusCommunicationServer(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}
int main(void)
{
InitDBusCommunicationServer();
sleep(100);
DeinitDBusCommunicationServer();
return 0;
}

View File

@ -0,0 +1,140 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "xkbgeneral-dbus.h"
#include "kylin-xkbgeneral-interface.h"
#include "src/common/kylin-print.h"
#include "xkbgeneral-generated.h"
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdbool.h>
#define GPW "group-per-window"
static GMainLoop *pLoop = NULL;
static GDBusConnection *pConnection = NULL;
static Xkbgeneral *pProxy = NULL;
bool kylin_hardware_keyboard_set_groupperwindow(const bool in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=GPW;
gboolean retv;
arg=g_variant_new("(sb)", key, in_arg);
xkbgeneral_call_transfer_bool_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_keyboard_groupperwindow. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
bool kylin_hardware_keyboard_get_groupperwindow()
{
GError* pError=NULL;
gchar *key=GPW;
gboolean value;
xkbgeneral_call_get_bool_value_sync(pProxy, key, &value, NULL, &pError);
return value;
}
void *run(void* arg)
{
/** start the main event loop which manages all available sources of events */
g_main_loop_run(pLoop);
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if(0 != err){
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusXkbgeneral(void)
{
bool bRet = TRUE;
GError *pConnError = NULL;
GError *pProxyError = NULL;
do{
bRet = TRUE;
pLoop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
/** First step: get a connection */
pConnection = g_bus_get_sync(XKBGENERAL_BUS, NULL, &pConnError);
if (NULL == pConnError){
/** Second step: try to get a connection to the given bus.*/
pProxy = xkbgeneral_proxy_new_sync(pConnection,
G_DBUS_PROXY_FLAGS_NONE,
XKBGENERAL_BUS_NAME,
XKBGENERAL_OBJECT_PATH,
NULL,
&pProxyError);
if (0 == pProxy){
print_error("InitDBusCommunication: Failed to create proxy. Reason: %s.\n", pProxyError->message);
g_error_free(pProxyError);
bRet = FALSE;
}
}
else{
print_error("InitDBusCommunication: Failed to connect to dbus. Reason: %s.\n", pConnError->message);
g_error_free(pConnError);
bRet = FALSE;
}
}while(FALSE == bRet);
thread_create();
return bRet;
}
bool DeInitDBusXkbgeneral(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINXKBGENERALINTERFACE_H__
#define __KYLINXKBGENERALINTERFACE_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initialize the DBus Communication
*/
bool InitDBusXkbgeneral(void);
/**
* Delete the DBus Communication
*/
bool DeInitDBusXkbgeneral(void);
/**
* Keep and manage separate group per window.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_keyboard_set_groupperwindow(const bool in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
bool kylin_hardware_keyboard_get_groupperwindow();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,193 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "xkbgeneral-dbus.h"
#include "src/common/kylin-print.h"
#include "xkbgeneral-generated.h"
#include <string.h>
#include <stdbool.h>
#define schemaID "org.mate.peripherals-keyboard-xkb.general"
static GMainLoop *pLoop = NULL;
static Xkbgeneral *pSkeleton = NULL;
static gboolean kylin_set_bool(Xkbgeneral* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gboolean value;
gint i;
g_variant_get(in_arg, "(sb)", &key, &value);
if(value==false)i=0;
else i=1;
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_boolean(setting,key,value);
g_object_unref(setting);
g_settings_sync();
xkbgeneral_complete_transfer_bool_value(object, invocation, retv);
print_info("(%s, %d)\n", key, i);
return TRUE;
}
static gboolean kylin_get_bool(Xkbgeneral* object,
GDBusMethodInvocation* invocation,
gchar *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gboolean ret=g_settings_get_boolean(setting, in_arg);
g_object_unref(setting);
xkbgeneral_complete_get_bool_value(object, invocation, ret);
return TRUE;
}
static void bus_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
GError *pError = NULL;
/** Second step: Try to get a connection to the given bus. */
pSkeleton = xkbgeneral_skeleton_new();
/** Third step: Attach to dbus signals. */
(void) g_signal_connect(pSkeleton, "handle-transfer-bool-value", G_CALLBACK(kylin_set_bool), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-bool-value", G_CALLBACK(kylin_get_bool), NULL);
/** Fourth step: Export interface skeleton. */
(void)g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(pSkeleton),
connection,
XKBGENERAL_OBJECT_PATH,
&pError);
if(pError != NULL){
print_error("Error: Failed to export object. Reason: %s.\n", pError->message);
g_error_free(pError);
g_main_loop_quit(pLoop);
}
}
static void name_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
print_info("name_acquired_cb call, Acquired bus name: %s.\n", XKBGENERAL_BUS_NAME);
}
static void name_lost_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
if(connection == NULL)
{
print_error("name_lost_cb call, Error: Failed to connect to dbus.\n");
}
else
{
print_error("name_lost_cb call, Error: Failed to obtain bus name: %s.\n", XKBGENERAL_BUS_NAME);
}
g_main_loop_quit(pLoop);
}
void* run(void* para)
{
/** Start the Main Event Loop which manages all available sources of events */
g_main_loop_run( pLoop );
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if (err != 0)
{
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusCommunicationServer(void)
{
bool bRet = TRUE;
g_print("InitDBusCommunicationServer: Server started.\n");
/** create main loop, but do not start it. */
pLoop = g_main_loop_new(NULL, FALSE);
/** first step: connect to dbus */
(void)g_bus_own_name(XKBGENERAL_BUS,
XKBGENERAL_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
&bus_acquired_cb,
&name_acquired_cb,
&name_lost_cb,
NULL,
NULL);
thread_create();
return bRet;
}
bool DeinitDBusCommunicationServer(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}
int main(void)
{
InitDBusCommunicationServer();
sleep(100);
DeinitDBusCommunicationServer();
return 0;
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __XKBGENERALDBUS_H__
#define __XKBGENERALDBUS_H__
#include <gio/gio.h> /* Bus define */
#ifdef __cplusplus
extern "C" {
#endif
#define XKBGENERAL_BUS G_BUS_TYPE_SESSION
#define XKBGENERAL_BUS_NAME "cn.kylinos.xkbgeneral"
#define XKBGENERAL_OBJECT_PATH "/cn/kylinos/xkbgeneral"
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,223 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __XKBGENERAL_GENERATED_H__
#define __XKBGENERAL_GENERATED_H__
#include <gio/gio.h>
G_BEGIN_DECLS
/* ------------------------------------------------------------------------ */
/* Declarations for cn.kylinos.xkbgeneral */
#define TYPE_XKBGENERAL (xkbgeneral_get_type ())
#define XKBGENERAL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_XKBGENERAL, Xkbgeneral))
#define IS_XKBGENERAL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_XKBGENERAL))
#define XKBGENERAL_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), TYPE_XKBGENERAL, XkbgeneralIface))
struct _Xkbgeneral;
typedef struct _Xkbgeneral Xkbgeneral;
typedef struct _XkbgeneralIface XkbgeneralIface;
struct _XkbgeneralIface
{
GTypeInterface parent_iface;
gboolean (*handle_get_bool_value) (
Xkbgeneral *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_transfer_bool_value) (
Xkbgeneral *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
};
GType xkbgeneral_get_type (void) G_GNUC_CONST;
GDBusInterfaceInfo *xkbgeneral_interface_info (void);
guint xkbgeneral_override_properties (GObjectClass *klass, guint property_id_begin);
/* D-Bus method call completion functions: */
void xkbgeneral_complete_transfer_bool_value (
Xkbgeneral *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void xkbgeneral_complete_get_bool_value (
Xkbgeneral *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
/* D-Bus method calls: */
void xkbgeneral_call_transfer_bool_value (
Xkbgeneral *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean xkbgeneral_call_transfer_bool_value_finish (
Xkbgeneral *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean xkbgeneral_call_transfer_bool_value_sync (
Xkbgeneral *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void xkbgeneral_call_get_bool_value (
Xkbgeneral *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean xkbgeneral_call_get_bool_value_finish (
Xkbgeneral *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean xkbgeneral_call_get_bool_value_sync (
Xkbgeneral *proxy,
const gchar *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_XKBGENERAL_PROXY (xkbgeneral_proxy_get_type ())
#define XKBGENERAL_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_XKBGENERAL_PROXY, XkbgeneralProxy))
#define XKBGENERAL_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_XKBGENERAL_PROXY, XkbgeneralProxyClass))
#define XKBGENERAL_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_XKBGENERAL_PROXY, XkbgeneralProxyClass))
#define IS_XKBGENERAL_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_XKBGENERAL_PROXY))
#define IS_XKBGENERAL_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_XKBGENERAL_PROXY))
typedef struct _XkbgeneralProxy XkbgeneralProxy;
typedef struct _XkbgeneralProxyClass XkbgeneralProxyClass;
typedef struct _XkbgeneralProxyPrivate XkbgeneralProxyPrivate;
struct _XkbgeneralProxy
{
/*< private >*/
GDBusProxy parent_instance;
XkbgeneralProxyPrivate *priv;
};
struct _XkbgeneralProxyClass
{
GDBusProxyClass parent_class;
};
GType xkbgeneral_proxy_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (XkbgeneralProxy, g_object_unref)
#endif
void xkbgeneral_proxy_new (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Xkbgeneral *xkbgeneral_proxy_new_finish (
GAsyncResult *res,
GError **error);
Xkbgeneral *xkbgeneral_proxy_new_sync (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
void xkbgeneral_proxy_new_for_bus (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Xkbgeneral *xkbgeneral_proxy_new_for_bus_finish (
GAsyncResult *res,
GError **error);
Xkbgeneral *xkbgeneral_proxy_new_for_bus_sync (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_XKBGENERAL_SKELETON (xkbgeneral_skeleton_get_type ())
#define XKBGENERAL_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_XKBGENERAL_SKELETON, XkbgeneralSkeleton))
#define XKBGENERAL_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_XKBGENERAL_SKELETON, XkbgeneralSkeletonClass))
#define XKBGENERAL_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_XKBGENERAL_SKELETON, XkbgeneralSkeletonClass))
#define IS_XKBGENERAL_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_XKBGENERAL_SKELETON))
#define IS_XKBGENERAL_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_XKBGENERAL_SKELETON))
typedef struct _XkbgeneralSkeleton XkbgeneralSkeleton;
typedef struct _XkbgeneralSkeletonClass XkbgeneralSkeletonClass;
typedef struct _XkbgeneralSkeletonPrivate XkbgeneralSkeletonPrivate;
struct _XkbgeneralSkeleton
{
/*< private >*/
GDBusInterfaceSkeleton parent_instance;
XkbgeneralSkeletonPrivate *priv;
};
struct _XkbgeneralSkeletonClass
{
GDBusInterfaceSkeletonClass parent_class;
};
GType xkbgeneral_skeleton_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (XkbgeneralSkeleton, g_object_unref)
#endif
Xkbgeneral *xkbgeneral_skeleton_new (void);
G_END_DECLS
#endif /* __XKBGENERAL_GENERATED_H__ */

View File

@ -0,0 +1,55 @@
COMM_PRINT= -L$(top_srcdir)/src/common -lukui-print
COMM_GSETTINGS= -L$(top_srcdir)/src/common -lukui-gsettings
#generate the .c and .h file which used by client and server side by XML file
#$(top_srcdir) represents the top-level directory of the project
DESC_XML = $(top_srcdir)/data/cn.kylinos.mouse.xml
GENERATED_CH = mouse-generated
mouse-generated.h mouse-generated.c: $(DESC_XML)
gdbus-codegen --interface-prefix cn.kylinos. --generate-c-code $(GENERATED_CH) $(DESC_XML)
#Generata binary file
lib_LTLIBRARIES = libukui-mouseclient.la
#gcc -wall: displays all the errors and warning information when compiling
#gcc -g: add the debugging code when compiling
COMM_CFS = -Wall -g
#Add the dependent source file for libmouseclient.la
#mouse-generated.c must be front of kylin-mouse-interface.c
libukui_mouseclient_la_SOURCES = mouse-generated.c kylin-mouse-interface.c \
$(NULL)
#The header files that need to be installed
include_HEADERS= kylin-mouse-interface.h \
$(NULL)
#Additional C compiler flags
libukui_mouseclient_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_mouseclient_la_LDFLAGS= $(COMM_PRINT) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Generata binary file
bin_PROGRAMS = ukui-mouseserver
#Add the dependent source file for mouseserver
ukui_mouseserver_SOURCES = \
mouse-generated.h mouse-generated.c \
kylin-mouse-server.c \
$(NULL)
#Additional C compiler flags
ukui_mouseserver_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
ukui_mouseserver_LDFLAGS= $(COMM_PRINT) $(COMM_GSETTINGS) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)

View File

@ -0,0 +1,390 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "mouse-dbus.h"
#include "kylin-mouse-interface.h"
#include "src/common/kylin-print.h"
#include "mouse-generated.h"
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdbool.h>
#define LH "left-handed"
#define MA "motion-acceleration"
#define MT "motion-threshold"
#define DT "drag-threshold"
#define DC "double-click"
#define MBE "middle-button-enabled"
#define LP "locate-pointer"
#define CF "cursor-font"
#define CT "cursor-theme"
#define CS "cursor-size"
static GMainLoop *pLoop = NULL;
static GDBusConnection *pConnection = NULL;
static Mouse *pProxy = NULL;
bool kylin_hardware_mouse_set_lefthanded(const bool in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=LH;
gboolean retv;
arg=g_variant_new("(sb)", key, in_arg);
mouse_call_transfer_bool_value_sync(pProxy, arg, &retv,NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_lefthanded. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
bool kylin_hardware_mouse_get_lefthanded()
{
gchar *key=LH;
gboolean value;
GError* pError=NULL;
mouse_call_get_bool_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_motionacceleration(const double in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=MA;
gboolean retv;
arg=g_variant_new("(sd)",key,in_arg);
mouse_call_transfer_double_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_motionacceleration. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
double kylin_hardware_mouse_get_motionacceleration()
{
gchar *key=MA;
double value;
GError* pError=NULL;
mouse_call_get_double_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_motionthreshold(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=MT;
gboolean retv;
arg=g_variant_new("(si)",key,in_arg);
mouse_call_transfer_int_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_motionthreshold. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
int kylin_hardware_mouse_get_motionthreshold()
{
gchar *key=MT;
int value;
GError* pError=NULL;
mouse_call_get_int_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_dragthreshold(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=DT;
gboolean retv;
arg=g_variant_new("(si)",key,in_arg);
mouse_call_transfer_int_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_dragthreshold. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
int kylin_hardware_mouse_get_dragthreshold()
{
gchar *key=DT;
int value;
GError* pError=NULL;
mouse_call_get_int_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_doubleclick(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=DC;
gboolean retv;
arg=g_variant_new("(si)",key,in_arg);
mouse_call_transfer_int_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_doubleclick. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
int kylin_hardware_mouse_get_doubleclick()
{
gchar *key=DC;
int value;
GError* pError=NULL;
mouse_call_get_int_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_middlebuttonenabled(const bool in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=MBE;
gboolean retv;
arg=g_variant_new("(sb)", key, in_arg);
mouse_call_transfer_bool_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_middlebuttonenabled. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
bool kylin_hardware_mouse_get_middlebuttonenabled()
{
gchar *key=MBE;
gboolean value;
GError* pError=NULL;
mouse_call_get_bool_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_locatepointer(const bool in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=LP;
gboolean retv;
arg=g_variant_new("(sb)", key, in_arg);
mouse_call_transfer_bool_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_locatepointer. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
bool kylin_hardware_mouse_get_locatepointer()
{
gchar *key=LP;
gboolean value;
GError* pError=NULL;
mouse_call_get_bool_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_cursorfont(const char *in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=CF;
gboolean retv;
arg=g_variant_new("(ss)", key, in_arg);
mouse_call_transfer_string_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_cursorfont. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
char *kylin_hardware_mouse_get_cursorfont()
{
gchar *key=CF;
char *value;
GError* pError=NULL;
mouse_call_get_string_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_cursortheme(const char *in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=CT;
gboolean retv;
arg=g_variant_new("(ss)", key, in_arg);
mouse_call_transfer_string_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_cursortheme. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
char *kylin_hardware_mouse_get_cursortheme()
{
gchar *key=CT;
char *value;
GError* pError=NULL;
mouse_call_get_string_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
bool kylin_hardware_mouse_set_cursorsize(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=CS;
gboolean retv;
arg=g_variant_new("(si)",key,in_arg);
mouse_call_transfer_int_value_sync(pProxy, arg, &retv, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_mouse_cursorsize. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return retv;
}
int kylin_hardware_mouse_get_cursorsize()
{
gchar *key=CS;
int value;
GError* pError=NULL;
mouse_call_get_int_value_sync(pProxy, key,&value, NULL, &pError);
return value;
}
void *run(void* arg)
{
/** start the main event loop which manages all available sources of events */
g_main_loop_run(pLoop);
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if(0 != err){
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusMouse(void)
{
bool bRet = TRUE;
GError *pConnError = NULL;
GError *pProxyError = NULL;
do{
bRet = TRUE;
pLoop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
/** First step: get a connection */
pConnection = g_bus_get_sync(MOUSE_BUS, NULL, &pConnError);
if (NULL == pConnError){
/** Second step: try to get a connection to the given bus.*/
pProxy =mouse_proxy_new_sync(pConnection,
G_DBUS_PROXY_FLAGS_NONE,
MOUSE_BUS_NAME,
MOUSE_OBJECT_PATH,
NULL,
&pProxyError);
if (0 == pProxy){
print_error("InitDBusCommunication: Failed to create proxy. Reason: %s.\n", pProxyError->message);
g_error_free(pProxyError);
bRet = FALSE;
}
}
else{
print_error("InitDBusCommunication: Failed to connect to dbus. Reason: %s.\n", pConnError->message);
g_error_free(pConnError);
bRet = FALSE;
}
}while(FALSE == bRet);
thread_create();
return bRet;
}
bool DeInitDBusMouse(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}

View File

@ -0,0 +1,186 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINMOUSEINTERFACE_H__
#define __KYLINMOUSEINTERFACE_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initialize the DBus Communication.
*/
bool InitDBusMouse(void);
/**
* Delete the DBus Communication.
*/
bool DeInitDBusMouse(void);
/**
* Swap left and right mouse buttons for left-handed mice.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_lefthanded(const bool in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
bool kylin_hardware_mouse_get_lefthanded();
/**
* Set acceleration multiplier for mouse motion.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_motionacceleration(const double in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
double kylin_hardware_mouse_get_motionacceleration();
/**
* Set the distance in pixels the pointer must move before accelerated mouse motion is activated.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_motionthreshold(const int in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
int kylin_hardware_mouse_get_motionthreshold();
/**
* Set the distance before a drag is started.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_dragthreshold(const int in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
int kylin_hardware_mouse_get_dragthreshold();
/**
* Set the length of a double click.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_doubleclick(const int in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
int kylin_hardware_mouse_get_doubleclick();
/**
* Enable middle mouse button emulation through simultaneous left and right button click.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_middlebuttonenabled(const bool in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
bool kylin_hardware_mouse_get_middlebuttonenabled();
/**
* Highlight the current location of the pointer when the Control key is pressed and released.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_locatepointer(const bool in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
bool kylin_hardware_mouse_get_locatepointer();
/**
* Set font name of the cursor. If unset, the default font is used.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_cursorfont(const char *in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
char *kylin_hardware_mouse_get_cursorfont();
/**
* Set cursor theme name. Used only by Xservers that support Xcursor,such as XFree86 4.3 and later.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_cursortheme(const char *in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
char *kylin_hardware_mouse_get_cursortheme();
/**
* Set the size of the cursor referenced by cursor_theme.
* @param in_arg is the value you want to set.
* @return true if setting successfully.
*/
bool kylin_hardware_mouse_set_cursorsize(const int in_arg);
/**
* Get the value of key.
* @return the value of key.
*/
int kylin_hardware_mouse_get_cursorsize();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,296 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "mouse-dbus.h"
#include "src/common/kylin-print.h"
#include "mouse-generated.h"
#include <stdbool.h>
#define schemaID "org.mate.peripherals-mouse"
static GMainLoop *pLoop = NULL;
static Mouse *pSkeleton = NULL;
static gboolean kylin_set_bool(Mouse* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gboolean value;
gint i;
g_variant_get(in_arg, "(sb)", &key, &value);
if(value==false)i=0;
else i=1;
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_boolean(setting,key,value);
g_object_unref(setting);
g_settings_sync();
mouse_complete_transfer_bool_value(object, invocation, retv);
print_info("(%s, %d)\n", key, i);
return TRUE;
}
static gboolean kylin_get_bool(Mouse *object,
GDBusMethodInvocation* invocation,
char *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gboolean ret=g_settings_get_boolean(setting, in_arg);
g_object_unref(setting);
mouse_complete_get_bool_value(object, invocation, ret);
return TRUE;
}
static gboolean kylin_set_double(Mouse* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
double value;
g_variant_get(in_arg, "(sd)", &key, &value);
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_double(setting,key,value);
g_object_unref(setting);
g_settings_sync();
mouse_complete_transfer_double_value(object, invocation, retv);
print_info("(%s, %f)\n", key, value);
return TRUE;
}
static gboolean kylin_get_double(Mouse *object,
GDBusMethodInvocation* invocation,
char *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gdouble ret=g_settings_get_double(setting, in_arg);
g_object_unref(setting);
mouse_complete_get_double_value(object, invocation, ret);
return TRUE;
}
static gboolean kylin_set_int(Mouse* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gint value;
g_variant_get(in_arg, "(si)", &key, &value);
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_int(setting,key,value);
g_object_unref(setting);
g_settings_sync();
mouse_complete_transfer_int_value(object, invocation, retv);
print_info("(%s, %d)\n", key, value);
return TRUE;
}
static gboolean kylin_get_int(Mouse *object,
GDBusMethodInvocation* invocation,
char *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gint ret=g_settings_get_int(setting, in_arg);
g_object_unref(setting);
mouse_complete_get_int_value(object, invocation, ret);
return TRUE;
}
static gboolean kylin_set_char(Mouse* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gchar *value=NULL;
g_variant_get(in_arg, "(ss)", &key, &value);
GSettings *setting=g_settings_new(schemaID);
gboolean retv=g_settings_set_string(setting,key,value);
g_object_unref(setting);
g_settings_sync();
mouse_complete_transfer_string_value(object, invocation, retv);
print_info("(%s, %s)\n", key, value);
return TRUE;
}
static gboolean kylin_get_char(Mouse *object,
GDBusMethodInvocation* invocation,
char *in_arg,
gpointer user_data)
{
GSettings *setting=g_settings_new(schemaID);
gchar *ret=g_settings_get_string(setting, in_arg);
g_object_unref(setting);
mouse_complete_get_string_value(object, invocation,ret);
return TRUE;
}
static void bus_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
GError *pError = NULL;
/** Second step: Try to get a connection to the given bus. */
pSkeleton = mouse_skeleton_new();
/** Third step: Attach to dbus signals. */
(void) g_signal_connect(pSkeleton, "handle-transfer-bool-value", G_CALLBACK(kylin_set_bool), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-bool-value", G_CALLBACK(kylin_get_bool), NULL);
(void) g_signal_connect(pSkeleton, "handle-transfer-double-value", G_CALLBACK(kylin_set_double), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-double-value", G_CALLBACK(kylin_get_double), NULL);
(void) g_signal_connect(pSkeleton, "handle-transfer-int-value", G_CALLBACK(kylin_set_int), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-int-value", G_CALLBACK(kylin_get_int), NULL);
(void) g_signal_connect(pSkeleton, "handle-transfer-string-value", G_CALLBACK(kylin_set_char), NULL);
(void) g_signal_connect(pSkeleton, "handle-get-string-value", G_CALLBACK(kylin_get_char), NULL);
/** Fourth step: Export interface skeleton. */
(void)g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(pSkeleton),
connection,
MOUSE_OBJECT_PATH,
&pError);
if(pError != NULL){
print_error("Error: Failed to export object. Reason: %s.\n", pError->message);
g_error_free(pError);
g_main_loop_quit(pLoop);
}
}
static void name_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
print_info("name_acquired_cb call, Acquired bus name: %s.\n", MOUSE_BUS_NAME);
}
static void name_lost_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
if(connection == NULL)
{
print_error("name_lost_cb call, Error: Failed to connect to dbus.\n");
}
else
{
print_error("name_lost_cb call, Error: Failed to obtain bus name: %s.\n", MOUSE_BUS_NAME);
}
g_main_loop_quit(pLoop);
}
void* run(void* para)
{
/** Start the Main Event Loop which manages all available sources of events */
g_main_loop_run( pLoop );
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if (err != 0)
{
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusCommunicationServer(void)
{
bool bRet = TRUE;
g_print("InitDBusCommunicationServer: Server started.\n");
/** create main loop, but do not start it. */
pLoop = g_main_loop_new(NULL, FALSE);
/** first step: connect to dbus */
(void)g_bus_own_name(MOUSE_BUS,
MOUSE_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
&bus_acquired_cb,
&name_acquired_cb,
&name_lost_cb,
NULL,
NULL);
thread_create();
return bRet;
}
bool DeinitDBusCommunicationServer(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}
int main(void)
{
InitDBusCommunicationServer();
sleep(100);
DeinitDBusCommunicationServer();
return 0;
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __MOUSEDBUS_H__
#define __MOUSEDBUS_H__
#include <gio/gio.h> /* Bus define */
#ifdef __cplusplus
extern "C" {
#endif
#define MOUSE_BUS G_BUS_TYPE_SESSION
#define MOUSE_BUS_NAME "cn.kylinos.mouse"
#define MOUSE_OBJECT_PATH "/cn/kylinos/mouse"
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,403 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __MOUSE_GENERATED_H__
#define __MOUSE_GENERATED_H__
#include <gio/gio.h>
G_BEGIN_DECLS
/* ------------------------------------------------------------------------ */
/* Declarations for cn.kylinos.mouse */
#define TYPE_MOUSE (mouse_get_type ())
#define MOUSE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_MOUSE, Mouse))
#define IS_MOUSE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_MOUSE))
#define MOUSE_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), TYPE_MOUSE, MouseIface))
struct _Mouse;
typedef struct _Mouse Mouse;
typedef struct _MouseIface MouseIface;
struct _MouseIface
{
GTypeInterface parent_iface;
gboolean (*handle_get_bool_value) (
Mouse *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_get_double_value) (
Mouse *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_get_int_value) (
Mouse *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_get_string_value) (
Mouse *object,
GDBusMethodInvocation *invocation,
const gchar *arg_InArg);
gboolean (*handle_transfer_bool_value) (
Mouse *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
gboolean (*handle_transfer_double_value) (
Mouse *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
gboolean (*handle_transfer_int_value) (
Mouse *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
gboolean (*handle_transfer_string_value) (
Mouse *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
};
GType mouse_get_type (void) G_GNUC_CONST;
GDBusInterfaceInfo *mouse_interface_info (void);
guint mouse_override_properties (GObjectClass *klass, guint property_id_begin);
/* D-Bus method call completion functions: */
void mouse_complete_transfer_bool_value (
Mouse *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void mouse_complete_get_bool_value (
Mouse *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void mouse_complete_transfer_string_value (
Mouse *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void mouse_complete_get_string_value (
Mouse *object,
GDBusMethodInvocation *invocation,
const gchar *OutArg);
void mouse_complete_transfer_int_value (
Mouse *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void mouse_complete_get_int_value (
Mouse *object,
GDBusMethodInvocation *invocation,
gint OutArg);
void mouse_complete_transfer_double_value (
Mouse *object,
GDBusMethodInvocation *invocation,
gboolean OutArg);
void mouse_complete_get_double_value (
Mouse *object,
GDBusMethodInvocation *invocation,
gdouble OutArg);
/* D-Bus method calls: */
void mouse_call_transfer_bool_value (
Mouse *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mouse_call_transfer_bool_value_finish (
Mouse *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean mouse_call_transfer_bool_value_sync (
Mouse *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void mouse_call_get_bool_value (
Mouse *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mouse_call_get_bool_value_finish (
Mouse *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean mouse_call_get_bool_value_sync (
Mouse *proxy,
const gchar *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void mouse_call_transfer_string_value (
Mouse *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mouse_call_transfer_string_value_finish (
Mouse *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean mouse_call_transfer_string_value_sync (
Mouse *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void mouse_call_get_string_value (
Mouse *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mouse_call_get_string_value_finish (
Mouse *proxy,
gchar **out_OutArg,
GAsyncResult *res,
GError **error);
gboolean mouse_call_get_string_value_sync (
Mouse *proxy,
const gchar *arg_InArg,
gchar **out_OutArg,
GCancellable *cancellable,
GError **error);
void mouse_call_transfer_int_value (
Mouse *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mouse_call_transfer_int_value_finish (
Mouse *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean mouse_call_transfer_int_value_sync (
Mouse *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void mouse_call_get_int_value (
Mouse *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mouse_call_get_int_value_finish (
Mouse *proxy,
gint *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean mouse_call_get_int_value_sync (
Mouse *proxy,
const gchar *arg_InArg,
gint *out_OutArg,
GCancellable *cancellable,
GError **error);
void mouse_call_transfer_double_value (
Mouse *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mouse_call_transfer_double_value_finish (
Mouse *proxy,
gboolean *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean mouse_call_transfer_double_value_sync (
Mouse *proxy,
GVariant *arg_InArg,
gboolean *out_OutArg,
GCancellable *cancellable,
GError **error);
void mouse_call_get_double_value (
Mouse *proxy,
const gchar *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mouse_call_get_double_value_finish (
Mouse *proxy,
gdouble *out_OutArg,
GAsyncResult *res,
GError **error);
gboolean mouse_call_get_double_value_sync (
Mouse *proxy,
const gchar *arg_InArg,
gdouble *out_OutArg,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_MOUSE_PROXY (mouse_proxy_get_type ())
#define MOUSE_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_MOUSE_PROXY, MouseProxy))
#define MOUSE_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_MOUSE_PROXY, MouseProxyClass))
#define MOUSE_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_MOUSE_PROXY, MouseProxyClass))
#define IS_MOUSE_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_MOUSE_PROXY))
#define IS_MOUSE_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_MOUSE_PROXY))
typedef struct _MouseProxy MouseProxy;
typedef struct _MouseProxyClass MouseProxyClass;
typedef struct _MouseProxyPrivate MouseProxyPrivate;
struct _MouseProxy
{
/*< private >*/
GDBusProxy parent_instance;
MouseProxyPrivate *priv;
};
struct _MouseProxyClass
{
GDBusProxyClass parent_class;
};
GType mouse_proxy_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MouseProxy, g_object_unref)
#endif
void mouse_proxy_new (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Mouse *mouse_proxy_new_finish (
GAsyncResult *res,
GError **error);
Mouse *mouse_proxy_new_sync (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
void mouse_proxy_new_for_bus (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Mouse *mouse_proxy_new_for_bus_finish (
GAsyncResult *res,
GError **error);
Mouse *mouse_proxy_new_for_bus_sync (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_MOUSE_SKELETON (mouse_skeleton_get_type ())
#define MOUSE_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_MOUSE_SKELETON, MouseSkeleton))
#define MOUSE_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_MOUSE_SKELETON, MouseSkeletonClass))
#define MOUSE_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_MOUSE_SKELETON, MouseSkeletonClass))
#define IS_MOUSE_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_MOUSE_SKELETON))
#define IS_MOUSE_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_MOUSE_SKELETON))
typedef struct _MouseSkeleton MouseSkeleton;
typedef struct _MouseSkeletonClass MouseSkeletonClass;
typedef struct _MouseSkeletonPrivate MouseSkeletonPrivate;
struct _MouseSkeleton
{
/*< private >*/
GDBusInterfaceSkeleton parent_instance;
MouseSkeletonPrivate *priv;
};
struct _MouseSkeletonClass
{
GDBusInterfaceSkeletonClass parent_class;
};
GType mouse_skeleton_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MouseSkeleton, g_object_unref)
#endif
Mouse *mouse_skeleton_new (void);
G_END_DECLS
#endif /* __MOUSE_GENERATED_H__ */

View File

@ -0,0 +1,131 @@
COMM_PRINT= -L$(top_srcdir)/src/common -lukui-print
COMM_GSETTINGS= -L$(top_srcdir)/src/common -lukui-gsettings
#generate the .c and .h file which used by client and server side by XML file
#$(top_srcdir) represents the top-level directory of the project
POWER_XML = $(top_srcdir)/data/cn.kylinos.power.xml
GENERATED_POW = power-generated
SCREEN_XML = $(top_srcdir)/data/cn.kylinos.screensaver.xml
GENERATED_SCREEN = screensaver-generated
SESS_XML = $(top_srcdir)/data/cn.kylinos.session.xml
GENERATED_SESS = session-generated
power-generated.h power-generated.c: $(POWER_XML)
gdbus-codegen --interface-prefix cn.kylinos. --generate-c-code $(GENERATED_POW) $(POWER_XML)
screensaver-generated.h screensaver-generated.c: $(SCREEN_XML)
gdbus-codegen --interface-prefix cn.kylinos. --generate-c-code $(GENERATED_SCREEN) $(SCREEN_XML)
session-generated.h session-generated.c: $(SESS_XML)
gdbus-codegen --interface-prefix cn.kylinos. --generate-c-code $(GENERATED_SESS) $(SESS_XML)
#Generata binary file
lib_LTLIBRARIES = libukui-powerclient.la libukui-screensaverclient.la libukui-sessionclient.la
#gcc -wall: displays all the errors and warning information when compiling
#gcc -g: add the debugging code when compiling
COMM_CFS = -Wall -g
#Add the dependent source file for libpowerclient.la
#power-generated.c must be front of kylin-power-interface.c
libukui_powerclient_la_SOURCES = power-generated.c kylin-power-interface.c \
$(NULL)
#The header files that need to be installed
include_HEADERS= kylin-power-interface.h \
kylin-screensaver-interface.h \
kylin-session-interface.h \
$(NULL)
#Additional C compiler flags
libukui_powerclient_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_powerclient_la_LDFLAGS= $(COMM_PRINT) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Add the dependent source file for libscreensaverclient.la
#screensaver-generated.c must be front of kylin-screensaver-interface.c
libukui_screensaverclient_la_SOURCES = screensaver-generated.c kylin-screensaver-interface.c \
$(NULL)
#Additional C compiler flags
libukui_screensaverclient_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_screensaverclient_la_LDFLAGS= $(COMM_PRINT) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Add the dependent source file for libsessionclient.la
#session-generated.c must be front of kylin-session-interface.c
libukui_sessionclient_la_SOURCES = session-generated.c kylin-session-interface.c \
$(NULL)
#Additional C compiler flags
libukui_sessionclient_la_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
libukui_sessionclient_la_LDFLAGS= $(COMM_PRINT) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Generata binary file
bin_PROGRAMS = ukui-powerserver ukui-screensaverserver ukui-sessionserver
#Add the dependent source file for powerserver
ukui_powerserver_SOURCES = \
power-generated.h power-generated.c \
kylin-power-server.c \
$(NULL)
#Additional C compiler flags
ukui_powerserver_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
ukui_powerserver_LDFLAGS= $(COMM_PRINT) $(COMM_GSETTINGS) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Add the dependent source file for screensaverserver
ukui_screensaverserver_SOURCES = \
screensaver-generated.h screensaver-generated.c \
kylin-screensaver-server.c \
$(NULL)
#Additional C compiler flags
ukui_screensaverserver_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
ukui_screensaverserver_LDFLAGS= $(COMM_PRINT) $(COMM_GSETTINGS) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)
#Add the dependent source file for sessionserver
ukui_sessionserver_SOURCES = \
session-generated.h session-generated.c \
kylin-session-server.c \
$(NULL)
#Additional C compiler flags
ukui_sessionserver_CFLAGS= $(COMM_CFS) \
$(GLIB_2_CFLAGS) $(GIO_2_CFLAGS) $(GIO_UNIX_2_CFLAGS) \
$(NULL)
#Additional link objects
ukui_sessionserver_LDFLAGS= $(COMM_PRINT) $(COMM_GSETTINGS) \
$(GLIB_2_LIBS) $(GIO_2_LIBS) $(GIO_UNIX_2_LIBS) \
$(NULL)

View File

@ -0,0 +1,203 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "power-dbus.h"
#include "kylin-power-interface.h"
#include "src/common/kylin-print.h"
#include "power-generated.h"
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdbool.h>
#define SCB "sleep-computer-battery"
#define SCA "sleep-computer-ac"
#define SDB "sleep-display-battery"
#define SDA "sleep-display-ac"
#define IP "icon-policy"
static GMainLoop *pLoop = NULL;
static GDBusConnection *pConnection = NULL;
static Power *pProxy = NULL;
void kylin_hardware_power_sleepcomputerbattery(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=SCB;
arg=g_variant_new("(si)",key,in_arg);
power_call_transfer_int_value_sync(pProxy, arg, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_power_sleepcomputerbattery. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return;
}
void kylin_hardware_power_sleepcomputerac(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=SCA;
arg=g_variant_new("(si)",key,in_arg);
power_call_transfer_int_value_sync(pProxy, arg, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_power_sleepcomputerac. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return;
}
void kylin_hardware_power_sleepdisplaybattery(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=SDB;
arg=g_variant_new("(si)",key,in_arg);
power_call_transfer_int_value_sync(pProxy, arg, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_power_sleepdisplaybattery. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return;
}
void kylin_hardware_power_sleepdisplayac(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=SDA;
arg=g_variant_new("(si)",key,in_arg);
power_call_transfer_int_value_sync(pProxy, arg, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_power_sleepdisplayac. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return;
}
void kylin_hardware_power_iconpolicy(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=IP;
arg=g_variant_new("(si)",key,in_arg);
power_call_transfer_int_value_sync(pProxy, arg, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_power_iconpolicy. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return;
}
void *run(void* arg)
{
/** start the main event loop which manages all available sources of events */
g_main_loop_run(pLoop);
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if(0 != err){
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusPower(void)
{
bool bRet = TRUE;
GError *pConnError = NULL;
GError *pProxyError = NULL;
do{
bRet = TRUE;
pLoop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
/** First step: get a connection */
pConnection = g_bus_get_sync(POWER_BUS, NULL, &pConnError);
if (NULL == pConnError){
/** Second step: try to get a connection to the given bus.*/
pProxy = power_proxy_new_sync(pConnection,
G_DBUS_PROXY_FLAGS_NONE,
POWER_BUS_NAME,
POWER_OBJECT_PATH,
NULL,
&pProxyError);
if (0 == pProxy){
print_error("InitDBusCommunication: Failed to create proxy. Reason: %s.\n", pProxyError->message);
g_error_free(pProxyError);
bRet = FALSE;
}
}
else{
print_error("InitDBusCommunication: Failed to connect to dbus. Reason: %s.\n", pConnError->message);
g_error_free(pConnError);
bRet = FALSE;
}
}while(FALSE == bRet);
thread_create();
return bRet;
}
bool DeInitDBusPower(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINPOWERINTERFACE_H__
#define __KYLINPOWERINTERFACE_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
//Initialize the DBus Communication
bool InitDBusPower(void);
//Delete the DBus Communication
bool DeInitDBusPower(void);
/*
* Sleep timeout computer when on battery
*/
void kylin_hardware_power_sleepcomputerbattery(const int in_arg);
/*
* Sleep timeout computer when on AC
*/
void kylin_hardware_power_sleepcomputerac(const int in_arg);
/*
* Sleep timeout display when on battery
*/
void kylin_hardware_power_sleepdisplaybattery(const int in_arg);
/*
* Sleep timeout display when on AC
*/
void kylin_hardware_power_sleepdisplayac(const int in_arg);
/*
* Display options for the notification icon.
* Possible values are:
* @in_arg is equal to 0, "always";
* @in_arg is equal to 1, "present";
* @in_arg is equal to 2, "charge";
* @in_arg is equal to 3, "low";
* @in_arg is equal to 4, "critical";
* @in_arg is equal to 5, "never".
*/
void kylin_hardware_power_iconpolicy(const int in_arg);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,178 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "power-dbus.h"
#include "src/common/kylin-gsettings-set.h"
#include "src/common/kylin-print.h"
#include "power-generated.h"
#include <string.h>
#include <stdbool.h>
#define schemaID "org.mate.power-manager"
static GMainLoop *pLoop = NULL;
static Power *pSkeleton = NULL;
static gboolean kylin_set_int(Power* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gint value;
g_variant_get(in_arg, "(si)", &key, &value);
power_complete_transfer_int_value(object, invocation);
GSettings *setting=gsettings_get_schemaID(schemaID);
if(strcmp(key,"icon-policy")==0)
gsettings_set_enum(setting, key, value);
else gsettings_set_int(setting, key, value);
Dec_ref(setting);
print_info("(%s, %d)\n", key, value);
return TRUE;
}
static void bus_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
GError *pError = NULL;
/** Second step: Try to get a connection to the given bus. */
pSkeleton = power_skeleton_new();
/** Third step: Attach to dbus signals. */
(void) g_signal_connect(pSkeleton, "handle-transfer-int-value", G_CALLBACK(kylin_set_int), NULL);
/** Fourth step: Export interface skeleton. */
(void)g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(pSkeleton),
connection,
POWER_OBJECT_PATH,
&pError);
if(pError != NULL){
print_error("Error: Failed to export object. Reason: %s.\n", pError->message);
g_error_free(pError);
g_main_loop_quit(pLoop);
}
}
static void name_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
print_info("name_acquired_cb call, Acquired bus name: %s.\n", POWER_BUS_NAME);
}
static void name_lost_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
if(connection == NULL)
{
print_error("name_lost_cb call, Error: Failed to connect to dbus.\n");
}
else
{
print_error("name_lost_cb call, Error: Failed to obtain bus name: %s.\n", POWER_BUS_NAME);
}
g_main_loop_quit(pLoop);
}
void* run(void* para)
{
/** Start the Main Event Loop which manages all available sources of events */
g_main_loop_run( pLoop );
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if (err != 0)
{
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusCommunicationServer(void)
{
bool bRet = TRUE;
g_print("InitDBusCommunicationServer: Server started.\n");
/** create main loop, but do not start it. */
pLoop = g_main_loop_new(NULL, FALSE);
/** first step: connect to dbus */
(void)g_bus_own_name(POWER_BUS,
POWER_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
&bus_acquired_cb,
&name_acquired_cb,
&name_lost_cb,
NULL,
NULL);
thread_create();
return bRet;
}
bool DeinitDBusCommunicationServer(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}
int main(void)
{
InitDBusCommunicationServer();
sleep(100);
DeinitDBusCommunicationServer();
return 0;
}

View File

@ -0,0 +1,147 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "screensaver-dbus.h"
#include "kylin-screensaver-interface.h"
#include "src/common/kylin-print.h"
#include "screensaver-generated.h"
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdbool.h>
#define IAE "idle-activation-enabled"
#define LE "lock-enabled"
static GMainLoop *pLoop = NULL;
static GDBusConnection *pConnection = NULL;
static Screensaver *pProxy = NULL;
void kylin_hardware_power_idleactivationenabled(const bool in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=IAE;
arg=g_variant_new("(sb)", key, in_arg);
screensaver_call_transfer_bool_value_sync(pProxy, arg, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_power_idleactivationenabled. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return;
}
void kylin_hardware_power_lockenabled(const bool in_arg)
{
GError* pError=NULL;
GVariant* arg=NULL;
gchar *key=LE;
arg=g_variant_new("(sb)", key, in_arg);
screensaver_call_transfer_bool_value_sync(pProxy, arg, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_power_lockenabled. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return;
}
void *run(void* arg)
{
/** start the main event loop which manages all available sources of events */
g_main_loop_run(pLoop);
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if(0 != err){
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusScreensaver(void)
{
bool bRet = TRUE;
GError *pConnError = NULL;
GError *pProxyError = NULL;
do{
bRet = TRUE;
pLoop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
/** First step: get a connection */
pConnection = g_bus_get_sync(SCREENSAVER_BUS, NULL, &pConnError);
if (NULL == pConnError){
/** Second step: try to get a connection to the given bus.*/
pProxy = screensaver_proxy_new_sync(pConnection,
G_DBUS_PROXY_FLAGS_NONE,
SCREENSAVER_BUS_NAME,
SCREENSAVER_OBJECT_PATH,
NULL,
&pProxyError);
if (0 == pProxy){
print_error("InitDBusCommunication: Failed to create proxy. Reason: %s.\n", pProxyError->message);
g_error_free(pProxyError);
bRet = FALSE;
}
}
else{
print_error("InitDBusCommunication: Failed to connect to dbus. Reason: %s.\n", pConnError->message);
g_error_free(pConnError);
bRet = FALSE;
}
}while(FALSE == bRet);
thread_create();
return bRet;
}
bool DeInitDBusScreensaver(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINSCREENSAVERINTERFACE_H__
#define __KYLINSCREENSAVERINTERFACE_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
//Initialize the DBus Communication
bool InitDBusScreensaver(void);
//Delete the DBus Communication
bool DeInitDBusScreensaver(void);
/*
* Set this to TRUE to activate the screensaver when the session is idle.
*
*/
void kylin_hardware_power_idleactivationenabled(const bool in_arg);
/*
* Set this to TRUE to lock the screen when the screensaver goes active.
*/
void kylin_hardware_power_lockenabled(const bool in_arg);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,179 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "screensaver-dbus.h"
#include "src/common/kylin-gsettings-set.h"
#include "src/common/kylin-print.h"
#include "screensaver-generated.h"
#include <string.h>
#include <stdbool.h>
#define schemaID "org.mate.screensaver"
static GMainLoop *pLoop = NULL;
static Screensaver *pSkeleton = NULL;
static gboolean kylin_set_bool(Screensaver* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gboolean value;
gint i;
g_variant_get(in_arg, "(sb)", &key, &value);
if(value==false)i=0;
else i=1;
screensaver_complete_transfer_bool_value(object, invocation);
GSettings *setting=gsettings_get_schemaID(schemaID);
gsettings_set_boolean(setting, key, value);
Dec_ref(setting);
print_info("(%s, %d)\n", key, i);
return TRUE;
}
static void bus_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
GError *pError = NULL;
/** Second step: Try to get a connection to the given bus. */
pSkeleton = screensaver_skeleton_new();
/** Third step: Attach to dbus signals. */
(void) g_signal_connect(pSkeleton, "handle-transfer-bool-value", G_CALLBACK(kylin_set_bool), NULL);
/** Fourth step: Export interface skeleton. */
(void)g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(pSkeleton),
connection,
SCREENSAVER_OBJECT_PATH,
&pError);
if(pError != NULL){
print_error("Error: Failed to export object. Reason: %s.\n", pError->message);
g_error_free(pError);
g_main_loop_quit(pLoop);
}
}
static void name_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
print_info("name_acquired_cb call, Acquired bus name: %s.\n", SCREENSAVER_BUS_NAME);
}
static void name_lost_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
if(connection == NULL)
{
print_error("name_lost_cb call, Error: Failed to connect to dbus.\n");
}
else
{
print_error("name_lost_cb call, Error: Failed to obtain bus name: %s.\n", SCREENSAVER_BUS_NAME);
}
g_main_loop_quit(pLoop);
}
void* run(void* para)
{
/** Start the Main Event Loop which manages all available sources of events */
g_main_loop_run( pLoop );
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if (err != 0)
{
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusCommunicationServer(void)
{
bool bRet = TRUE;
g_print("InitDBusCommunicationServer: Server started.\n");
/** create main loop, but do not start it. */
pLoop = g_main_loop_new(NULL, FALSE);
/** first step: connect to dbus */
(void)g_bus_own_name(SCREENSAVER_BUS,
SCREENSAVER_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
&bus_acquired_cb,
&name_acquired_cb,
&name_lost_cb,
NULL,
NULL);
thread_create();
return bRet;
}
bool DeinitDBusCommunicationServer(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}
int main(void)
{
InitDBusCommunicationServer();
sleep(100);
DeinitDBusCommunicationServer();
return 0;
}

View File

@ -0,0 +1,131 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "session-dbus.h"
#include "kylin-session-interface.h"
#include "src/common/kylin-print.h"
#include "session-generated.h"
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdbool.h>
#define ID "idle-delay"
static GMainLoop *pLoop = NULL;
static GDBusConnection *pConnection = NULL;
static Session *pProxy = NULL;
void kylin_hardware_power_idledelay(const int in_arg)
{
GError* pError=NULL;
GVariant *arg=NULL;
gchar *key=ID;
arg=g_variant_new("(si)",key,in_arg);
session_call_transfer_int_value_sync(pProxy, arg, NULL, &pError);
if (pError != NULL){
print_error("Failed to call method kylin_hardware_power_idledelay. Reason: %s.\n", pError->message);
g_error_free(pError);
}
return;
}
void *run(void* arg)
{
/** start the main event loop which manages all available sources of events */
g_main_loop_run(pLoop);
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if(0 != err){
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusSession(void)
{
bool bRet = TRUE;
GError *pConnError = NULL;
GError *pProxyError = NULL;
do{
bRet = TRUE;
pLoop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
/** First step: get a connection */
pConnection = g_bus_get_sync(SESSION_BUS, NULL, &pConnError);
if (NULL == pConnError){
/** Second step: try to get a connection to the given bus.*/
pProxy = session_proxy_new_sync(pConnection,
G_DBUS_PROXY_FLAGS_NONE,
SESSION_BUS_NAME,
SESSION_OBJECT_PATH,
NULL,
&pProxyError);
if (0 == pProxy){
print_error("InitDBusCommunication: Failed to create proxy. Reason: %s.\n", pProxyError->message);
g_error_free(pProxyError);
bRet = FALSE;
}
}
else{
print_error("InitDBusCommunication: Failed to connect to dbus. Reason: %s.\n", pConnError->message);
g_error_free(pConnError);
bRet = FALSE;
}
}while(FALSE == bRet);
thread_create();
return bRet;
}
bool DeInitDBusSession(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __KYLINSESSIONINTERFACE_H__
#define __KYLINSESSIONINTERFACE_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
//Initialize the DBus Communication
bool InitDBusSession(void);
//Delete the DBus Communication
bool DeInitDBusSession(void);
/*
* Time before session is considered idle
*/
void kylin_hardware_power_idledelay(const int in_arg);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,176 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include <stdio.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "session-dbus.h"
#include "src/common/kylin-gsettings-set.h"
#include "src/common/kylin-print.h"
#include "session-generated.h"
#include <string.h>
#include <stdbool.h>
#define schemaID "org.mate.session"
static GMainLoop *pLoop = NULL;
static Session *pSkeleton = NULL;
static gboolean kylin_set_int(Session* object,
GDBusMethodInvocation* invocation,
GVariant *in_arg,
gpointer user_data)
{
gchar *key=NULL;
gint value;
g_variant_get(in_arg, "(si)", &key, &value);
session_complete_transfer_int_value(object, invocation);
GSettings *setting=gsettings_get_schemaID(schemaID);
gsettings_set_int(setting, key, value);
Dec_ref(setting);
print_info("(%s, %d)\n", key, value);
return TRUE;
}
static void bus_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
GError *pError = NULL;
/** Second step: Try to get a connection to the given bus. */
pSkeleton = session_skeleton_new();
/** Third step: Attach to dbus signals. */
(void) g_signal_connect(pSkeleton, "handle-transfer-int-value", G_CALLBACK(kylin_set_int), NULL);
/** Fourth step: Export interface skeleton. */
(void)g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(pSkeleton),
connection,
SESSION_OBJECT_PATH,
&pError);
if(pError != NULL){
print_error("Error: Failed to export object. Reason: %s.\n", pError->message);
g_error_free(pError);
g_main_loop_quit(pLoop);
}
}
static void name_acquired_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
print_info("name_acquired_cb call, Acquired bus name: %s.\n", SESSION_BUS_NAME);
}
static void name_lost_cb(GDBusConnection* connection,
const gchar* bus_name,
gpointer user_data)
{
if(connection == NULL)
{
print_error("name_lost_cb call, Error: Failed to connect to dbus.\n");
}
else
{
print_error("name_lost_cb call, Error: Failed to obtain bus name: %s.\n", SESSION_BUS_NAME);
}
g_main_loop_quit(pLoop);
}
void* run(void* para)
{
/** Start the Main Event Loop which manages all available sources of events */
g_main_loop_run( pLoop );
return ((void*)0);
}
int thread_create(void)
{
int err;
pthread_t thr;
err = pthread_create(&thr, NULL, run, NULL);
if (err != 0)
{
print_error("Can't create thread: %s\n", strerror(err));
}
return err;
}
bool InitDBusCommunicationServer(void)
{
bool bRet = TRUE;
g_print("InitDBusCommunicationServer: Server started.\n");
/** create main loop, but do not start it. */
pLoop = g_main_loop_new(NULL, FALSE);
/** first step: connect to dbus */
(void)g_bus_own_name(SESSION_BUS,
SESSION_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
&bus_acquired_cb,
&name_acquired_cb,
&name_lost_cb,
NULL,
NULL);
thread_create();
return bRet;
}
bool DeinitDBusCommunicationServer(void)
{
bool bRet = FALSE;
if(0 != pLoop){
g_main_loop_quit(pLoop);
g_main_loop_unref(pLoop);
bRet = TRUE;
}
return bRet;
}
int main(void)
{
InitDBusCommunicationServer();
sleep(100);
DeinitDBusCommunicationServer();
return 0;
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __POWERDBUS_H__
#define __POWERDBUS_H__
#include <gio/gio.h> /* Bus define */
#ifdef __cplusplus
extern "C" {
#endif
#define POWER_BUS G_BUS_TYPE_SESSION
#define POWER_BUS_NAME "cn.kylinos.power"
#define POWER_OBJECT_PATH "/cn/kylinos/power"
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,190 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __POWER_GENERATED_H__
#define __POWER_GENERATED_H__
#include <gio/gio.h>
G_BEGIN_DECLS
/* ------------------------------------------------------------------------ */
/* Declarations for cn.kylinos.power */
#define TYPE_POWER (power_get_type ())
#define POWER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_POWER, Power))
#define IS_POWER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_POWER))
#define POWER_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), TYPE_POWER, PowerIface))
struct _Power;
typedef struct _Power Power;
typedef struct _PowerIface PowerIface;
struct _PowerIface
{
GTypeInterface parent_iface;
gboolean (*handle_transfer_int_value) (
Power *object,
GDBusMethodInvocation *invocation,
GVariant *arg_InArg);
};
GType power_get_type (void) G_GNUC_CONST;
GDBusInterfaceInfo *power_interface_info (void);
guint power_override_properties (GObjectClass *klass, guint property_id_begin);
/* D-Bus method call completion functions: */
void power_complete_transfer_int_value (
Power *object,
GDBusMethodInvocation *invocation);
/* D-Bus method calls: */
void power_call_transfer_int_value (
Power *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean power_call_transfer_int_value_finish (
Power *proxy,
GAsyncResult *res,
GError **error);
gboolean power_call_transfer_int_value_sync (
Power *proxy,
GVariant *arg_InArg,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_POWER_PROXY (power_proxy_get_type ())
#define POWER_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_POWER_PROXY, PowerProxy))
#define POWER_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_POWER_PROXY, PowerProxyClass))
#define POWER_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_POWER_PROXY, PowerProxyClass))
#define IS_POWER_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_POWER_PROXY))
#define IS_POWER_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_POWER_PROXY))
typedef struct _PowerProxy PowerProxy;
typedef struct _PowerProxyClass PowerProxyClass;
typedef struct _PowerProxyPrivate PowerProxyPrivate;
struct _PowerProxy
{
/*< private >*/
GDBusProxy parent_instance;
PowerProxyPrivate *priv;
};
struct _PowerProxyClass
{
GDBusProxyClass parent_class;
};
GType power_proxy_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PowerProxy, g_object_unref)
#endif
void power_proxy_new (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Power *power_proxy_new_finish (
GAsyncResult *res,
GError **error);
Power *power_proxy_new_sync (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
void power_proxy_new_for_bus (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Power *power_proxy_new_for_bus_finish (
GAsyncResult *res,
GError **error);
Power *power_proxy_new_for_bus_sync (
GBusType bus_type,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
/* ---- */
#define TYPE_POWER_SKELETON (power_skeleton_get_type ())
#define POWER_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_POWER_SKELETON, PowerSkeleton))
#define POWER_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_POWER_SKELETON, PowerSkeletonClass))
#define POWER_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_POWER_SKELETON, PowerSkeletonClass))
#define IS_POWER_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_POWER_SKELETON))
#define IS_POWER_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_POWER_SKELETON))
typedef struct _PowerSkeleton PowerSkeleton;
typedef struct _PowerSkeletonClass PowerSkeletonClass;
typedef struct _PowerSkeletonPrivate PowerSkeletonPrivate;
struct _PowerSkeleton
{
/*< private >*/
GDBusInterfaceSkeleton parent_instance;
PowerSkeletonPrivate *priv;
};
struct _PowerSkeletonClass
{
GDBusInterfaceSkeletonClass parent_class;
};
GType power_skeleton_get_type (void) G_GNUC_CONST;
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PowerSkeleton, g_object_unref)
#endif
Power *power_skeleton_new (void);
G_END_DECLS
#endif /* __POWER_GENERATED_H__ */

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __SCREENSAVERDBUS_H__
#define __SCREENSAVERDBUS_H__
#include <gio/gio.h> /* Bus define */
#ifdef __cplusplus
extern "C" {
#endif
#define SCREENSAVER_BUS G_BUS_TYPE_SESSION
#define SCREENSAVER_BUS_NAME "cn.kylinos.screensaver"
#define SCREENSAVER_OBJECT_PATH "/cn/kylinos/screensaver"
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More