summaryrefslogtreecommitdiff
path: root/comm/ObexStream.h
blob: 3c0caad75962d5aec2748f0a724eec6cb7068037 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 *	Ivy League
 *
 *	OBEX protocol
 *
 *	Copyright 2000
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	by Stephane Chatty
 *
 *	$Id$
 *
 */

#ifndef ObexStream_H_
#define ObexStream_H_

#include "ivl/cplus_bugs.h"
#include "Stream.h"
class IvlAddress;
#include "ivl/List.h"
#include "Trigger.h"
#include "Scheduler.h"
#include "BufStream.h"
#include "Event.h"

#define OBEX_MIN_PACKET 255

class IvlObexStream : public IvlStream {
friend class IvlObexAgent;

protected:
	sword	MaxPacketSize;
public:
	IvlTrigger	NewAgents;

		IvlObexStream (IvlAddress*, sword = OBEX_MIN_PACKET, IvlBaseScheduler* = IvlScd);
		~IvlObexStream ();

	IvlChannel*	Copy () const;
	void		HandleRead ();
};

class IvlObexHeader;
class IvlObexObject;

class IvlObexAgent : public IvlBufStream {
private:
	IvlObexStream*	MyLink;
	void*	CurObj;
	IvlListOf<IvlObexHeader*>	OutHeaders;
	int	Status;

	void	HandleRead ();
	void	ParseConnect (sword, bool);
	void	ParseDisconnect (sword, bool);
	void	ParseAbort (sword, bool);
	void	ParsePut (sword, bool);
	void	ParseGet (sword, bool);
	void	ParseSetPath (sword, bool);
	void	ParseHeaders (sword, bool);
	void	KeepSending ();
	void	SendHeader (byte, byte, const char*, int);

public:
		IvlObexAgent (int, IvlObexStream*);
		IvlObexAgent (IvlAddress*, IvlObexStream*);
		~IvlObexAgent ();
	void	SendObject (IvlObexObject&);
};

class IvlObexAgentEvent : public IvlEvent {
public:
static	IvlEventType*	ObexNewAgent, *ObexAgentBye;

protected:
	IvlObexAgent*	Agent;

public:
		IvlObexAgentEvent (IvlObexAgent*, IvlEventType*);
		~IvlObexAgentEvent ();

inline	IvlObexAgent*	GetAgent () const	{ return Agent;}
};

class IvlObexObject {
friend class IvlObexAgent;
protected:
	IvlString	Name;
	IvlString	Description;
	IvlString	Body;	// should not be a text string, actually
	lword	Class;

public:
		IvlObexObject ();
		~IvlObexObject ();
	void	SetName (const char*);
	void	SetDescription (const char*);
	void	SetBody (const char*);
	void	SetClass (lword);
};

#endif	/* ObexStream_H_ */