3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
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>
14 * PROPRIETARY/CONFIDENTIAL
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.
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.
31 #include "MsgPluginConfig.h"
32 #include "MsgException.h"
35 /*==================================================================================================
36 IMPLEMENTATION OF MsgPlgToken - Member Functions
37 ==================================================================================================*/
38 int MsgPlgToken::tokenize(char *pStr)
43 THROW(MsgException::INVALID_PARAM, "pstr is NULL");
45 char *pFirst = index(pStr, '[');
47 if (pFirst) // title is enclosed by [ ]
49 pFirst++; // excluding '['
51 char *pEnd = index(pStr, ']');
57 tokenType = TOK_PLG_TITLE;
58 int len = pEnd-pFirst+1;
60 memcpy(tokenVal, pFirst, len);
63 MSG_DEBUG("%s", tokenVal);
66 THROW(MsgException::INVALID_RESULT, "']' not found");
68 else // (attribute, value) pair
70 char tokStr[strlen(pStr)+1];
71 strncpy(tokStr, pStr, strlen(pStr));
73 char *attr = strtok(tokStr, "=");
74 char *val = strtok(NULL, "=");
78 tokenType = TOK_UNDEFINED;
83 char *tmp = index(val,'\n');
88 MSG_DEBUG("attr \"%s\", val \"%s\" ", attr, val);
90 // classifying the attribute
91 if (strcmp(attr, "type") == 0)
93 tokenType = TOK_PLG_TYPE;
94 strncpy(tokenVal, val, 255);
96 else if (strcmp(attr, "path") == 0)
98 tokenType = TOK_PLG_PATH;
99 strncpy(tokenVal, val, 255);
103 tokenType = TOK_UNDEFINED;
114 /*==================================================================================================
115 IMPLEMENTATION OF MsgPlgConfig - Member Functions
116 ==================================================================================================*/
117 MsgPlgConfig::MsgPlgConfig(FILE* fp)
122 THROW(MsgException::INVALID_PARAM, "fp is NULL");
124 MsgPlgToken tokTitle, tokMsgType, tokLibPath;
127 memset(str, 0x00, sizeof(str));
129 MsgPlgToken tok = MsgPlgToken();
131 while (fgets(str, 255, fp))
133 tok.tokenize(str); // parsing the line into tokens
135 switch ( tok.getType() )
137 case MsgPlgToken::TOK_PLG_TITLE:
138 // processing previous items
139 if( tokTitle && tokMsgType && tokLibPath )
141 insert(tokTitle, tokMsgType, tokLibPath);
150 case MsgPlgToken::TOK_PLG_TYPE:
154 case MsgPlgToken::TOK_PLG_PATH:
159 MSG_DEBUG("the line \"%s\" is not accecpted", str);
164 if (tokTitle && tokMsgType && tokLibPath)
166 insert(tokTitle, tokMsgType, tokLibPath);
173 void MsgPlgConfig::insert(const MsgPlgToken& tokTitle, const MsgPlgToken& tokMsgType, const MsgPlgToken& tokLibPath)
177 MsgPlgTokenVec item2add;
178 item2add.push_back(tokMsgType);
179 item2add.push_back(tokLibPath);
182 tokTitle.getVal(titleVec);
183 MsgConfigMap::iterator it=configMap.find(titleVec);
185 if (it == configMap.end())
186 configMap.insert(std::make_pair(titleVec, item2add));
188 THROW(MsgException::PLUGIN_ERROR, "duplicated plugin title");
190 MSG_DEBUG("item inserted");
191 MSG_DEBUG("token:%d,value:%s", tokTitle.getType(), tokTitle.getVal());
192 MSG_DEBUG("token:%d,value:%s", tokMsgType.getType(), tokMsgType.getVal());
193 MSG_DEBUG("token:%d,value:%s", tokLibPath.getType(), tokLibPath.getVal());
199 const CharVector& MsgPlgConfig::title(unsigned int pos)
201 if (pos >= configMap.size() || pos < 0)
202 THROW(MsgException::OUT_OF_RANGE, "Input Parameter is not valid [%d]", pos);
204 MsgConfigMap::iterator it = configMap.begin();
208 while (it != configMap.end())
210 if (i++ == pos) break;
214 if (it == configMap.end())
215 THROW(MsgException::INVALID_RESULT, "no title");
217 MSG_DEBUG("searched title:%s", &(it->first)[0]);
223 void MsgPlgConfig::token(const CharVector& key, unsigned int pos, MsgPlgToken& retTok)
225 MsgConfigMap::iterator it = configMap.find(key);
227 if (it != configMap.end()) //found
229 MSG_DEBUG("searched title:%s", &(it->first)[0]);
231 MsgPlgTokenVec tokVec = it->second;
232 retTok = tokVec[pos];
234 MSG_DEBUG("searched token:%d,value:%s", retTok.getType(), retTok.getVal());
238 THROW(MsgException::INVALID_RESULT, "no title");
243 void MsgPlgConfig::token(int i, unsigned int pos, MsgPlgToken& retTok)
245 const CharVector& key = title(i);
247 token(key, pos, retTok);
249 MSG_DEBUG("returned token:%d,value:%s", retTok.getType(), retTok.getVal());