maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   How to properly use alarmd? (https://talk.maemo.org/showthread.php?t=16669)

fiferboy 2008-02-15 14:21

How to properly use alarmd? (SOLVED)
 
Hi,

I have been looking for an easy way to access all the alarms set in chinook. osso_worldclock has a nifty little dialog for viewing/adding/editing/deleting alarms that would be perfect to add to my statusbar clock except that I cannot find the source for osso_worldclock anywhere.

The alarm statusbar plugin uses the same dialog, but its source is also unavailable. Does anyone know if this dialog can be called using a command or dbus? That would be very helpful.

Also, if I try to check what alarms are set in my program using alarmd commands I get a segfault. The following is the code I was using:

Code:

#include <alarmd/alarm_event.h>
...
cookie_t *list;
list=alarm_event_query(time(NULL),time(NULL)+40,0,0);
...

My program crashes every time at the "list=..." line both in scratchbox (ARMEL and x86) and on the device. The code above is directly taken from the apitest.c included in the alarmd source, so it should be correct. Does anyone have experience using alarmd?

wnd 2008-02-20 15:33

Re: How to properly use alarmd?
 
Quote:

Originally Posted by fiferboy (Post 142800)
Also, if I try to check what alarms are set in my program using alarmd commands I get a segfault. -- My program crashes every time at the "list=..."

I've only used alarmd in one application so far, but I haven't really had any problems with it. alarm_event_query() works just fine here, compile with gcc -Wall $(pkg-config --libs --cflags libalarm) file.c:

Code:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <alarmd/alarm_event.h>

int
main(int argc, char **argv)
{
        cookie_t *list, *iter;
        time_t now;

        now = time(NULL);
        list = alarm_event_query(now, now + 60, 0, 0);
        if (list == NULL) {
                fprintf(stderr, "alarm_event_query() failed\n");
                return EXIT_FAILURE;
        }

        if (list[0] == (cookie_t) 0) {
                printf("no alarms set\n");
        } else {
                printf("alarm ids:");
                for (iter = list; *iter != (cookie_t) 0; iter++) {
                        printf(" %u\n", (unsigned int) *iter);
                }
                printf("\n");
        }

        free(list);
        return EXIT_SUCCESS;
}


fiferboy 2008-02-20 15:34

Re: How to properly use alarmd?
 
Thank you very much for the reply. I suspect my problem was not compiling with the correct libraries. I will give this another try.

UPDATE: Yes, that was my problem - I wasn't compiling with libalarm CFLAGS and LIBS. Now the program runs with no hitches. So, I can now start the fun task of building an interface similar to that in world clock for managing alarms (since there is no available source for this)

fiferboy 2008-02-21 15:56

Re: How to properly use alarmd?
 
Okay, while my code now compiles and runs with no problems I cannot for the life of me get alarmd running in scratchbox.

alarmd is installed, and when I have af-sb-init running the following occur:
- running "/etc/init.d/alarmd start" comes back with "Starting OSSO Alarm Daemon: alarmd." but no process gets started.
- running "alarmd -d" executes, but again no process starts.

As I only have one tablet I do not relish doing any testing of alarmd on it, especially to the level I eventually want to get. If anyone has been successful in getting alarmd testing to work in scratchbox, please let me know.

Thanks

fiferboy 2008-02-28 21:02

Re: How to properly use alarmd? (solved)
 
Just for posterity's sake (in case anyone is searching for how to do this in the future) I will post how to get alarmd to work in scratchbox!

This really is the simplest solution to a frustrating problem I have seen in quite some time.

Code:

run-standalone.sh alarmd
That's all folks! And you thought run-standalone just made your application look pretty! This is really going to help with testing alarms in statusbar-clock.

niv 2011-04-27 15:55

Re: How to properly use alarmd?
 
#!/usr/bin/env python
#simple example to issue a command using python and maemo alarmed RTC tool
# look at /var/cache/alarmd/alarm_queue.ini for the full queue
import time,alarm

if __name__ == '__main__':
event = alarm.Event()
event.appid = 'lovelyName'
event.alarm_time = time.time() +10
action = event.add_actions(1)[0]
action.flags |= alarm.ACTION_WHEN_TRIGGERED | alarm.ACTION_TYPE_EXEC
action.command = 'touch /tmp/alarm.txt'
cookie = alarm.add_event(event)
print cookie

tetris11_ 2012-08-12 22:50

Re: How to properly use alarmd?
 
^ Thanks niv, really helped me.

Here's the C++ version:

Code:

#include <alarmd/libalarm.h>
#include <iostream>
#define APPID "example-apps"

cookie_t MyClass::addAlarmdJob(){
    cookie_t cookie = 0;
    alarm_event_t *eve = 0;
    alarm_action_t *act = 0;

    /* Create alarm event structure, set application
      * identifier and dialog message */
    eve = alarm_event_create();
    alarm_event_set_alarm_appid(eve, APPID);

    /* Use absolute time triggering, show dialog
      * ten seconds from now */
    eve->alarm_time = time(0) + 10;

    /* Add command*/
    act = alarm_event_add_actions(eve,1);
    act->flags |= ALARM_ACTION_WHEN_TRIGGERED;
    act->flags |= ALARM_ACTION_TYPE_EXEC;
    act->exec_command = "phone-control --notify Hello!";

    /* Send the alarm to alarmd */
    cookie = alarmd_event_add(eve);

    std::cout << cookie << std::endl;

    /* Free all dynamic memory associated with the*/
    //alarm_event_delete(eve); //<-- Invalid pointer exception
    return cookie;  //Cookie ID of event
}



All times are GMT. The time now is 07:04.

vBulletin® Version 3.8.8