00001 /* 00002 * Copyright (C) 2003-2007 Funambol 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 #ifndef INCL_POSIX_DEVICE_MANAGEMENT_NODE 00020 #define INCL_POSIX_DEVICE_MANAGEMENT_NODE 00021 00023 #include "base/fscapi.h" 00024 #include "base/util/ArrayElement.h" 00025 #include "spdm/ManagementNode.h" 00026 00027 00028 /* 00029 * File-based implementation of ManagementNode. 00030 * Each node is mapped to one file, located in 00031 * $HOME/.sync4j/<node> 00032 * with entries of the type 00033 * <property>\s*=\s*<value>\n 00034 * 00035 * Comments look like: 00036 * \s*# <comment> 00037 */ 00038 class DeviceManagementNode : public ManagementNode { 00039 ArrayList *lines; 00040 BOOL modified; 00041 char *prefix; 00042 00043 class line : public ArrayElement { 00044 char *str; 00045 00046 public: 00047 line(const char *newStr = NULL) { str = NULL; setLine(newStr); } 00048 ~line() { free(str); } 00049 ArrayElement *clone() { return new line(str); } 00050 00051 const char *getLine() { return str; } 00052 void setLine(const char *newStr) { if (str) { free(str); } str = strdup(newStr ? newStr : ""); } 00053 }; 00054 00055 // the application's working directory 00056 int cwdfd; 00057 00058 // change into directory which holds config file, 00059 // creating directories if necessary for writing 00060 // 00061 // @return TRUE for success, FALSE for error - call returnFromDir() in both cases 00062 BOOL gotoDir(BOOL read); 00063 00064 // return to original directory after a gotoDir() 00065 void returnFromDir(); 00066 00067 // copy content of "lines" to or from file 00068 void update(BOOL read); 00069 00070 public: 00071 00072 // ------------------------------------------ Constructors & destructors 00073 00082 DeviceManagementNode(const char* parent, const char *leafName); 00083 DeviceManagementNode(const char* fullName); 00084 00085 DeviceManagementNode(const DeviceManagementNode &other); 00086 virtual ~DeviceManagementNode(); 00087 00088 00089 // ----------------------------------------------------- Virtual methods 00090 00091 /* 00092 * Returns the value of the given property 00093 * 00094 * @param property - the property name 00095 */ 00096 virtual char* readPropertyValue(const char* property); 00097 00098 00099 /* 00100 * Sets a property value. 00101 * 00102 * @param property - the property name 00103 * @param value - the property value (zero terminated string) 00104 */ 00105 virtual void setPropertyValue(const char* property, const char* value); 00106 00107 /* 00108 * Returns the children's name of the parent node. 00109 */ 00110 char **getChildrenNames(); 00111 00112 /* 00113 * Find how many children are defined for this node in the underlying 00114 * config system. 00115 */ 00116 virtual int getChildrenMaxCount(); 00117 00118 /* 00119 * Creates a new ManagementNode with the exact content of this object. 00120 * The new instance MUST be created with the C++ new opertator. 00121 */ 00122 virtual ArrayElement* clone(); 00123 00124 00125 }; 00126 00128 #endif