Class: ItunesController::ServerCommand Abstract
- Inherits:
-
Object
- Object
- ItunesController::ServerCommand
- Defined in:
- lib/itunesController/controllserver.rb
Overview
Subclass and override #processData to implement a server command
This is the base class of all server commands.
Direct Known Subclasses
AddFilesCommand, ClearFilesCommand, CreateControllerCommand, FileCommand, HelloCommand, LoginCommand, PasswordCommand, QuitCommand, RefreshFilesCommand, RemoveDeadFilesCommand, RemoveFilesCommand, VersionCommand
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The command name.
-
#requiredLoginState ⇒ Number
readonly
The required login state need for this command.
-
#singleThreaded ⇒ Object
readonly
Returns the value of attribute singleThreaded.
Instance Method Summary collapse
-
#executeSingleThreaded(state) ⇒ Object
This is executed when the command is popped from the job queue.
-
#initialize(name, requiredLoginState, singleThreaded, state, itunes) ⇒ ServerCommand
constructor
The constructor.
-
#processData(data, io) ⇒ Boolean, String
This is a virtual method that must be overridden by command classes.
-
#processLine(line, io) ⇒ Boolean, String
The returned status of the command.
Constructor Details
#initialize(name, requiredLoginState, singleThreaded, state, itunes) ⇒ ServerCommand
The constructor
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
#name ⇒ String (readonly)
The command name
96 97 98 |
# File 'lib/itunesController/controllserver.rb', line 96 def name @name end |
#requiredLoginState ⇒ Number (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.
96 97 98 |
# File 'lib/itunesController/controllserver.rb', line 96 def requiredLoginState @requiredLoginState end |
#singleThreaded ⇒ Object (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
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.
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.
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 |