Modify flora license version.
[platform/core/messaging/msg-service.git] / include / framework / MsgPluginConfig.h
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://floralicense.org/license/
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef MSG_PLUGIN_CONFIG_H
18 #define MSG_PLUGIN_CONFIG_H
19
20
21 /*==================================================================================================
22                                          INCLUDE FILES
23 ==================================================================================================*/
24 #include <map>
25 #include <list>
26 #include <stdio.h>
27 #include <string.h>
28 #include "MsgDebug.h"
29 #include "MsgTypes.h"
30 #include "MsgCppTypes.h"
31
32 class MsgPlgToken
33 {
34         int tokenType; // not defined 0, title: 1, msgtype: 2, libpath: 3
35         char tokenVal[256]; // null-terminated char array
36
37 public:
38         MsgPlgToken(char* pstr=NULL) : tokenType(TOK_UNDEFINED)
39         {
40                 if(pstr)
41                 {
42                         tokenize(pstr);
43                 }
44                 else
45                 {
46                         bzero(tokenVal, 256);
47                 }
48         }
49
50         MsgPlgToken& operator = (const MsgPlgToken& rhs)
51         {
52                 if (this != &rhs)
53                 {
54                         tokenType = rhs.tokenType;
55                         strncpy(tokenVal, rhs.tokenVal, 255);
56                 }
57
58                 return *this;
59         }
60
61         int getType() const { return tokenType; } // not defined 0, title: 1, msgtype: 2, libpath: 3
62         const char* getVal(void) const { return tokenVal; }
63         void getVal(CharVector& vec) const { vec.assign(tokenVal, tokenVal+strlen(tokenVal));}
64         int tokenize(char* pStr);
65
66         enum { TOK_UNDEFINED=0, TOK_PLG_TITLE, TOK_PLG_TYPE, TOK_PLG_PATH };
67
68         void reset() { tokenType = TOK_UNDEFINED; }
69         operator void*() const {
70                 return (tokenType==TOK_UNDEFINED)? NULL:(void*) this;
71         }
72 };
73
74 typedef std::vector<MsgPlgToken> MsgPlgTokenVec;
75 typedef std::map<CharVector, MsgPlgTokenVec> MsgConfigMap;
76
77 class MsgPlgConfig
78 {
79         MsgConfigMap configMap;
80         void insert(const MsgPlgToken& tokTitle, const MsgPlgToken& tokMsgType, const MsgPlgToken& tokLibPath);
81
82 public:
83         MsgPlgConfig(FILE* fp);
84
85         /* access method for tokens */
86         const CharVector& title(unsigned int pos);// const; // iteration with ith position i=0, .. , itemCount-1
87         inline int titleCount() const { return configMap.size(); }
88
89         void token(const CharVector& key, unsigned int pos, MsgPlgToken& retTok);// const;
90         void token(int i, unsigned int pos, MsgPlgToken& retTok);// const;
91         int tokenCount(const CharVector& key) { return configMap[key].size(); } // const leads to error why?
92 };
93
94 #endif // MSG_PLUGIN_CONFIG_H