1 /* 2 * Copyright 2002-2016 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 module hunt.stomp.simp.stomp.StompCommand; 18 19 import hunt.stomp.simp.SimpMessageType; 20 import hunt.util.ObjectUtils; 21 22 import std.string; 23 24 /** 25 * Represents a STOMP command. 26 * 27 * @author Rossen Stoyanchev 28 * @author Juergen Hoeller 29 * @since 4.0 30 */ 31 struct StompCommand { 32 33 enum StompCommand Null = StompCommand("Null", SimpMessageType.OTHER); 34 35 // client 36 enum StompCommand STOMP = StompCommand("STOMP", SimpMessageType.CONNECT); 37 enum StompCommand CONNECT = StompCommand("CONNECT", SimpMessageType.CONNECT); 38 enum StompCommand DISCONNECT = StompCommand("DISCONNECT", SimpMessageType.DISCONNECT); 39 enum StompCommand SUBSCRIBE = StompCommand("SUBSCRIBE", SimpMessageType.SUBSCRIBE, true, true, false); 40 enum StompCommand UNSUBSCRIBE = StompCommand("UNSUBSCRIBE", SimpMessageType.UNSUBSCRIBE, false, true, false); 41 enum StompCommand SEND = StompCommand("SEND", SimpMessageType.MESSAGE, true, false, true); 42 enum StompCommand ACK = StompCommand("ACK", SimpMessageType.OTHER); 43 enum StompCommand NACK = StompCommand("NACK", SimpMessageType.OTHER); 44 enum StompCommand BEGIN = StompCommand("BEGIN", SimpMessageType.OTHER); 45 enum StompCommand COMMIT = StompCommand("COMMIT", SimpMessageType.OTHER); 46 enum StompCommand ABORT = StompCommand("ABORT", SimpMessageType.OTHER); 47 48 // server 49 enum StompCommand CONNECTED = StompCommand("CONNECTED", SimpMessageType.OTHER); 50 enum StompCommand RECEIPT = StompCommand("RECEIPT", SimpMessageType.OTHER); 51 enum StompCommand MESSAGE = StompCommand("MESSAGE", SimpMessageType.MESSAGE, true, true, true); 52 enum StompCommand ERROR = StompCommand("ERROR", SimpMessageType.OTHER, false, false, true); 53 54 mixin GetConstantValues!(StompCommand); 55 56 private string _name; 57 private SimpMessageType messageType; 58 private bool destination; 59 private bool subscriptionId; 60 private bool hasBody; 61 62 63 this(string name, SimpMessageType messageType) { 64 this(name, messageType, false, false, false); 65 } 66 67 this(string name, SimpMessageType messageType, 68 bool destination, bool subscriptionId, bool hasBody) { 69 this._name = toUpper(name); 70 71 this.messageType = messageType; 72 this.destination = destination; 73 this.subscriptionId = subscriptionId; 74 this.hasBody = hasBody; 75 } 76 77 static StompCommand valueOf(string name) { 78 string n = toUpper(name); 79 foreach(ref StompCommand s; values) { 80 if(n == s._name) { 81 return s; 82 } 83 } 84 return Null; 85 } 86 87 string name() { 88 return _name; 89 } 90 91 SimpMessageType getMessageType() { 92 return this.messageType; 93 } 94 95 bool requiresDestination() { 96 return this.destination; 97 } 98 99 bool requiresSubscriptionId() { 100 return this.subscriptionId; 101 } 102 103 bool requiresContentLength() { 104 return this.hasBody; 105 } 106 107 bool isBodyAllowed() { 108 return this.hasBody; 109 } 110 111 string toString() { 112 return _name; 113 } 114 115 }