aboutsummaryrefslogtreecommitdiff
path: root/vendor/voclient/libsamp/sampMsg.c
blob: bbb31e2cc29aa3284b2505c975d4788eec4fa732 (plain) (blame)
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
/**
 *  SAMPMSG.C -- (Internal) Interface to Message objects.
 *
 *             msg = samp_newMsg  ()
 *                 samp_msgMType  (Msg msg, String mtype)
 *                 samp_msgParam  (Msg msg, Param param)
 *                   samp_msgTag  ()
 *                  samp_freeMsg  (Msg msg)
 *  
 *  @brief      (Internal)  Interface to Message objects.
 *  
 *  @file       sampMsg.c
 *  @author     Mike Fitzpatrick
 *  @date       7/10/11
 */


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#include "samp.h"



/**
 *  SAMP_NEWMSG -- Create a new Msg object
 *
 *  @brief	Create a new Msg object
 *  @fn		int samp_newMsg (void)
 *
 *  @return 		handle to new Msg
 */
Msg
samp_newMsg ()
{
    Map    msg = (Map) xr_newStruct();
    return ( (Map) msg );
}


/**
 *  SAMP_FREEMSG -- Free the given Msg object
 *
 *  @brief	Free the given Msg object
 *  @fn		void samp_freeMsg (Msg msg)
 *
 *  @param  msg		Msg object to free
 *  @return 		nothing
 */
void
samp_freeMsg (Msg msg)
{
    xr_freeStruct (msg);
}


/**
 *  SAMP_SETMTYPE -- Set the MType of a Msg.
 *
 *  @brief	Set the MType of a Msg.
 *  @fn		void samp_setMtype (Msg msg, String mtype)
 *
 *  @param  msg		handle to Msg object
 *  @param  mtype	MType string
 *  @return 		nothing
 */
void
samp_msgMType (Msg msg, String mtype)
{
    xr_setStringInStruct (msg, "samp.mtype", mtype);
}


/**
 *  SAMP_NEWMSG -- Create a new Msg object
 *
 *  @brief	Create a new Msg object
 *  @fn		int samp_newMsg (void)
 *
 *  @return 		handle to new Msg
 */
char *
samp_msgTag ()
{
    static int  msgnum = 0;
    static char tag[128];

    memset (tag, 0, 128);
    sprintf (tag, "msg%06d", msgnum++);

    return ( tag );
}


/**
 *  SAMP_MSGPARAM -- Add a parameter to the Msg.
 *
 *  @brief	Add a parameter to the Msg.
 *  @fn		void samp_msgParam (Msg msg, Param param)
 *
 *  @param  msg		handle to Msg object
 *  @param  keyw	map keyword
 *  @param  param	parameter map
 *  @return 		nothing
 */
void
samp_msgParam (Msg msg, Param param)
{
    xr_setStructInStruct (msg, "samp.params", param);
}