update tizen source
[framework/messaging/msg-service.git] / include / framework / MsgPluginConfig.h
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #ifndef MSG_PLUGIN_CONFIG_H
32 #define MSG_PLUGIN_CONFIG_H
33
34
35 /*==================================================================================================
36                                          INCLUDE FILES
37 ==================================================================================================*/
38 #include <map>
39 #include <list>
40 #include <stdio.h>
41 #include <string.h>
42 #include "MsgDebug.h"
43 #include "MsgTypes.h"
44 #include "MsgCppTypes.h"
45
46 class MsgPlgToken
47 {
48         int tokenType; // not defined 0, title: 1, msgtype: 2, libpath: 3
49         char tokenVal[256]; // null-terminated char array
50
51 public:
52         MsgPlgToken(char* pstr=NULL) : tokenType(TOK_UNDEFINED)
53         {
54                 if(pstr)
55                 {
56                         tokenize(pstr);
57                 }
58                 else
59                 {
60                         bzero(tokenVal, 256);
61                 }
62         }
63
64         MsgPlgToken& operator = (const MsgPlgToken& rhs)
65         {
66                 if (this != &rhs)
67                 {
68                         tokenType = rhs.tokenType;
69                         strncpy(tokenVal, rhs.tokenVal, 255);
70                 }
71
72                 return *this;
73         }
74
75         int getType() const { return tokenType; } // not defined 0, title: 1, msgtype: 2, libpath: 3
76         const char* getVal(void) const { return tokenVal; }
77         void getVal(CharVector& vec) const { vec.assign(tokenVal, tokenVal+strlen(tokenVal));}
78         int tokenize(char* pStr);
79
80         enum { TOK_UNDEFINED=0, TOK_PLG_TITLE, TOK_PLG_TYPE, TOK_PLG_PATH };
81
82         void reset() { tokenType = TOK_UNDEFINED; }
83         operator void*() const {
84                 return (tokenType==TOK_UNDEFINED)? NULL:(void*) this;
85         }
86 };
87
88 typedef std::vector<MsgPlgToken> MsgPlgTokenVec;
89 typedef std::map<CharVector, MsgPlgTokenVec> MsgConfigMap;
90
91 class MsgPlgConfig
92 {
93         MsgConfigMap configMap;
94         void insert(const MsgPlgToken& tokTitle, const MsgPlgToken& tokMsgType, const MsgPlgToken& tokLibPath);
95
96 public:
97         MsgPlgConfig(FILE* fp);
98
99         /* access method for tokens */
100         const CharVector& title(unsigned int pos);// const; // iteration with ith position i=0, .. , itemCount-1
101         inline int titleCount() const { return configMap.size(); }
102
103         void token(const CharVector& key, unsigned int pos, MsgPlgToken& retTok);// const;
104         void token(int i, unsigned int pos, MsgPlgToken& retTok);// const;
105         int tokenCount(const CharVector& key) { return configMap[key].size(); } // const leads to error why?
106 };
107
108 #endif // MSG_PLUGIN_CONFIG_H