PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PNetwork.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/devices/PNetwork.cpp
4// Purpose: Class for handling network communication
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2006-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#include "PNetwork.h"
28#include "../utility/PError.h"
29
30
31using std::ostream;
32using std::fstream;
33using std::flush;
34using std::string;
35using std::cout;
36
38 mHostName(""),
39 mHost(0),
40 mPort(0),
41 mIsOpen(false)
42{
43 InitializeProperty("NAME","<NETWORK>");
44 InitializeProperty("HOSTNAME",0);
45 InitializeProperty("HOSTIP",0);
46 InitializeProperty("PORT",0);
47 InitializeProperty("ISOPEN",0);
49}
50
51
55
56
57Variant PNetwork::ConvertAddress(unsigned long int address)
58{
59 //Uint32 address;
60
61 unsigned char octet[4] = {0,0,0,0};
62 for (int i=0; i<4; i++)
63 {
64 octet[i] = (address >> (i*8) ) & 0xFF;
65 }
66 Variant v = "";
67 v = v+Variant(octet[3])+
68 Variant(".")+Variant(octet[2])+
69 Variant(".")+ Variant(octet[1])+
70 Variant(".")+ Variant(octet[0]);
71 return v;
72}
73ostream & PNetwork::SendToStream(ostream & out) const
74{
75 out << "<Generic Network Object>" << flush;
76 return out;
77}
78
79
80
81void PNetwork::SetHostIP(unsigned int host){
82 mHost = host;
84}
85
86unsigned int PNetwork::GetHost()
87{
88 return mHost;
89}
90
91void PNetwork::SetOpen(bool open)
92{
93 mIsOpen = open;
94 PEBLObjectBase::SetProperty("ISOPEN",open);
95}
96
97void PNetwork::SetHostName(std::string hostname)
98{
99 PEBLObjectBase::SetProperty("HOSTNAME",hostname);
100 mHostName = hostname;
101}
102
104{
105 return mHostName;
106}
107
108void PNetwork::SetPort(unsigned int port)
109{
110 mPort = port;
112}
113
114 unsigned int PNetwork::GetPort()
115 {
116 return mPort;
117 }
118
120 return mIsOpen;
121};
@ CDT_NETWORKCONNECTION
Definition PEBLObject.h:64
virtual bool InitializeProperty(std::string name, Variant v)
virtual bool SetProperty(std::string name, Variant v)
ComplexDataType mCDT
Definition PEBLObject.h:109
bool mIsOpen
Definition PNetwork.h:77
virtual void SetHostIP(unsigned int host)
Definition PNetwork.cpp:81
virtual std::string GetHostName()
Definition PNetwork.cpp:103
virtual bool IsOpen()
Definition PNetwork.cpp:119
virtual ~PNetwork()
The Standard destructor.
Definition PNetwork.cpp:52
virtual void SetOpen(bool open)
Definition PNetwork.cpp:91
std::string mHostName
Definition PNetwork.h:73
unsigned int mPort
Definition PNetwork.h:75
PNetwork()
The Standard constructor.
Definition PNetwork.cpp:37
virtual unsigned int GetPort()
Definition PNetwork.cpp:114
virtual std::ostream & SendToStream(std::ostream &out) const
Definition PNetwork.cpp:73
unsigned int mHost
Definition PNetwork.h:74
virtual Variant ConvertAddress(unsigned long int address)
Definition PNetwork.cpp:57
virtual void SetHostName(std::string hostname)
Definition PNetwork.cpp:97
virtual void SetPort(unsigned int port)
Definition PNetwork.cpp:108
virtual unsigned int GetHost()
Definition PNetwork.cpp:86