如何获取可用的DBus接口属性列表?
我正在编写一个跟踪特定类型的USB设备连接的脚本.一种区分要跟踪的连接与所有usb连接的方法我想是检查DBus在usb连接上发送的信号接口的属性.我想得到所有这些属性的列表来选择相关的.
我的代码是:
import sys
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
def deviceAdded(udi):
device = bus.get_object("org.freedesktop.Hal", udi)
device_if = dbus.Interface(device, 'org.freedesktop.Hal.Device')
if device_if.GetPropertyString('info.subsystem') == 'usb_device':
#
# Properties can be accesed like this:
# vendor_id = device_if.GetPropertyInteger('usb_device.vendor_id')
#
# how to get the list of all properties?
#
# do something
def deviceRemoved(udi):
# do something
pass
if __name__ == "__main__":
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(
deviceAdded,
'DeviceAdded',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
bus.add_signal_receiver(
deviceRemoved,
'DeviceRemoved',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
loop …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的 C++ 程序,我试图通过 python 脚本执行它。(我对编写脚本非常陌生)并且我在通过管道读取输出时遇到问题。从我所见,如果没有 EOF,readline() 似乎无法工作,但我希望能够在程序中间读取并使脚本响应输出的内容。它不读取输出,而是挂起 python 脚本:
#!/usr/bin/env python
import subprocess
def call_random_number():
print "Running the random guesser"
rng = subprocess.Popen("./randomNumber", stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
i = 50
rng.stdin.write("%d\n" % i)
output = rng.stdout.readline()
output = rng.stdout.readline()
call_random_number()
Run Code Online (Sandbox Code Playgroud)
c++ 文件生成 1 到 100 之间的随机数,然后检查用户的猜测,直到他们猜对为止
#include<iostream>
#include<cstdlib>
int main(){
std::cout<< "This program generates a random number from 1 to 100 and asks the user to enter guesses until they succuessfully guess the number. It then tells the user how many …
Run Code Online (Sandbox Code Playgroud) 我有两个例子给出相同的结果.
带块:
def self.do_something(object_id)
self.with_params(object_id) do |params|
some_stuff(params)
end
end
def self.with_params(object_id, &block)
find_object_by_id
calculate_params_hash
block.call(params_hash)
end
Run Code Online (Sandbox Code Playgroud)
并与方法:
def self.do_something(object_id)
some_stuff(self.get_params(object_id))
end
def self.get_params(object_id)
find_object_by_id
calculate_params_hash
params_hash
end
Run Code Online (Sandbox Code Playgroud)
第二个解决方案似乎更直接,但我在应用程序代码中找到了第一个解决方案的一些用法.我的问题是:在哪种情况下推荐第一个?每个人的利弊是什么?
我在网上看的例子,Tuple
但我没有看到它的任何理想用途.
意思是,它似乎是一个存储变量的地方.
有什么实际用途吗Tuple
?我喜欢做的是将值传递给元组,然后让它返回3个值,这些值都是字符串.
我看到.pyc和.pyo文件都是编译的python代码.他们和我应该使用的时候有什么区别?
考虑以下具有单个数据成员和结构的结构 operator==
struct S {
int a;
/*constexpr*/ bool operator==(const S& other) const {
return this->a == other.a;
}
};
Run Code Online (Sandbox Code Playgroud)
在使用中,可以像constexpr
初始化列表一样轻松创建两个结构
int main() {
constexpr S s1 = {1};
constexpr S s2 = {2};
constexpr bool b = s1 == s2; // error
return 0;
}
Run Code Online (Sandbox Code Playgroud)
bool比较无法编译,因为==
运算符未标记为constexpr
,如果是,程序编译.
是否所有类别的比较运算符都constexpr
可以标记为constexpr
?我没有看到任何理由,但我也没有看到代码练习这个.
我还会更进一步,询问是否operator*(S, S)
应该一直constexpr
这样.
我正在尝试按照入门步骤构建Google的ligjingle ,并且我已经到达了"Building"部分.
当我发出任何一个
ninja -C out/Debug
Run Code Online (Sandbox Code Playgroud)
要么
ninja -C out/Release
Run Code Online (Sandbox Code Playgroud)
我收到以下错误: 如果您愿意,我也会在pastebin中发布输出
ninja -C out/Debug
ninja: Entering directory `out/Debug'
[3/2606] LINK genmacro
FAILED: cc -Wl,-z,now -Wl,-z,relro -Wl,--fatal-warnings -pthread -Wl,-z,noexecstack -fPIC -B/home/nschoe/workspace/webrtc/jingle/trunk/third_party/binutils/Linux_x64/Release/bin -Wl,--disable-new-dtags -m64 -Wl,--icf=none -fuse-ld=gold -Wl,--gdb-index -o genmacro -Wl,--start-group obj/third_party/yasm/source/patched-yasm/tools/genmacro/genmacro.genmacro.o -Wl,--end-group
/home/nschoe/workspace/webrtc/jingle/trunk/third_party/binutils/Linux_x64/Release/bin/ld.gold: -plugin: unknown option
/home/nschoe/workspace/webrtc/jingle/trunk/third_party/binutils/Linux_x64/Release/bin/ld.gold: use the --help option for usage information
collect2: error: ld returned 1 exit status
[3/2606] CC obj/net/third_party/nss/ssl/libssl.sslauth.o
ninja: build stopped: subcommand failed.
Run Code Online (Sandbox Code Playgroud)
我试过了
ld.gold --help | grep "plugin"
Run Code Online (Sandbox Code Playgroud)
得到了:
--plugin PLUGIN Load …
Run Code Online (Sandbox Code Playgroud) 在昨天处理了一些奇怪的东西之后,我的错误的原因是它std::bind
可能需要更多的参数来进行调用
int f(int);
auto b = std::bind(f);
b(1,2,3,4,5,6); // 2-6 are discarded
Run Code Online (Sandbox Code Playgroud)
cppreference声称:
如果调用g()时提供的某些参数与存储在g中的任何占位符不匹配,则会评估并丢弃未使用的参数.
通过标准搜索我没有看到任何支持这一点.唯一可能使这个没问题的是:
20.9.2/4转发调用包装器是一个调用包装器,可以使用任意参数列表调用,并将参数作为引用传递给包装的可调用对象
因为,(我想)它并没有说"提供所有论据",但我不相信.
我在这个问题中的"为什么"由两部分组成
什么阅读标准明确表示std::bind
允许放弃论证?
为什么这是理想的行为?对我来说,这感觉非常不可靠.我想不出一个我想要的非人为的情况,但可以想到它会成为一个问题.它是否以某种方式使我的实现更容易?
我认为这是一个非常基本的问题,但我找不到类似的东西.
以下代码无法编译(C3668)
struct Param
{
int a;
int b;
};
template <typename T>
struct Foo
{
virtual void doStuff (const T) const = 0;
};
struct Bar : public Foo<Param&>
{
void doStuff (const Param &) const override
{
/*...*/
}
};
Run Code Online (Sandbox Code Playgroud)
它将在删除const后编译
void doStuff (const Param &)
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?我希望const Param& in Foo::doStuff
通过我的界面声明强制执行.相反它似乎被删除了.
我有简单的Angular-Dart组件,尝试ngModel
在单选输入中将connect属性设置为,应用正确编译,但是浏览器控制台给我错误:
No provider found for RadioControlRegistry: RadioControlValueAccessor -> RadioControlRegistry.
Run Code Online (Sandbox Code Playgroud)
代码:
import 'package:angular/angular.dart';
import 'package:angular_forms/angular_forms.dart';
@Component(
selector: 'order-question-test',
template: '''
<input type="radio" name="food" [(ngModel)]="foodChicken">
<input type="radio" name="food" [(ngModel)]="foodFish">
''',
directives: [
coreDirectives,
formDirectives,
]
)
class OrderQuestion {
RadioButtonState foodChicken = RadioButtonState(true, "chicken");
RadioButtonState foodFish = RadioButtonState(false, "fish");
OrderQuestion ();
}
Run Code Online (Sandbox Code Playgroud)
pubspec.yaml
environment:
sdk: '>=2.2.0 <3.0.0'
dependencies:
angular: ^5.2.0
angular_components: ^0.13.0
json_annotation: ^2.0.0
dev_dependencies:
angular_test: ^2.2.0
build_runner: ^1.5.0
build_test: ^0.10.3
build_web_compilers: ^1.0.0
json_serializable: ^2.0.0
pedantic: ^1.0.0
test: ^1.5.1
Run Code Online (Sandbox Code Playgroud)
怎么了?
c++ ×3
python ×3
interface ×2
angular ×1
angular-dart ×1
block ×1
c# ×1
c++11 ×1
c++14 ×1
compilation ×1
constexpr ×1
dart ×1
dbus ×1
gold-linker ×1
ld ×1
linker ×1
pipe ×1
proc ×1
properties ×1
readline ×1
ruby ×1
stdout ×1
subprocess ×1
templates ×1