Class: ItunesController::ServerCommand Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/itunesController/controllserver.rb

Overview

This class is abstract.

Subclass and override #processData to implement a server command

This is the base class of all server commands.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, requiredLoginState, singleThreaded, state, itunes) ⇒ ServerCommand

The constructor

Parameters:

  • name (String)

    The command name

  • requiredLoginState (Number)

    The required login state need for this command. Either nil, ServerState::NOT_AUTHED, ServerState::DOING_AUTH or ServerState::AUTHED. If nil then works in any login state.

  • state (ItunesController::ServerState)

    The status of the connected client within the server

  • itunes (ItunesController::BaseITunesController)

    The itunes controller class



106
107
108
109
110
111
112
# File 'lib/itunesController/controllserver.rb', line 106

def initialize(name,requiredLoginState,singleThreaded,state,itunes)
    @name=name
    @state=state
    @itunes=itunes
    @requiredLoginState=requiredLoginState
    @singleThreaded=singleThreaded
end

Instance Attribute Details

#nameString (readonly)

The command name

Returns:

  • (String)

    the current value of name



96
97
98
# File 'lib/itunesController/controllserver.rb', line 96

def name
  @name
end

#requiredLoginStateNumber (readonly)

The required login state need for this command. Either nil, ServerState::NOT_AUTHED, ServerState::DOING_AUTH or ServerState::AUTHED. If nil then works in any login state.

Returns:

  • (Number)

    the current value of requiredLoginState



96
97
98
# File 'lib/itunesController/controllserver.rb', line 96

def requiredLoginState
  @requiredLoginState
end

#singleThreadedObject (readonly)

Returns the value of attribute singleThreaded.



97
98
99
# File 'lib/itunesController/controllserver.rb', line 97

def singleThreaded
  @singleThreaded
end

Instance Method Details

#executeSingleThreaded(state) ⇒ Object

This is executed when the command is popped from the job queue. It is used to force single threaded access to itunes

Parameters:



128
129
# File 'lib/itunesController/controllserver.rb', line 128

def executeSingleThreaded(state)
end

#processData(data, io) ⇒ Boolean, String

This is a virtual method that must be overridden by command classes. This method is used to perform the commands task and return the result to the server.

Parameters:

  • data (String)

    The commands parameters if their are any

  • io

    A IO Stream that is used to talk to the connected client

Returns:

  • (Boolean, String)

    The returned status of the command. If the first part is false, then the server will disconnect the client. The second part is a string message send to the client



121
122
123
# File 'lib/itunesController/controllserver.rb', line 121

def processData(data,io)
    raise "ERROR: Your trying to instantiate an abstract class"
end

#processLine(line, io) ⇒ Boolean, String

Returns The returned status of the command. If nil, nil is returned by the command, then the given line does not match this command. If the first part is false, then the server will disconnect the client. The second part is a string message send to the client.

Parameters:

  • line (String)

    A line of text recived from the client containg the command and it’s parameters

  • io

    A IO Stream that is used to talk to the connected client

Returns:

  • (Boolean, String)

    The returned status of the command. If nil, nil is returned by the command, then the given line does not match this command. If the first part is false, then the server will disconnect the client. The second part is a string message send to the client.



137
138
139
140
141
142
143
144
# File 'lib/itunesController/controllserver.rb', line 137

def processLine(line,io)
    line = line.chop
    if (line.start_with?(@name))
        ItunesController::ItunesControllerLogging::debug("Command recived: #{@name}")
        return processData(line[@name.length,line.length],io)
    end
    return nil,nil
end