File: chat.c

package info (click to toggle)
yuma123 2.14-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,436 kB
  • sloc: ansic: 185,144; cpp: 10,968; python: 7,990; sh: 2,676; makefile: 1,175; xml: 807; exp: 776; perl: 70
file content (145 lines) | stat: -rw-r--r-- 3,106 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
    module chat (based on chat.yang)
 */

#define __USE_XOPEN 1
//#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>

#include "procdefs.h"
#include "agt.h"
#include "agt_cb.h"
#include "agt_timer.h"
#include "agt_util.h"
#include "agt_not.h"
#include "agt_rpc.h"
#include "dlq.h"
#include "ncx.h"
#include "ncxmod.h"
#include "ncxtypes.h"
#include "status.h"
#include "rpc.h"

/* module static variables */
static ncx_module_t *chat_mod;


/********************************************************************
* FUNCTION y_chat_send_message_invoke
* 
* RPC invocation phase
* All constraints have passed at this point.
* Call device instrumentation code in this function.
* 
* INPUTS:
*     see agt/agt_rpc.h for details
* 
* RETURNS:
*     error status
********************************************************************/
static status_t
    y_chat_send_message_invoke (
        ses_cb_t *scb,
        rpc_msg_t *msg,
        xml_node_t *methnode)
{
    val_value_t* input_text_val=NULL;
    val_value_t* text_val=NULL;
    status_t res;
    obj_template_t* notification_obj;
    obj_template_t* text_obj;
    agt_not_msg_t *notif;
    res = NO_ERR;

    /* remove the next line if scb is used */
    (void)scb;

    /* remove the next line if methnode is used */
    (void)methnode;

    /* invoke your device instrumentation code here */
    input_text_val = val_find_child(
        msg->rpc_input,
        "chat",
        "text");
    assert(input_text_val);
    printf("message is: %s\n", VAL_STRING(input_text_val));

    notification_obj = ncx_find_object(
        chat_mod,
        "message");
    assert(notification_obj);

    notif = agt_not_new_notification(notification_obj);
    assert (notif != NULL);

    /* add params to payload */
    text_obj = obj_find_child(notification_obj,
                      "chat",
                      "text");
    assert(text_obj);
    text_val = val_new_value();
    assert(text_val);

    val_init_from_template(text_val, text_obj);
    res = val_set_simval_obj(text_val,
                         text_val->obj,
                         VAL_STRING(input_text_val));
    agt_not_add_to_payload(notif, text_val);

    agt_not_queue_notification(notif);

    return res;

}


/* The 3 mandatory callback functions: y_chat_init, y_chat_init2, y_chat_cleanup */

status_t
    y_chat_init (
        const xmlChar *modname,
        const xmlChar *revision)
{
    agt_profile_t *agt_profile;
    status_t res;

    agt_profile = agt_get_profile();

    res = ncxmod_load_module(
        "chat",
        NULL,
        &agt_profile->agt_savedevQ,
        &chat_mod);
    if (res != NO_ERR) {
        return res;
    }

    res = agt_rpc_register_method(
        "chat",
        "send-message",
        AGT_RPC_PH_INVOKE,
        y_chat_send_message_invoke);
    if (res != NO_ERR) {
        return res;
    }

    return res;
}

status_t y_chat_init2(void)
{
    return NO_ERR;
}

void y_chat_cleanup(void)
{
}