データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリを使ったサンプルです。 EthernetIF版 https://mlkcca.com/

Dependencies:   EthernetInterface Milkcocoa_EthernetIF mbed-rtos mbed

Committer:
jksoft
Date:
Tue Oct 31 09:26:44 2017 +0000
Revision:
9:561182aac695
??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 9:561182aac695 1 /**
jksoft 9:561182aac695 2 * Configuration file interface class (Version 0.0.1)
jksoft 9:561182aac695 3 *
jksoft 9:561182aac695 4 * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
jksoft 9:561182aac695 5 * http://shinta.main.jp/
jksoft 9:561182aac695 6 */
jksoft 9:561182aac695 7 #include "mbed.h"
jksoft 9:561182aac695 8
jksoft 9:561182aac695 9 #ifndef _CONFIG_FILE_H_
jksoft 9:561182aac695 10 #define _CONFIG_FILE_H_
jksoft 9:561182aac695 11
jksoft 9:561182aac695 12 /**
jksoft 9:561182aac695 13 * Configuration File class.
jksoft 9:561182aac695 14 */
jksoft 9:561182aac695 15 class ConfigFile {
jksoft 9:561182aac695 16 public:
jksoft 9:561182aac695 17
jksoft 9:561182aac695 18 /**
jksoft 9:561182aac695 19 * Create a configuration file class.
jksoft 9:561182aac695 20 */
jksoft 9:561182aac695 21 ConfigFile();
jksoft 9:561182aac695 22
jksoft 9:561182aac695 23 /**
jksoft 9:561182aac695 24 * Destroy a configuration file class.
jksoft 9:561182aac695 25 */
jksoft 9:561182aac695 26 ~ConfigFile();
jksoft 9:561182aac695 27
jksoft 9:561182aac695 28 /**
jksoft 9:561182aac695 29 * Get a value for a key.
jksoft 9:561182aac695 30 *
jksoft 9:561182aac695 31 * @param key A target key name.
jksoft 9:561182aac695 32 * @param value A pointer to a value storage.
jksoft 9:561182aac695 33 * @param siz A size of a value storage.
jksoft 9:561182aac695 34 * @return A value or NULL.
jksoft 9:561182aac695 35 */
jksoft 9:561182aac695 36 bool getValue(char *key, char *value, size_t siz);
jksoft 9:561182aac695 37
jksoft 9:561182aac695 38 /**
jksoft 9:561182aac695 39 * Set a set of a key and value.
jksoft 9:561182aac695 40 *
jksoft 9:561182aac695 41 * @param key A key.
jksoft 9:561182aac695 42 * @param value A value.
jksoft 9:561182aac695 43 *
jksoft 9:561182aac695 44 * @return True if it succeed.
jksoft 9:561182aac695 45 */
jksoft 9:561182aac695 46 bool setValue(char *key, char *value);
jksoft 9:561182aac695 47
jksoft 9:561182aac695 48 /**
jksoft 9:561182aac695 49 * Remove a config.
jksoft 9:561182aac695 50 *
jksoft 9:561182aac695 51 * @param key A key.
jksoft 9:561182aac695 52 *
jksoft 9:561182aac695 53 * @return True if it succeed.
jksoft 9:561182aac695 54 */
jksoft 9:561182aac695 55 bool remove(char *key);
jksoft 9:561182aac695 56
jksoft 9:561182aac695 57 /**
jksoft 9:561182aac695 58 * Remove all config.
jksoft 9:561182aac695 59 *
jksoft 9:561182aac695 60 * @return True if it succeed.
jksoft 9:561182aac695 61 */
jksoft 9:561182aac695 62 bool removeAll(void);
jksoft 9:561182aac695 63
jksoft 9:561182aac695 64 /**
jksoft 9:561182aac695 65 * Get a number of configuration sets.
jksoft 9:561182aac695 66 *
jksoft 9:561182aac695 67 * @return number of configuration sets.
jksoft 9:561182aac695 68 */
jksoft 9:561182aac695 69 int getCount();
jksoft 9:561182aac695 70
jksoft 9:561182aac695 71 /**
jksoft 9:561182aac695 72 * Get a key and a value.
jksoft 9:561182aac695 73 *
jksoft 9:561182aac695 74 * @param index Index number of this list.
jksoft 9:561182aac695 75 * @param key A pointer to a buffer for key.
jksoft 9:561182aac695 76 * @param keybufsiz A size of the key buffer.
jksoft 9:561182aac695 77 * @param value A pointer to a buffer for value.
jksoft 9:561182aac695 78 * @param valuebufsiz A size of the value buffer.
jksoft 9:561182aac695 79 *
jksoft 9:561182aac695 80 * @return true if it succeed.
jksoft 9:561182aac695 81 */
jksoft 9:561182aac695 82 bool getKeyAndValue(int index, char *key, size_t keybufsiz, char *value, size_t valuebufsiz);
jksoft 9:561182aac695 83
jksoft 9:561182aac695 84 /**
jksoft 9:561182aac695 85 * Read from the target file.
jksoft 9:561182aac695 86 *
jksoft 9:561182aac695 87 * @param file A target file name.
jksoft 9:561182aac695 88 */
jksoft 9:561182aac695 89 bool read(char *file);
jksoft 9:561182aac695 90
jksoft 9:561182aac695 91 typedef enum {
jksoft 9:561182aac695 92 UNIX,
jksoft 9:561182aac695 93 MAC,
jksoft 9:561182aac695 94 DOS
jksoft 9:561182aac695 95 } FileFormat;
jksoft 9:561182aac695 96
jksoft 9:561182aac695 97 /**
jksoft 9:561182aac695 98 * Write from the target file.
jksoft 9:561182aac695 99 *
jksoft 9:561182aac695 100 * @param file A pointer to a file name.
jksoft 9:561182aac695 101 * @param header A pointer to a header.
jksoft 9:561182aac695 102 * @param ff File format.
jksoft 9:561182aac695 103 */
jksoft 9:561182aac695 104 bool write(char *file, char *header = NULL, FileFormat ff = UNIX);
jksoft 9:561182aac695 105
jksoft 9:561182aac695 106 private:
jksoft 9:561182aac695 107 typedef struct {
jksoft 9:561182aac695 108 char *key;
jksoft 9:561182aac695 109 char *value;
jksoft 9:561182aac695 110 } config_t;
jksoft 9:561182aac695 111 config_t **configlist;
jksoft 9:561182aac695 112 static const int MAXCONFIG = 64;
jksoft 9:561182aac695 113 static const int MAXLEN_KEY = 64;
jksoft 9:561182aac695 114 static const int MAXLEN_VALUE = 128;
jksoft 9:561182aac695 115 static const char SEPARATOR = '=';
jksoft 9:561182aac695 116
jksoft 9:561182aac695 117 config_t *search(char *key);
jksoft 9:561182aac695 118 bool add(config_t *cfg);
jksoft 9:561182aac695 119 };
jksoft 9:561182aac695 120
jksoft 9:561182aac695 121 #endif