/*
 * Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.dev.shell.remoteui;

/*
 * Notes:
 * - GWT 2.0.3 and earlier set the enum fields as "required" (such as requestType, which is
 *   of type RequestType, which is an enum).  This ended up preventing new values to be
 *   added to the enums.  Those enum fields are now set as "optional", allowing future versions
 *   of GPE and GWT to add new values to the enums.
 */

option java_outer_classname = "RemoteMessageProto";

// Outer envelope for all messages
message Message {
  
  // Two types of messages - either a request, or a response
  enum MessageType {
    REQUEST = 0;
    RESPONSE = 1;
    FAILURE = 2;
  }
    
  // A request message. This is the root type for all request messages
  message Request {
  
    // Every request must be addressed to a service. The two types of 
    // services are the ViewerService, and the DevModeService. The ViewerService
    // accepts commands for a Viewer. The DevModeService accepts requests for
    // the Development Mode Server.
    enum ServiceType {
      VIEWER = 0;
      DEV_MODE = 1;
    }
          
    // The root type for all requests for the ViewerService
    message ViewerRequest {
    
      // The different types of requests for a ViewerService
      enum RequestType {
        CAPABILITY_EXCHANGE = 0;
        ADD_LOG = 1;
        ADD_LOG_BRANCH = 2;
        ADD_LOG_ENTRY = 3;
        DISCONNECT_LOG = 4;
        INITIALIZE = 5;        
      }
      
      // Request the capabilities of the ViewerService. No additional
      // information is needed at this time.
      message CapabilityExchange {
      }
      
      // Add a log message to the view
      message AddLog {

        // The type of log - either a web server log, a module log, or 
        // the main log      
        enum LogType {    
          MAIN = 0;
          MODULE = 1;
          WEB_SERVER = 2;
        }
    
        // Information needed for creating a Module Log
        message ModuleLog {
          required string name = 1;   
          optional bytes icon = 2;
          optional string sessionKey = 3;
          optional string userAgent = 4;
          optional string url = 5;
          optional string tabKey = 6;
          optional string remoteHost = 7;                
        }
        
        // Information needed for creating a Server Log
        message ServerLog {
          required string name = 1;   
          optional bytes icon = 2;
        }
        
        // Information needed for creating the Main Log. At this time, no
        // additional information is needed.
        message MainLog {
        }
        
        optional LogType type = 1;
        optional ModuleLog moduleLog = 2;
        optional ServerLog serverLog = 3;
        optional MainLog mainLog = 4;
      }
      
      // The data for a log entry
      message LogData {
      
        // The HelpInfo portion of the log entry       
        message HelpInfo {
          optional string url = 1;
          optional string text = 2;
        }
  
       required string summary = 1;
       optional string level = 2;
       optional bool needsAttention = 3;
       optional string details = 4;
       optional HelpInfo helpInfo = 5;
      }
      
      // Add a new log branch to an existing log
      message AddLogBranch {
        required uint32 parentLogHandle = 1;
        required uint32 indexInParent = 2;
        required LogData logData = 3;
      }
      
      // Add a log entry to a log
      message AddLogEntry {
        required uint32 logHandle = 1;
        required uint32 indexInLog = 2;
        required LogData logData = 3;
      }
      
      // Disconnect the given log (i.e. process for which information was
      // being logged is dead)
      message DisconnectLog {
        required uint32 logHandle = 1;
      }
      
      message Initialize {
        optional string clientId = 1;
        repeated string startupURLs = 2;       
      }
      
      optional RequestType requestType = 1;
      optional CapabilityExchange capabilityExchange = 2;
      optional AddLog addLog = 3;
      optional AddLogBranch addLogBranch = 4;
      optional AddLogEntry addLogEntry = 5;
      optional DisconnectLog disconnectLog = 6;
      optional Initialize initialize = 7;                 
    }
  
    // The root type for all requests for the DevModeService
    message DevModeRequest {
      
      // The different types of requests for the DevModeService
      enum RequestType {
        CAPABILITY_EXCHANGE = 0;
        RESTART_WEB_SERVER = 1;
      }
      
      // Request the capabilities of the DevModeService. No additional
      // information is needed at this time.
      message CapabilityExchange {
      }
      
      // Restart the web server. No additional information is needed at this time.
      message RestartWebServer {
      }
               
      optional RequestType requestType = 1;
      optional CapabilityExchange capabilityExchange = 2;
      optional RestartWebServer restartWebServer = 3;      
    }
    
    optional ServiceType serviceType = 1;
    optional ViewerRequest viewerRequest = 2;
    optional DevModeRequest devModeRequest = 3;
  }

  // A response message for a request. This is the root type for all response 
  // messages. 
  message Response {
 
    // The root type for all response messages from the ViewerService
    message ViewerResponse {
    
      // The different types of response messages that can come from the
      // ViewerService
      enum ResponseType {
        CAPABILITY_EXCHANGE = 0;
        ADD_LOG = 1;
        ADD_LOG_BRANCH = 2;        
      }
      
      // Response for the capabilities of the ViewerService
      message CapabilityExchange {
        message Capability {
          optional Message.Request.ViewerRequest.RequestType capability = 1;
        }
        
        repeated Capability capabilities = 2; 
      }
      
      // Response to an AddLog request
      message AddLog {
        required uint32 logHandle = 1;
      }
      
      // Response to an AddLogBranch request
      message AddLogBranch {
        required uint32 logHandle = 1;
      }
      
      optional ResponseType responseType = 1;
      optional CapabilityExchange capabilityExchange = 2;
      optional AddLog addLog = 3;
      optional AddLogBranch addLogBranch = 4;      
    }
  
    // The root type for all response messages from the DevModeService
    message DevModeResponse {
      
      // The different types of response messages from the DevModeService
      enum ResponseType {
        CAPABILITY_EXCHANGE = 0;
        RESTART_WEB_SERVER = 1;
      }
      
      // Response for the capabilities of the DevModeService
      message CapabilityExchange {
        message Capability {
          optional Message.Request.DevModeRequest.RequestType capability = 1;
        }
        
        repeated Capability capabilities = 2;  
      }
      
      // Response to a RestartWebServer request. Right now, there is no information
      // that needs to be passed back
      message RestartWebServer {
      }
      
      optional ResponseType responseType = 1;
      optional CapabilityExchange capabilityExchange = 2;      
      optional RestartWebServer restartWebServer = 3;     
    }
 
    optional ViewerResponse viewerResponse = 1;
    optional DevModeResponse devModeResponse = 2;
  }
  
  message Failure {
    optional string message = 1;
    optional string stackTrace = 2;
  }
  
  // In the first release, we'll ignore this field. In the future, 
  // we can make use of it to detect protocol incompatibilities
  optional string protocolVersion = 1;
  
  optional MessageType messageType = 2;
  required uint32 messageId = 3;
  optional Request request = 4;
  optional Response response = 5;
  optional Failure failure = 6; 
}
