Internet Based Electronic Booking System for a Building S Laundry Room

Total Page:16

File Type:pdf, Size:1020Kb

Internet Based Electronic Booking System for a Building S Laundry Room

Web Based Booking System

PREFACE

I would like to thank the great support offered by the personnel from ISBIT AB. Specially to Christian Andersson for his supervision during the development of this project. I also want to thank Kristian Sandström from Mälardalens Högskola for the support offered in the correction and clarification of concepts in this report.

ABSTRACT

Today exists the possibility for real estate owners of using electronic booking units to control the building’s laundry room. These units substitute today’s manual booking systems and they also can control peoples the access to the laundry room shared by the residents. This means, for example, that the access to a laundry room, under a certain time, is restricted to the user that has reserved that time. As Internet is becoming more available and convenient and with the fast development of present communication systems, like broadband and the WAN, web based laundry booking will be of higher interest for both real estate owners and their residents. The objective of this degree project was to develop a web based booking system that enables the users of laundry rooms to perform all the tasks that they usually can do through the electronic booking unit, but now via Internet. The system consists of a hardware device, the electronic booking unit, that communicates with an embedded PC/104 compatible system with P266 MHz processor, 100 Mbit Ethernet network, RS232 serial communication, 32 MB RAM memory and a 16MB Flash Disc. The operating system is a modified and reduced Linux distribution, which contains an Apache server. This report requires of the reader to have at least a couple of years of studies in computer science. CONTENTS

INTRODUCTION...... 1 Background...... 1 Description of the present system...... 1 The hardware...... 1 The Software...... 1 Advantages and disadvantages...... 2 Purpose...... 2 Demarcations...... 2 The structure of the report...... 2 DESCRIPTION OF THE TASK...... 3 Problem...... 3 Goal...... 3 THEORY...... 4 Socket...... 4 System V Inter Process Communication (IPC)...... 5 Semaphores...... 7 Shared Memory...... 7 Messages Queues...... 8 CGI...... 10 Serial Communication...... 11 ANALYSIS...... 12 Requirements...... 12 Customer related requirements...... 12 System related requirements...... 12 The problem and the possible solutions...... 13 DESIGN...... 16 Client Process...... 16 Class description...... 18 Server Process...... 18 Class Description...... 21 IMPLEMENTATION...... 22 Client Process...... 22 Main method...... 22 Execute method...... 22 Server Process...... 23 Main method...... 23 Start method...... 23 Execute method...... 23 CONCLUSIONS...... 26

REFERENCES...... 26

II LIST OF TABLES

Table 1: sockets system calls...... 5 Table 2 Summary of System V IPC system calls...... 5 Table 3 Summary of the access permissions...... 6

LIST OF FIGURES

Figure 1: UML-diagram for the client process...... 17 Figure 2: UML-diagram for the server process...... 20 Figure 3: UML-sequence diagram for the reserve cancel command...... 24 Figure 4: ULM-sequence diagram for the set time command...... 25

III INT RODUCT ION

BACKGROUND

ISBIT AB is a company in the area of advance software engineering within Industrial IT. The company was established in 1998, and the main office is in Västerås. At the present there are 25 consults working in different projects. The biggest customer in Västerås is ABB, the leader company within Industrial IT.

ADC Systems was established in 1996 with the idea of producing smart card readers at a component level. It is a company lied in Gothenburg. During the last 5 years this company has developed complete products and systems for contactless smart cards, as PCB readers for OEM business as well as capsulated products in areas as public transportation, access control and industrial areas.

One of the offered products is an electronic laundry-booking unit. Its objective is to give real estate owners a tool to control people access to the laundry room shared by the residents. The business developers at ISBIT saw the possibility of adding more value to this unit through development a web based system to access it.

DESCRIPTION OF THE PRESENT SYSTEM

THE HARDWARE

The hardware consists of an embedded PC/104 compatible system with P266 MHz processor, 100 Mbit Ethernet network serial communication, the electronic booking system. A strongly diminished Linux-distribution that contains an apache web server. The storage media is a 16MB flash card memory that supports multi-level power down capability for power saving benefits. Comply with PC Card (PCMCIA) ATA standards, up to 1 million write/erase cycles and unlimited read cycles

THE SOFTWARE

At the present time, there is a well functioning version of the system in use. It is composed of three processes: a client process, a server process and a process that deal with communication with the booking unit via serial communication, called rs232. Every process is implemented in ANSI C and includes a number of functions that take care of the incoming data from the other process in the system.

A transaction may be started in two ways: through the booking unit, or by a browser client. Any of these ways exclude the possibility of parallel treatment of data, which means that if a browser client starts a transaction, it will reach at sometime the server process. The server further will send the request to the serial component, and waits for response. When the rs232 process receives the data sends it bit for bit to the booking unit. It’s at this time that the booking unit will be blocked, showing this

1 by sending a message to the unit’s user display. When the booking unit is ready with this task, it sends a response to the serial component, and becomes ready to receive the next request. The serial component rs232 receives the message, decodes it and sends back to server process information about the transaction. The server process updates the database and sends the actual state of the system to the client. Finally, the client process makes a html page, sends it to the browser, and finishes. This system uses socket for communication between the different processes, and serial communication between the server process and the electronic laundry- booking unit.

ADVANTAGES AND DISADVANTAGES

This form of programming makes difficult future development of the system, since other programmers, who can be involved in this project, will have to review great part of the code to be able to understand how the program is constructed. In addition, which seemed to be an advantage, the unrestricted access to the data, becomes here in a problem because it makes difficult to new programmers knowing how and where data is acceded. Other of the problems that is evident here is the difficulty to test the different parts of system independently. This can result, in the worse case, that a programmer may be forced to rewrite one or more parts of the code.

PURPOSE

The purpose of this report is to present an alternative solution to the problem, based on the object-oriented design that satisfies the requirements of the system, and that facilitates the development of this one.

DEMARCATIONS

Since one of the limitations in this project is the time available for the development, the developed prototype in this degree project will provide the users with a some facilities, such as look for a week in the database, reserve/cancel a wash time and setting the system and the unit time.

THE STRUCTURE OF THE REPORT

DESCRIPTION OF THE TASK: Presents a description of the problem and what are the goals for this project. THEORY: Reviews the different theories that this project rests on. ANALYSIS: Presents the requirements of the system and suggests possible solutions DESIGN: This section describes what classes constitute every process in the system and how they are related to each other. We use UML diagrams to show these relations. IMPLEMENTATION: This section will give a description of the different messages along a transaction. CONCLUSION: Presents the conclusions of this degree project and propound further development. REFERENCES.

2 BIBLIOGRAPHY

3 D ESCRIPT ION OF T HE TASK

PROBLEM

The building of a booking system raises a chain of problems to solve in order to produce a stable and robust system:

 Guarantee the transference of data from a Internet client to the system’s database  Updating of data in the electronic laundry-booking unit  Guaranteeing of the atomicity of the transactions. In this case, atomic transaction means to receive from the unit a well-known answer to a certain request that has a relation with the question  Ward again system crash or halt.  Guarantee a multi-user system. All the transactions will be synchronous, that is to say, the system will not treat more than a transaction simultaneously.  Sending right answer to right client

GOAL

The purpose of this project is to develop a system that allows the access and the administration of the electronic laundry-booking unit via the Internet. This means that the system users should be able to execute the same tasks via the Internet as at the electronic laundry-booking unit.

Furthermore, the system should be design in such a way that enables increasing development of the system, in order to introduce new features, without to redesign it.

4 T HE ORY

SOCKET

Sockets are a generalized networking capability introduced by BSD (Berkeley Software Distribution), and it constitutes an API to the communication protocols (TCP, UDP, IP). A socket is defined as an endpoint of communication to which a name can be bound. It has a type and one or more associated processes. They provide point-to-point, two-way communication between two different processes on the same or different machines. Sockets exist in communication domains (that is, abstractions that provide an addressing structure and a set of protocols), and connect only with sockets in the same domain.

Like other forms of inter-process communication, sockets can be used to communicate between processes on a single system. For this purpose, in the UNIX domain (or AF_UNIX) a socket is given a path name within the file system name space. A file system node is created for the socket and other processes may then refer to the socket by giving the proper pathname. UNIX domain names, therefore, allow communication between any two processes that work in the same file system. They can also be used to communicate between processes on different systems. The socket address space between connected systems is called the Internet domain, and uses the TCP/IP Internet protocol. Addresses in the Internet domain consist of a machine network address and an identifying number, called a port.

Basically, a socket behaves like a low-level file descriptor. It uses the system calls read, write and close in the same way that files do. However, sockets differ from file descriptors in the way that they are created, and through a variety of special operations to control them. These operations are necessary because of the additional complexity in establishing network connections when compared with normal disk access. For communication with socket, the operating system provides several system calls, which constitutes the socket’s interface:

Socket Creates an endpoint for communication and returns a descriptor Bind Assigns a name ton an unnamed socket connect Initiates a connection on a socket Listen Used by a connection-oriented server to indicate that it is ready to receive connections accept Accepts a connection on a socket. Accept takes the first connection request on the queue and creates another socket with the same properties as the incoming socket descriptor send, sendto Sends a message from a socket recv, Receives a message from a socket recvfrom Close Closes a file descriptor. In this case a socket descriptor

5 gethostbynam This call returns the host information from the local DNS e using the hostname Table 1: sockets system calls

Another aspect that increments the complexity of the use of socket, with inter process communication, is the roles of the processes. One must actuate as a server, and the other as a client. These roles, concerning communication, are not symmetric and cannot be reversed without some attempt.

There are two way to make a connection using sockets: connection-oriented or connection less. Connection-oriented service works like a telephone service. When host X desires to communicate with host Y, X makes a request from the network to establish a connection to Y. Y has the option to accept or discard this connection. If Y agrees to the connection, the network system reserves a data path between X and Y and tells them that they can now communicate. X and Y communicate as long as they desire, and each can send information anytime it wants. They are also free to send any amount of data any time they want, because there is lower layer software that transparently splits the data into packets for transmission. Both nodes can request that the connection be closed at any time.

For a client-server communication using a connectionless protocol, the system calls are not the same. On the one hand, the client does not establish a connection with the server, but just sends a datagram to the server using the sendto system call (a datagram is datagram a message that containing not only data but also the source and the destination address). On the other hand, the server does not need to accept a connection from a client. It only has to use the recvfrom system call to wait until data arrives from some client. This system call returns the network address of the client process.

SYSTEM V INTER PROCESS COMMUNICATION (IPC)

The IPC services provide a clean, consistent solution to passing data between processes on the same machine. There are three types of IPC facilities: Semaphores, shared memory and messages queues. They share many similarities in the system calls that access them, and in the information that the kernel maintains on them. A summary of their system calls is shown in the table bellow.

Facility Message queue Semaphore Shared Memory System call to create or msgget Semget shmget open System call to control msgctl Semctl shmctl operations System call for IPC msgsnd, shmat, operations msgrcv shmdt Table 2 Summary of System V IPC system calls

The UNIX system V IPC enables us to perform the following tasks:

6 Create and handle semaphores. This includes the capability to read, set, and reset semaphore values. Send messages from one process to another by a message queue. Processes can add messages to a queue, check the length of a queue, and remove messages from a queue. Create and handle shared memory. This includes the capability to read from and write into areas of shared memory.

For each resource the system uses a common structure of type struct ipc_perm to store information needed in determining permissions to perform an ipc operation. The ipc_perm structure, defined by the system header file, includes the following members:

struct ipc_perm{ ushort uid; /* owner’s user id*/ ushort gid; /* owner’s group id */ ushort cuid; /* creator’s user id*/ ushort cgid; /* creator’s group id*/ ushort mode; /* access mode*/ ushort seq; /* slot usage sequence number*/ key_t key; /* key*/ }

The three ctl system calls are used to access this structure and modify it. The three get system call, which create or open an IPC channel (also referred to as objects in the operating system), take a key value of type key_t, and return an integer identifier. An IPC key is a long integer used to name the IPC resource. A key is assigned by the programmer or by the system via the ftok system call, which returns a system V IPC key (for more details about ftok you can look at the UNIX man pages). The mode member of the ipc_perm structure defines, with its lower 9 bits, the access permissions to the resource for a process executing an IPC system call.

The interpretation of the permissions are summarized in the following tables:

Flags Description IPC_CREATE Create a new object for the specified key, if it does not already exist, or return it if the object exists. IPC_CREATE & IPC_EXCL This flag creates an IPC channel given a key. It returns an error if the object with the specified key already exist. This flag prevents to two unrelated processes from crating two channels with the same key. IPC_PRIVATE (note that this Guarantees that a unique IPC object is created. is key_t type) IPC_RMID Given an resource ID, this flag removes it from the system. The calling process must have the permissions on the object to be able removing it. IPC_STAT Given an resource ID, this flag returns the values of each member of an IPC object specified in the structure ipc_perm IPC_NOWAIT Return error is a request must wait IPC_SET Given an ID and a data structure for an object, this flag sets the values of each member of the corresponding

7 IPC object Table 3 Summary of the access permissions

When a new object is created using one of the get system calls with the IPC_CREAT flag as argument, the low-order 9 bits of the flag argument initialize the member mode in the ipc_perm structure. Additionally, the structure members cuid and uid are set to the effective user ID. The structure members gid and cgid further are set to the effective group ID of the calling process. The ipc_perm structure also contains a member variable called seq. This variable is a counter kept by the kernel for every possible IPC object in the system. The kernel increments this counter every time an IPC channel is closed. When it overflows the counter is reset to zero.

SEMAPHORES

One of the problems involved in multi-process applications is the need to synchronize various transactions between the processes. One way to solve this problem is communicate by socket, messages queues or pipes. However, sometimes exists the need to synchronize operations between several processes, or control the access to resources that may be shared by several processes in parallel, in order to prevent potentially erroneous read/write situations. The system V IPC primitive semaphore allows us to synchronize such operations. A semaphore is simply a counter provided by the kernel. The value of the variable at any time is the number of resource units available.

SHARED MEMORY

When two processes wants to communicate, they have to send the information through the kernel. If we consider the normal steps involved in a client-server file copying using pipes, FIFO or messages queues, a total of four copies of data are required:

 The server reads from the input file. The kernel read the data and put it into one of its internal block buffers. Then copied it from this block to the server’s buffer by the read system call.  The server writes the data to a message. Using a pipe, a FIFO or a message queue the data requires to be copied from the user’s buffer into the kernel  The client reads the data from the IPC object. The client as well as the server requires copying the data from the kernel into its own buffer.  The data contained in the client’s buffer is copied to the output file. We can do this by the write system call

To go around this problem, the shared memory facility lets two or more processes share a memory segment. We declare a given section in the memory as one that will be used simultaneously by several processes. This brings up the following problem: How the processes have to coordinate the use of the memory among themselves. What it is about here is to prevent a dirty read/write. In other words when a process is writing onto some shared memory, all other process that also share the same segment have to wait until the writing process is finished. The answer to this question is the use of semaphores for the synchronization. This result in only two

8 data copying: from the input file into the share memory and from the shared memory to the output file. As we said before, a shared memory segment is uniquely identified by a positive integer and has an associated data structure of type struct shmid_ds, defined in , containing the following members:

9 struct shmid_ds { struct ipc_perm shm_perm; /* operation perms */ int shm_segsz; /* size of segment (bytes) */ time_t shm_atime; /* last attach time */ time_t shm_dtime; /* last detach time */ time_t shm_ctime; /* last change time */ unsigned short shm_cpid; /* pid of creator */ unsigned short shm_lpid; /* pid of last operator */ short shm_nattch; /* no. of current attaches */ }; The following system calls are provide by the system to work with shared memory: int shmget(key_t key, int size, int smhflag);

The call gets a key for the segment, the desired segment size, in bytes, and flags to indicate access permissions. The value returned by this call is the shared memory identifier, shmid, or –1 if an error occurs.

char *shmat(int shmid, char *shmaddr, int shmflag);

This system call returns the starting address of the shared memory segment. This call gets an shmid containing an identifier returned by a call to shmget, the attaching address specified by shmaddr and the shmflag that specifies in which mode the segment will be attached.

int shmctl(int shmid, int cmd, struct shmid_ds *buf);

This system call allows the calling process to receive information on a shared memory segment, set the owner, group, and permissions of a shared memory segment, or destroy it. The information about the segment identified by shmid is returned in the shmid_ds buf buffer. The returned value is 0 if the operation is successful, otherwise the value is –1.

MESSAGES QUEUES

In the system V implementation of messages, all messages are stored in the kernel, and every one is associated to a message queue identifier, a type. So, we can identify a particular queue of messages by this queue identifier. A message queue can be either private or public. A private queue can only be accessed by its creating process or by child processes of that creator. In contrast to both pipe and FIFO implementation, there are not requirements that any process must wait for a message to arrive on a queue before some other process is allowed to write a message to that queue. This means that, it is possible for a process to write some message to a queue and then exit. The message later can be read by another process that can access this message queue. IPC messaging passing lets processes send and receive messages, and queue messages for processing in an arbitrary order. Again, in contrast to pipe’s and FIFO’s file byte-stream data flow, each IPC messages has an explicit length. Because of the message’s specific type, a server process can direct message traffic between clients on its queue by using the client process PID as the message type. For example, if we have a server communicating with two client processes A and B, so the server has the possibility to read a message from the process B even if the process A has a message first in the queue.

10 Before a process can send or receive a message, the queue must be initialized. This means that if the queue does not exist, it must firstly be created; or if it exists, we have to initialise it to access it. This can be done by the system call

int msgget(key_t key, int msgflag);

Processes that request access to an IPC object must be able to identify it. This can be done by the functions that initialize or provide access to this object via the key argument in the system call. The second parameter contains the flag msgflag, which controls how the system call is to be processed. It may contain values like IPC_CREAT or IPC_EXCL, and access permissions bits defined before. The returned value by msgget is the message queue identifier msqid, or –1 if an error occurred.

Once a message is initialized, we can put a message on the queue using the msgsnd system call.

int msgsnd(int msqid, struct msgbuf *ptr, int length, int flag);

Each message is made up of, at least, two parts, which are defined in the template structure struct msgbuf as defined in sys/msg.h:

struct msgbuf { long mtype; char mtext[1]; };

The field mtype is used later when retrieving messages from the queue, and can be set to any positive number. The data portion of the message is not restricted to text. Any form of data is allowed. This means that the struct msgbuf may contain several variable members. So, the ptr argument points to a long integer that contains the message type, followed by the message itself.

The length argument to msgsnd system call specifies the length of the message in bytes. This is the length of the user-defined data that follows the long integer message type. So, if we use the C function sizeof(struct msgbuf), we must decrease by 4 the return value of sizeof. The flag argument can be specified as either IPC_NOWAIT or as zero. The IPC_NOWAIT value allows the system call to return immediately if there is no space the message queue for the new message. In this case the system call returns –1, otherwise it returns zero.

The followings are system limits affecting a msgsnd system call:

MSGMAX : Maximum size for a message text: the implementation set this value to 4080 bytes.

MSGMNB : Default maximum size in bytes of a message queue: policy dependent. The super-user can increase the size of a message queue beyond MSGMNB by a msgctl system call.

For reading a message from the message queue we can use the msgrcv system call

11 int msgrcv(int msqid, struct msgbuf *ptr, int length, long msgtype, int flag );

The msqid, *ptr, length, and the flag argument are defined as before. The msgtype argument is defined as:

0 – the fist message on the queue will be returned A positive integer - the first message on the queue whose type equals this integer A negative integer – the first message on the queue whose type is less then or equal to the absolute value of this integer

On successful return, msgrcv returns the number of bytes of data in the received message. This does not include the long integer message type that is also returned through the ptr argument.

There is also a system call for controlling the permissions and other characteristics of a message queue: msgctl

int msgctl(int msqid, int cmd, struct msgbuf *buff );

The cmd argument is one of the following:

IPC_STAT: Places information about the status of the queue in the data structure pointed by buff. The calling process must have read permission on the queue for this call to succeed IPC_SET: Sets the owner’s user and group ID, the permissions, and the size (in number of bytes) of the message queue. A process IPC_RMID: Removes the message queue specified by the msqid argument

CGI

The Common Gateway Interface (CGI) is a standard method for a Web browser and a CGI program running on a Web server to communicate. CGI was developed to meet the demand of doing web pages more interactive. People wanted to be able to collect information from the clients, for example, to take orders or allow database lookups from the sever, etc. A CGI program is a program, which “knows” how to receive information from the Web server; how to processes it and sends a reply back. The CGI program does not communicate with the browser directly, but by the Web server. It is the Web server that connects the GCI application (a program or a script) with the client browser. CGI is essentially the minimum that a Web server needs to provide in order to allow external process to create web pages. In this sense CGI can be defined as a standard for interfacing external applications with information servers, such as HTTP or Web servers. When a Web server receives a request for a CGI application, submitted via an HTML page classified as either a “GET” or “POST”, executes the CGI application, just as another process with the incoming parameters, collects the process output and sends them as a static html file. A CGI program takes its inputs from environment variables and standard input, stdin, and sends its output to standard output, stdout. From the application’s point of view, stdin is what comes from the browser via the server when a POST or GET method is used. stdout is where the application writes its output back to the browser.

12 The HTML tag “ form” is used to submit data to a CGI program

Hello World

field:

Everything between the

is part of the form. The method can be either “get” or “post”, and the “action” is what the server does when it receives the form data. Every form has a method, an action, and a submit button. The rest of the form consists of input fields. The method GET is the standard request method for retrieving documents via HTTP. The browser creates a GET request for the URL we ask for. GET are intended only to retrieve resources and should not have side effects. They should not alter information maintained on the server, because web browsers assume that GET requests have no side effects (e.g. changing a data base), so they no need think about multiple requests for the same document. GET passes its data to the CGI program (cgi_exec in the example above) through the environment variable QUERY_STRING. The method POST is used to submit information that alters data stored on the web server. A post operation occurs when the browser sends data from a fill-in form to the server. The data gets passed from the server using stdin. This means that the CGI application needs to know how much data there is in the buffer. For this reason, the server supplies with another environment variable, CONTENT_LENGTH, to indicate the size in bytes of the incoming data.

SERIAL COMMUNICATION

RS-232 is a standard electrical interface for serial communications. In order to connect with this device, UNIX provides access to serial ports via opening the corresponding device file, associated with it. Since a serial port is a file (/dev/ttyS0 or /dev/ttyS1), the open system call is used to access it, the write system call to write data to the port, the read system call to read data from the port, and close to close it. For more detailed information about these facilities, the reader is referred to the UNIX man pages.

13 A NALYSIS

REQUIREMENTS

CUSTOMER RELATED REQUIREMENTS

Login: The system must verify the identity of the users to give them the possibility of using the system according to theirs access rights. Laundry room reservation Laundry room cancellation Browser navigation: The users are able to see the week schedules one by one Separated log storage for the previous week Looking for reserved wash time When a resident wants to make a reservation or a cancellation, they have to login the system first. When a transaction is finished the system will automatically logout the user System configuration: The administrator will be able to configure the system through the browser. System access control: Users will not be able to access part of the system that they have no right to . Reliable communication with the electronic booking unit Add and remove users. Enable the administrator to modify the users data. Enable the administrator to change the time of the system, and the electronic laundry-booking unit. Storage of the previous week in a separate file.

SYSTEM RELATED REQUIREMENTS

To guarantee the data transfer from an Internet client, and the electronic laundry- booking unit to the system’s database. Updating of the information in the electronic laundry-booking unit. Updating of the week schedule before starting a new week Guarantee of the atomicity of the transactions: the system must guarantee that other client process cannot interrupt a transaction. The system must guarantee a recovery after system crash or halt; in other words, the data must be consistent. Guarantee a multi-user system: In spite of the electronic laundry-booking unit is single user device; the system must behave as if the unit was a multi user device. Sending right answer to right client: Because of the multi user behaviour. To guarantee a parallel access to the system from two sources: the electronic laundry-booking unit and an Internet client, through a server apache.

14 THE PROBLEM AND THE POSSIBLE SOLUTIONS

Since one of the main requirements is that the complete system must fit into a 16 MB flash card memory, we must analyse the possible solutions of the system taking into account that these must have, at the same time, a low complexity, and a little physical space requirement. In addition to these considerations, we must think about the nature of the system, specifically about the possible simultaneous accesses to it that may occur, which necessarily requires a division of this system into subsystems, introducing in this way the following questions: which will be the communication form between the different parts of the system; in how many parts we must subdivide it. Another subject to consider in this analysis is the necessity to have a system fail-safe, in others words, a system that guarantees the consistency of the information in the event of a possible failure. Finally, a last aspect to take into consideration in this analysis is the time available for the development of the system: we have only 10 weeks for the analysis, the design, the implementation of the system and the previous studies concerning the different tools that will be necessary for the accomplishment of this system. Such tools have to do with the programming language to use, which are the different mechanisms of communication that the OS offers, how the data crossing from and towards Internet will be done, etc.

One of the main aspects of the analysis is the behaviour of the different parts from the system. In this sense we could divide it in four parts: the first part would have to do with all the information from Internet. A Second would be related to the functionality of the unit. The third part would maintain all the information of the system, and finally, a central part that would send data from a place to another. Each one of these parts would constitute a process in the system and would have the sufficient logic to be able to treat the incoming data, independently of the other processes in the system. Such system has as advantage the clear division made respect to the behaviour of these parts, which facilitates its development, and possible modifications. A disadvantage would be the increasing necessity of messages crossing from one process to another, having as consequence the greater use of the operating system resources, and the greater complexity in the implementation of each component.

If we integrated two of the four processes, the central process of the system and the process that it has to do with the data processing, we would obtain a system that requires minor data transfer from one place to another, and a less complex process respect to the accomplishment of this functionality, because it is now not necessary to implement this part as an own process (a function call may solve this task). Nevertheless, we obtain a system with greater internal complexity, since the task of two whole processes would have to be made now by only one.

Going further on still, it is possible to conceive a system with only two processes. First, the client process would be shot by the server apache whenever the information is sent from an Internet browser to this server. This information would be received and decoded by the client in order to extract data that would be sent to another process for its processing. This client process also would have as a function to display the originating results of the other process. The other process, the server

15 process, would be responsible to receive and to compute requests done by the client process and the electronic unit of the reservation. This process would include a database and all the functions that previously were made in a separate process, which have to do with the electronic booking unit.

The main advantage of such a system is that we don’t need to communicate several processes with each other, using in this way, few system resources. However, such solution can be inconvenient, because it would curry us to build a system difficult to test, to increase, to change, etc. A system like this may suffer from all the problems concerning with the procedural programming. Nevertheless, such solution not necessarily must be discarded “a priori”. A system like this one, of small dimensions, can without any problem be implemented with the aid of well-defined objects.

Another of the previously described aspects is the time available for the development of the project. Because its magnitude, it is almost impossible to fulfil to 100% the requirements. Therefore we must reflect a little on which it will be the strategy to follow to obtain a system that, without being complete, may satisfy the requirements. One way to tackling the problem would be to organize the development of the system into releases. Two of the most popular approaches are iterative development and incremental development [Lawrence98]. Both of approaches separate the system into subsystems by functionality. The iterative development delivers a full system at the very beginning and then changes and/or increases the functionality of each subsystem with new releases. However, in the incremental development, the releases are defined with one small, functional subsystem and then adding functionality with each release. A possible solution would be to use the incremental method. The first release would concentrate on provides the users with some facilities, such as reserving-cancelling a wash time, looking after a certain time, and setting the system time. However, each of these would be developed iteratively.

A third subject to analyse here is the method that we will use for the communication between processes. As we have already described it in the theory section, exist different methods: socket, shared memory and message queues. Each one of these offers reliable communication. Nevertheless, the decision on which method we will use, it will be based on the complexity that implies each one of these. Socket is most complex to use, because it requires for his creation of four different calls from system before being used. In addition sockets offers more than what is necessary here, because the processes to communicate belong to a same node. The second method that we will review is the shared memory. This facility, although it is not so complex to be created and to be used, as the socket, implies greater effort in the control of access to the information, since it is exposed at the same time to different processes. It is for this reason that we must use semaphores to control the access, which implies to introduce greater complexity to the system. The third and last method is message queue. This method appears as most suitable for the necessity of communication between processes. The greater advantages of this method are its creation and its use, since it requires only one system call to create a message queue and one to access it. The method offers in addition the possibility of managing synchronization without introducing more complexity to the system. Concerning the disadvantages we can mention two: the limited amount of bytes that can be sent

16 simultaneously (4080). However, this is not a problem in our case, since we do not need to send such amount of information at a time. A second disadvantage is the impossibility to send an undetermined size of information. Thus for example, if we have a class that has inherited of the STL class vector, and we have not defined its size, we cannot put an object of this into a message queue to be sent to another process. This implies that the information kept by an object of this type will be first extract to be transmitted in predetermined amount of information.

The last aspect that we will bring up here deals with the possible problems that can come up when a crash occurs in the system. Some operating systems, Linux among them, are susceptible to be corrupted in the eventuality of system failure, because a logical file write operation often requires multiple I/O operations which can not be totally stored at a certain moment. The solution to this inconvenience is to replace the Linux file system ext2, by another that guarantees the consistency of the information. There are several systems that accomplish this task: The Journaled File System [IBM] uses techniques that originally were developed for databases in order to log information about operations performed on the file system meta-data (i.e. directories and des addressing structures) as atomic transactions. If the system fails, the file system is restored to a consistent state by replaying the log and applying log records for the appropriate transactions. This technology is currently used in the IBM OS/2 Warp Server and is now an open source project. Other alternative file systems are ReiserFS [ReiserFS] developed by Namesys, SGI’s XFS file system for workstations and servers [SGI XFS], and ext3, which is a journaling for ext2fs [EXT3].

17 D ESIGN

Before giving a description of the processes that make up the system, we can think about how the system behaves. What a user does, as much from the electronic booking unit as from a browser, is sending a request to system. This request may intend to obtain information of the system, or to introduce new data to it. Is in this way that we can imagine these requests as commands. However, we can’t implement the command explicitly in the client object because it doesn’t know anything about how a specific command works. It only knows that a command will be performed. In order to solve this problem we will use the Command design pattern [Gamma95]. The Command pattern provides a design for dealing with users requests. The idea is to turn each command into an object. First, we declare a base class for all the commands, called Command. This base class defines an interface for all the concrete commands, which consist in only one method, execute. Each concrete command subclass implements the command that it represents by overriding the execute method, applying an adequate algorithm to carry out the command.

After the analysis of the possible scenes we have concluded that the best solution for a system of this magnitude and according to the requirements, is to divided the system into a two subsystems, which can be designed based on the client server model. A client, which sends well-defined messages to the server, this one makes the required services, sends an answer and waits for the following request. The client, receives the answer, displays the results to the user and finishes his execution.

CLIENT PROCESS

The client process is a process that will be created every time a browser sends a request to the system and it will be going on until it gets a reply from the system. It means that the system must be capable of serving an arbitrary number of clients efficiently, but not necessarily at the same time. Information send to a client via an Internet browser must be treated in order to extract all the necessary data so that the server can make the required service. Therefore, the system offers an object, the CGIVector, which reads from standard input the name and the value of each data. This is done by another object - the GCIpair -, which knows how to decode the sequence of data and to extract the information.

Figure 1 shows the UML-diagram that describes the object model for the client process:

18 singletonServer

1

message queue string

msgManager Command CGIpair 1 <>

vector

1 * 1 1 CGIVector CGIClient

1

LoginCmd systemRestart clientReserveCancelCmd ExportWlogCmd GetWeek ... 1 1 1 HTMLBase 1 1 1 1 1

LoginHtml 1

1 ReserveHtml

1 WeekTableHtml

AdminHtml

... Figure 1: UML-diagram for the client process

20 CLASS DESCRIPTION

GCIClient: This class will be instanced every time a browser sends a request to the system. It has a method – invoke – that takes the value of the requested command and creates a new instance of that command class and then calls the new object’s execute method. CGIClient has two methods: initClient, and invoke.

msgManager: This class contains the necessary methods for establishing and maintaining communication with another process

CGIvector: parses and holds all the name-value pairs submitted from the form as part or a CGI request.

CGIpair: this is a helper class to the CGIvector. Its job is to take the input data and parse each name-value pairs submitted from the html form and into keys and values, which will be hold in map of strings. Its result is added to the CGIvector.

HTMLBase: This creates the base html code of a page. It also constitutes an interface for different concretes htmlpage-classes, and it contains only one method: theBody Loginhtml, ReserveHtml, WeekTableHtml, and AdminHtml are the concrete classes that implement the method theBody

The remaining classes constitute the command design pattern.

Command: declares an interface for executing an operation LoginCmd, clientReserveCancelCmd, systemRestart, ExportWlogCmd, GetWeek: These classes implement the execute method by invoking the corresponding operations. Notice that it is transparent for the client object how the command will be performed. The client only calls the adequate concrete command. The systemRestart class is not a class that communicate with the server, but rather it activates script in the system that starts the server process again.

SERVER PROCESS

The second process is the server process. The task of this process is to listen at the incoming queue for service requests. When a message is received the server performs the appropriate actions the client requests of it, sends back a reply, if the client is a CGIClient, and goes back to listen the queues again.

There are two kinds of clients the server may service: A browser client (a CGIClient) and the electronic booking.

The services offered by the server process are the following: The server provides a database, which can store reservation schedules for an arbitrary number of weeks and information of the system’s users. All the transactions made by a client browser will both be registered in the database and sent to the electronic booking unit. If the request is a query the server needs only check the database. Communication with the booking unit according to the protocol defined by ADC Systems. When a user does a transaction via the electronic booking unit, This device sends through the serial port to the server the information about the transaction and what kind of transaction. The server process receives this information and updates the database.

Worth to emphasize here is that the electronic unit has priority, so when a request comes from a browser client, the server first check if there is no requests from the unit. In that case, these requests will be served first.

As the same way as the client process, messages’ sending, in the server process, has been solved by the Command design pattern.

Since the electronic booking unit communicates with the system by serial communication, it has been included to the system, an object, the serialComm, that has the function to establish a connection with the unit when it is required, to send and to receive information from the electronic unit and finally to disconnect the unit if it is required.

Figure bellows shows the UML-diagram, which describes the object model for the server process:

22 serialComm

msgManage BUnitManager

Command messageManager <> 1 this object represents a client process

CGIClient 1

* 1 singletonServer

message queue 1 1 1 1 1 1 GetWeek LoginCmd LogoutCmd ReserveCancelCmd ExportWlogCmd .... 0,1 0,1 1 0,1 1 0,1 1 1 0,1 1

1

database vector 1 vector

WPass * administrator

systemUser * * WTable resident Figure 2: UML-diagram for the server process

24 CLASS DESCRIPTION

singletonServer: This class represents the server process. The singleton design pattern has been used in order to guarantee the existence of only one instance of the server class in the system. database: This class represents the system’s database. systemUser: A base class that contains common data of all kinds of system’s users resident: a derived class that represents a laundry room user. administrator: A derived class that represent a system user with administrator rights WTable: This class represents a timetable of all the wash periods in a week. It inherits from the standard vector template. The template has as argument a WPass Represents a single wash period in a week. messageManager: This class contains the information and methods necessary to establish communication with the clients processes. BUnitManager: this class represents the used protocol to communicate with the electronic booking unit. serialComm: This class contains the information and methods necessary to establish communication with the electronic booking unit. BUnitManager: This class implements the protocol to communicate with the electronic unit and the required facilities to get reliable communication with the unit.

A kind of IPC communication previously described is message queue. This method has shown to be one of simplest to use, for the requirements of our system, without diminishing for that reason its stability. With the aid of message queues, we can obtain complete control of the incoming messages, since these are removed from the queue one by one, in the order that have arrived, or in the order that they have been required, since message queues make possible the access to a specific message. With the help of this facility we can also synchronize the system, since the system calls msgsnd and msgrcv can block the system, while they send or receive a message. In this way a server receives a request, transacts it and sends back a reply, takes the following message and so on. Another of the facilities that this way of IPC communication provides is the transference of parameters, since an object can be sent and be received with no need of been changed. IMPL E ME NTAT ION

CLIENT PROCESS

In this section we present the pseudo code of the client and the server. In addition, we show the implementation of two commandos with the aid of sequential diagrams

The following steps form part of the implementation of the client process.

MAIN METHOD

 Create a msgManager object and a CGIClient object with this msgManager object as parameter.  Call the method initClient to initiate the client, which means that we get the client process identifier and initiate the msgManager through creating (or initiating) two message queues, one for sending data to the server and one for receiving data. The identifier of the sending message queue is the same for all the client instances. The receiving message queue is different for different clients and has as key number the client process id.  Call the invoke method with the commando identifier and the msgManager object as parameters. This method creates an instance of the desired command with the msgManager object as argument, the CGIVector object to get the information send by the Internet browser and the respective html object.  Once the object has been created, the execute method of this command is called. This method involves all the necessary functionality for the command in question.  After the method execute has finalized its execution we delete the command object and terminate the invoke method. The client process ends its execution.

EXECUTE METHOD

 Create a command string with all the necessary information and stores it in the struct to send  Get the client message queue id and stores it in the struct to send.  Send the message to the server  Wait for reply. The client process is blocked until we get the answer/s from the server  Present the data send by the server with the aid of the html object  Remove the client’s message queue from the system and return from execute.

26 SERVER PROCESS

The following steps form part of the implementation of the server process.

MAIN METHOD

 Creates an instance of the singletonServer class  Initiate the server process: initiate the serial com port, and the server’s message queue.  System synchronization: What we do here is two things. First resetting the server’s database and then getting the information about the reservation done on the electronic booking unit and putting it into the database. And Second synchronizing the time of the electronic booking unit with the system time.  Start the server process.

START METHOD

 Wait for message to come.  On message arrive:  Check if the electronic unit wants to update the database. Do it if this is true.  Check if a client has a request:  If this is true:  Check what kind of message has come  Create an object of the desired type with the necessary objects as arguments.  Call the command execute method  Delete the current command object  Wait for message to come.

EXECUTE METHOD

 Check if the electronic unit wants to update the database. Do it if this is true  Get the client message  Parse the message’s data to extract the essential information  Call the corresponding method in the BUnitManager.  Update the system according to the client request  Send back to client the expected information. It may be more than one sending here depending on the command.  Send to the client process a quit message to signal end of data and terminate the execution of the execute method CGIClient clientReserveCancelCmd singletonServer messageManager ReserveCancelCmd database serialComm BUnitManager

init() init_port() initManager()

systemSynchronization()

new clientReserveCancelCmd start() execute()

execute() RESERVE_CANCEL_MSG

new reserveCancelCmd

getClientMsg()

reserveCancelCmd(clientMsg) makeCmdStr()

getStringXor()

connect() request(cmdStr) usleep()

reply()

disconnect()

return true

makeReservation()

GetWlogg()

setReceiverId()

sendWeeklogg()

SendMsg(out)

SendMsg(quit) Figure 3: UML-sequence diagram for the reserve cancel command

29 CGIClient clientSetTimeCmd singletonServer messageManager msgManager setTimeCmd Timer database BUnitManager

init() initClient() init_port() initManager()

systemSynchronization()

start()

invoke() new clientSetTimeCmd(msnManager *)

execute()

execute() SET_TIME_MSG new Timer() new setTimeCmd(Timer,BUnitManager,database,serialComm) execute() get_fd_in() execute() SendMsg(out) getHours() getMinutes() getSeconds() getYear() getMonth() getDay() getDayNum() setWatch() getClientMsg() setReceiverId() getSystemTimer(timeStr) SendMsg(out) ReadMsg(in)

removeFds()

Figure 4: ULM-sequence diagram for the set time command

30 CONCL USIONS

This system implemented by objects offers great possibilities of development. It may be increased with new functionalities or improved with more inteligentes functions. In addtion, this system is not only limited to be a laundry booking system, but it also can be used in different booking systems, since the different aspects of the systems have been catched by different objects with a well defined interface. For example, there is an object that implements the specific protocol for communication with the electronic booking unit. Thus, we would only need to change this specific object by onother that implements a different protocol, if we want to use this system in another reservations system. Another of the advantages that this system gives is the facility to add new functionalities. The current design is thought for a traditional Internet communication. Nevertheless method overriding in order to establish wireless communication is totally possible since all this functionality is encapsulated in different objects in the process client. One of the most interesting characteristics of Linux is the capacity to be modified. In this way it is possible to diminish, increase or transform the operating system according to the particular necessities, without causing side effects. This has been very important in the implementation since one constrain is the physical space available for the system. So in this way we have been able to remove a part of the OS functionality not necessary for us, without affecting the system in its totality. However, Linux is not a fail-safe operating system, since it may be corrupted in the event of a sistem crash. One of the future task here is the study of different fail-safe file system that may solve this problem. In the analysis section we mentioned some of these References

[IBM] http://oss.software.ibm.com/developerworks/opensource/features/jfs_feature.html.

[ReiserFS] http://www.namesys.com/

[SGI XFS] http://oss.sgi.com/projects/xfs/

[EXT3] ftp://ftp.linux.org.uk/pub/linux/sct/fs/jfs/

[Lawrence98] Software Engineering, Theory and Practice, Shari Lawrence Pfleeger, 1998 Prentice Hall

[Gamma95] Design Patterns, Elements of Reusable Object-oriented software Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides 1995 Addison-Wesley Pub Co

B IB L IOGRA PHY

Unix Neetwork Programing, W.Richards Stevens , 1990 Prentice Hall Software Series

UML in 24 hours, Joseph Schmuller, 1999 Sams Publishing

The Waite Group's Object-Oriented Programming in C++, 1998 Waite Group

Software Engineering, Theory and Practice, Shari Lawrence Pfleeger, 1998 Prentice Hall

Design Patterns, Elements of Reusable Object-oriented software Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides 1995 Addison-Wesley Pub Co

Thinking in C++ 2nd Edition by Bruce Eckel http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

Serial Programming Guide for POSIX Operating Systems 5th Edition Michael R. Sweet Copyright 1994-1999 http://www.easysw.com/~mike/serial/serial.html

32

Recommended publications