Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / libs / Network / uip / plan9 / plan9.h
1 #ifndef __PLAN9_H__
2 #define __PLAN9_H__
3
4 /*
5 * 9P network filesystem protocol
6 *
7 * by Daniel Mendler <mail@daniel-mendler.de>
8 *
9 * Resources:
10 *
11 * - Documentation: http://9p.cat-v.org/
12 * - List of implementations: http://9p.cat-v.org/implementations
13 * - Specification: http://ericvh.github.io/9p-rfc/
14 * - Linux documentation: https://www.kernel.org/doc/Documentation/filesystems/9p.txt
15 *
16 * How to use it:
17 *
18 * 1. Add "network.plan9.enable true" to the config
19 * 2. Mount under Linux with "mount -t 9p $ip /mnt/smoothie
20 */
21
22 #include <map>
23 #include <queue>
24 #include <string>
25 #include <stdint.h>
26
27 extern "C" {
28 #include "psock.h"
29 }
30
31 class Plan9
32 {
33 public:
34 Plan9();
35 ~Plan9();
36
37 static void init();
38 static void appcall();
39
40 struct EntryData {
41 uint8_t type;
42 int refcount;
43
44 EntryData() {}
45 EntryData(uint8_t t)
46 : type(t), refcount(0) {}
47 };
48
49 typedef std::map<std::string, EntryData> EntryMap;
50 typedef EntryMap::value_type* Entry;
51 typedef std::map<uint32_t, Entry> FidMap;
52 union Message;
53
54 private:
55 int receive();
56 int send();
57 bool process(Message*, Message*);
58
59 Entry add_entry(uint32_t, uint8_t, const std::string&);
60 Entry get_entry(uint32_t);
61 bool add_fid(uint32_t, Entry);
62 void remove_fid(uint32_t);
63
64 static const uint32_t INITIAL_MSIZE = 300;
65 EntryMap entries;
66 FidMap fids;
67 psock sin, sout;
68 char bufin[INITIAL_MSIZE], bufout[INITIAL_MSIZE];
69 std::queue<Message*> queue;
70 uint32_t msize, queue_bytes;
71 };
72
73 #endif