shiny :-)
ack
On Sun, Jun 19, 2011 at 10:28 AM, Russell Bryant
<russell(a)russellbryant.net> wrote:
This patch implements the identify method that was defined for the
Host
API. The implementation triggers a system beep for 1 second when the
identify method is invoked.
This implementation is based on documentation that I found for how to
trigger a system beep on Linux and windows. It still needs to be
tested to make sure it actually works...
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/host/host-dbus.c | 4 +---
src/host/host-qmf.cpp | 2 ++
src/include/matahari/host.h | 10 +++++++++-
src/lib/host.c | 6 ++++++
src/lib/host_linux.c | 27 +++++++++++++++++++++++++++
src/lib/host_private.h | 9 +++++++++
src/lib/host_windows.c | 14 ++++++++++++++
7 files changed, 68 insertions(+), 4 deletions(-)
diff --git a/src/host/host-dbus.c b/src/host/host-dbus.c
index 612b457..0c7284e 100644
--- a/src/host/host-dbus.c
+++ b/src/host/host-dbus.c
@@ -53,9 +53,7 @@ Host_identify(Matahari* matahari, DBusGMethodInvocation *context)
dbus_g_method_return_error(context, error);
return FALSE;
}
- // TODO: Implement when implemented in backend
- error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
- "Action identify is not implemented yet!");
+ mh_host_identify();
dbus_g_method_return(context, TRUE);
return TRUE;
}
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index 96bf05c..826c6b6 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -115,6 +115,8 @@ HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
mh_host_shutdown();
} else if (methodName == "reboot") {
mh_host_reboot();
+ } else if (methodName == "identify") {
+ mh_host_identify();
} else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
goto bail;
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index d8d3acd..89e3a2a 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -46,7 +46,15 @@ extern int mh_host_get_cpu_count(void);
extern int mh_host_get_cpu_number_of_cores(void);
extern int mh_host_get_cpu_wordsize(void);
-extern void mh_host_identify(const unsigned int iterations);
+/**
+ * Identify a host.
+ *
+ * Trigger the system beep to help identify a host.
+ *
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+extern int mh_host_identify(void);
extern void mh_host_reboot(void);
extern void mh_host_shutdown(void);
diff --git a/src/lib/host.c b/src/lib/host.c
index 6e71db0..311149f 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -254,3 +254,9 @@ host_get_cpu_details(void)
sigar_cpu_info_list_destroy(host_init.sigar, &cpus);
}
+
+int
+mh_host_identify(void)
+{
+ return host_os_identify();
+}
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 6c1babd..c5e2c9b 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -23,11 +23,14 @@
#include <unistd.h>
#include <limits.h>
#include <string.h>
+#include <fcntl.h>
#include <sys/reboot.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
+#include <sys/ioctl.h>
#include <linux/reboot.h>
+#include <linux/kd.h>
#include <pcre.h>
@@ -133,3 +136,27 @@ host_os_shutdown(void)
{
reboot(LINUX_REBOOT_CMD_HALT);
}
+
+int
+host_os_identify(void)
+{
+ static const long DURATION = 1000; /* 1 second */
+ static const long FREQ = 440; /* 440 Hz */
+
+ int fd = open("/dev/tty", O_NOCTTY);
+ int res;
+
+ if (fd == -1) {
+ return -1;
+ }
+
+ /*
+ * Reference info on KDMKTONE:
+ *
http://tldp.org/LDP/lpg/node83.html
+ */
+ res = ioctl(fd, KDMKTONE, (DURATION << 32) + (1190000 / FREQ));
+
+ close(fd);
+
+ return res;
+}
diff --git a/src/lib/host_private.h b/src/lib/host_private.h
index 0994536..2900797 100644
--- a/src/lib/host_private.h
+++ b/src/lib/host_private.h
@@ -40,4 +40,13 @@ host_os_reboot(void);
extern void
host_os_shutdown(void);
+/**
+ * Platform specific implementation of a system beep.
+ *
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+extern int
+host_os_identify(void);
+
#endif /* __MH_HOST_PRIVATE_H__ */
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c
index e86ff47..3bb2ab7 100644
--- a/src/lib/host_windows.c
+++ b/src/lib/host_windows.c
@@ -79,3 +79,17 @@ host_os_shutdown(void)
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,
SHTDN_REASON_FLAG_PLANNED);
}
+
+int
+host_os_identify(void)
+{
+ static const long DURATION = 1000; /* 1 second */
+ static const long FREQ = 440; /* 440 Hz */
+
+ /*
+ * Reference for Windows Beep():
+ *
http://msdn.microsoft.com/en-us/library/ms679277%28v=vs.85%29.aspx
+ */
+
+ return Beep(FREQ, DURATION) ? 0 : -1;
+}
--
1.7.5.4
_______________________________________________
Matahari mailing list
Matahari(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/matahari