コード例 #1
0
inline void sample(const int i, const Vec& offset, Vec& sp, Vec& sn) {
	double r0 = hal(0, i) + offset.x;
	double r1 = hal(1, i) + offset.y;
	if (r0 > 1.0) r0 -= 1.0;
	if (r1 > 1.0) r1 -= 1.0;
	const double p = 2.0 * PI * r0, t = 2.0 * acos(sqrt(1.0 - r1));
	const Vec d = Vec(cos(p) * sin(t), cos(t), sin(p) * sin(t));
	sp = sph.p + d * sph.rad;
	sn = d;
}
コード例 #2
0
ファイル: powertray.cpp プロジェクト: dracolinux/powertray
void PowerTray::monitorBattery()
{
    QDBusConnection conn = QDBusConnection::systemBus();
    QDBusInterface hal("org.freedesktop.Hal","/org/freedesktop/Hal/Manager","org.freedesktop.Hal.Manager",conn);
    QDBusMessage msg = hal.call("FindDeviceByCapability", "battery");
    QList<QVariant> devices = msg.arguments();

    int battery_level = 0;
    bool battery_active = false;
    bool battery_exists = false;
    foreach (QVariant name, devices)
    {
        QString bat = name.toStringList()[0];
        QDBusInterface device("org.freedesktop.Hal",bat,"org.freedesktop.Hal.Device",conn);
        QDBusReply<bool> battery_present = device.call("GetPropertyBoolean","battery.present");
        if (battery_present)
        {
            battery_exists = true;
            QDBusReply<int> battery_charge_level = device.call("GetPropertyInteger","battery.charge_level.percentage");
            QDBusReply<bool> battery_discharging = device.call("GetPropertyBoolean","battery.rechargeable.is_discharging");
            if (battery_discharging)
            {
                battery_active = true;
            }
            else
            {
                battery_active = false;
            }
            battery_level = battery_level + battery_charge_level;
        }
    }
コード例 #3
0
ファイル: app_x11.cpp プロジェクト: jsj2008/cmplayer
bool AppX11::shutdown() {
	_Debug("Try KDE session manger to shutdown.");
	QDBusInterface kde("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface", QDBusConnection::sessionBus());
	auto response = kde.call("logout", 0, 2, 2);
	if (response.type() != QDBusMessage::ErrorMessage)
		return true;
	_Debug("KDE session manager does not work: [%%] %%", response.errorName(), response.errorMessage());
	_Debug("Fallback to Gnome session manager.");
	QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", QDBusConnection::sessionBus());
	response = gnome.call("RequestShutdown");
	if (response.type() != QDBusMessage::ErrorMessage)
		return true;
	_Debug("Gnome session manager does not work: [%%] %%", response.errorName(), response.errorMessage());
	_Debug("Fallback to gnome-power-cmd.sh.");
	if (QProcess::startDetached("gnome-power-cmd.sh shutdown") || QProcess::startDetached("gnome-power-cmd shutdown"))
		return true;
	_Debug("gnome-power-cmd.sh does not work.");
	_Debug("Fallback to HAL.");
	QDBusInterface hal("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
	response = hal.call("Shutdown");
	if (response.type() != QDBusMessage::ErrorMessage)
		return true;
	_Debug("HAL does not work: [%%] %%", response.errorName(), response.errorMessage());
	_Debug("Fallback to ConsoleKit.");
	QDBusInterface consoleKit("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus());
	response = consoleKit.call("Stop");
	if (response.type() != QDBusMessage::ErrorMessage)
		return true;
	_Debug("ConsoleKit does not work: [%%] %%", response.errorName(), response.errorMessage());
	_Debug("Sorry, there's no way to shutdown.");
	return false;
}
コード例 #4
0
ファイル: boundry.c プロジェクト: hhashoww/misc
int main() {

    data_t *hal_data[10];
    //data_t hal_data[10];

    uint8_t buffer[255];
    uint8_t tmp[3] = {0x01, 0x02, 0x03};

    data_t *ptr = (data_t *)buffer;
    ptr->len = 3;
    memcpy((uint8_t *)ptr + sizeof(data_t), tmp, 3);

    printf("%x\n", ptr->arg[0]); // 0xaa
    printf("%x\n", ptr->arg[1]); // 0xbb
    printf("%x\n", ptr->arg[2]); // 0xcc

    /***************************************/

    uint8_t buffer2[255];
    uint8_t tmp2[3] = {0x04, 0x05, 0x06};

    data_t *ptr2 = (data_t *)buffer2;
    ptr2->len = 3;
    memcpy((uint8_t *)ptr2 + sizeof(data_t), tmp2, 3);

    printf("%x\n", ptr2->arg[0]); // 0xaa
    printf("%x\n", ptr2->arg[1]); // 0xbb
    printf("%x\n", ptr2->arg[2]); // 0xcc
    hal_data[1] = ptr;
    hal_data[2] = ptr2;
    hal(hal_data);

    return 0;
}
コード例 #5
0
ファイル: boundry.c プロジェクト: hhashoww/misc
int main() {

    uint8_t buffer[255];
    uint8_t tmp[3] = {0x01, 0x02, 0x03};
    uint8_t tmp2[4] = {0x04, 0x05, 0x06, 0x07};

    data_t *ptr = (data_t *)buffer;
    ptr->len = 3;
    memcpy((uint8_t *)ptr + sizeof(data_t), tmp, 3);

    printf("%x\n", ptr->arg[0]); // 0xaa
    printf("%x\n", ptr->arg[1]); // 0xbb
    printf("%x\n", ptr->arg[2]); // 0xcc

    /***************************************/


    ptr = ptr + sizeof(data_t) + (sizeof(uint8_t) * 3);
    ptr->len = 4;
    memcpy((uint8_t *)ptr + sizeof(data_t), tmp2, 4);

    printf("%x\n", ptr->arg[0]); // 0xaa
    printf("%x\n", ptr->arg[1]); // 0xbb
    printf("%x\n", ptr->arg[2]); // 0xcc
    printf("%x\n", ptr->arg[3]); // 0xcc


    hal((data_t *)buffer);

    return 0;
}
コード例 #6
0
Vec trace(const Ray& r, const int index, const int num_samps) {
	// ray-sphere intersection
	double t;
	if (!intersect(r, t)) return Vec();

	// compute the intersection data
	const Vec x = r.o + r.d * t, n = (x - sph.p).normalized(), w = -r.d;

	// compute Fresnel transmittance at point of emergence
	const double T21 = 1.0 - fresnel(w.dot(n), eta);

	// integration of the BSSRDF over the surface
	unsigned int xi = next_rand(index);
	Vec result;
	for (int i = 0; i < num_samps; i++) {
		// generate a sample
		Vec sp, sn, sw;
		sample(i, Vec(hal(2, index), hal(3, index), 0.0), sp, sn);
		sw = Vec(1, 1, -0.5).normalized();

		// directional light source
		const double radiance = 8.0*PI;
		const double cos_wi_n = sn.dot(sw);
		if (cos_wi_n > 0.0) {
			// Russian roulette (note that accept_prob can be any value in (0, 1))
			const double accept_prob = exp(-(sp - x).len() * min_sigma_tr);
			if ((xi / rand_range) < accept_prob) {
				const double T12 = 1.0 - fresnel(cos_wi_n, eta);
				const double Li_cos = T12 * radiance * cos_wi_n / (samplePDF * accept_prob);

				for (int j = 0; j < 3; j++) result[j] += bssrdf(sp, sn, sw, x, n, w, j) * Li_cos;

				// reciprocal evaulation with the reciprocity hack
				//for (int j = 0; j < 3; j++) result[j] += 0.5 * (bssrdf(sp, sn, sw, x, n, w, j) + bssrdf(x, n, w, sp, sn, sw, j)) * Li_cos;
			}
			xi = next_rand(xi);
		}
	}
	return T21 * result / (double)num_samps;
}
コード例 #7
0
static bool DBusReboot(void)
{
#if CONFIG_QTDBUS
    QDBusInterface kde("org.kde.ksmserver",
                       "/KSMServer",
                       "org.kde.KSMServerInterface");
    QDBusInterface gnome("org.gnome.SessionManager",
                         "/org/gnome/SessionManager",
                         "org.gnome.SessionManager");
    QDBusInterface consolekit("org.freedesktop.ConsoleKit",
                              "/org/freedesktop/ConsoleKit/Manager",
                              "org.freedesktop.ConsoleKit.Manager",
                              QDBusConnection::systemBus());
    QDBusInterface hal("org.freedesktop.Hal",
                       "/org/freedesktop/Hal/devices/computer",
                       "org.freedesktop.Hal.Device.SystemPowerManagement",
                       QDBusConnection::systemBus());

    QDBusReply<void> void_reply = kde.call("logout", 0, 1, 2);
    QDBusReply<bool> bool_reply;
    QDBusReply<int>  int_reply;

    if (!void_reply.isValid())
    {
        bool_reply = gnome.call("CanShutdown");
        if (bool_reply.isValid() && bool_reply.value() == 1)
            void_reply=gnome.call("RequestReboot");
    }
    if (!void_reply.isValid())
    {
        bool_reply = consolekit.call("CanRestart");
        if (bool_reply.isValid() && bool_reply.value() == 1)
            void_reply = consolekit.call("Restart");
    }
    if (!void_reply.isValid())
        int_reply = hal.call("Reboot");

    return void_reply.isValid() || int_reply.isValid();
#endif
    return false;
}